Page 1 of 1

Weird love.graphics.line behaviour

Posted: Wed Jul 20, 2011 11:42 am
by Zaphio

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!

Re: Weird love.graphics.line behaviour

Posted: Wed Jul 20, 2011 12:05 pm
by vrld
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.

Re: Weird love.graphics.line behaviour

Posted: Wed Jul 20, 2011 1:17 pm
by kikito
I must point out that the current result looks more interesting than the "plain sinusoidal curves" to me.

Re: Weird love.graphics.line behaviour

Posted: Wed Jul 20, 2011 1:28 pm
by Kadoba
psychedelic man