Weird love.graphics.line behaviour

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Zaphio
Prole
Posts: 2
Joined: Thu Jun 02, 2011 1:49 pm

Weird love.graphics.line behaviour

Post by Zaphio » Wed Jul 20, 2011 11:42 am

Code: Select all

function love.load()
	love.graphics.setMode(500, 500)
	love.graphics.setLineWidth(100000)
	------------------------
	-- EDIT THIS VARIABLE --
	interval = 1
	-- Try out: .9, 1, 2, 5, 10, 50
	------------------------
end

function love.draw()
	love.graphics.setLine(25)
	drawRainbow({255,   0,   0, 255}, 10)
	drawRainbow({255, 127,   0, 255}, 20)
	drawRainbow({127, 255,   0, 255}, 30)
	drawRainbow({  0, 255,   0, 255}, 40)
	drawRainbow({  0, 255, 127, 255}, 50)
	drawRainbow({  0, 127, 255, 255}, 60)
	drawRainbow({  0,   0, 255, 255}, 70)
	drawRainbow({127,   0, 255, 255}, 80)
	drawRainbow({255,   0, 127, 255}, 90)
end

local function f(x)
	return 250+10*math.sin(x)
end

function drawRainbow(col, offset)
	love.graphics.setColor(unpack(col))
	local ly, t = f(0), love.timer.getTime()
	for x = 1, 500, interval do
		local y = f(x/30+t) + offset
		love.graphics.line(x-1, ly, x, y)
		ly = y
	end
end

I'm trying to draw a rainbow, but I'm getting skewed vertical lines that turn instead of a smooth horizontal line.
Why is this happening? Have I hit a bug? Or am I just plain dumb? :?
Also note setLineWidth doesn't seem to affect anything.

Image

Thanks in advance!

User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Weird love.graphics.line behaviour

Post by vrld » Wed Jul 20, 2011 12:05 pm

Zaphio wrote:I'm trying to draw a rainbow, but I'm getting skewed vertical lines that turn instead of a smooth horizontal line.
It's because of how you loop over x. Replacing 1 with interval and adjusting the vertical starting position should fix it:

Code: Select all

local t = love.timer.getTime()
local ly = f(t) + offset
for x = interval, 500, interval do
    local y = f(x/30+t) + offset
    love.graphics.line(x-interval, ly, x, y)
    ly = y
end
Zaphio wrote:Also note setLineWidth doesn't seem to affect anything.
That's a feature of how OpenGL defines line drawings and how graphic card vendors implement it: There is an arbitrary upper (and lower) limit of the line width, which depends on the type of graphics card you have installed. I can get a line width up to 10, but yours seems to be limited to about 2. The line drawing method will be replaced in the next LÖVE version.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Weird love.graphics.line behaviour

Post by kikito » Wed Jul 20, 2011 1:17 pm

I must point out that the current result looks more interesting than the "plain sinusoidal curves" to me.
When I write def I mean function.

User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Weird love.graphics.line behaviour

Post by Kadoba » Wed Jul 20, 2011 1:28 pm

psychedelic man

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 11 guests