Page 1 of 2

Colour Spectrum (Fixed)

Posted: Fri Jan 27, 2012 6:00 am
by nate890

Code: Select all

local colours={}

for i=1,255 do
	table.insert(colours,{0,0,i})
end
for i=1,255 do
	table.insert(colours,{0,i,255})
end
for i=1,255 do
	table.insert(colours,{0,i,0})
end
for i=1,255 do
	table.insert(colours,{i,255,0})
end
for i=1,255 do
	table.insert(colours,{i,0,0})
end

local x=800
local y=600

function love.draw()
	for i=1,#colours do
		love.graphics.setColor(unpack(colours[i]))
		love.graphics.rectangle("fill",x/#colours*(i-x),0,x/#colours,y)
	end
end
Trying to create a quick colour spectrum, I get the error "24 - Incorrect draw mode -501.333333333333", what's this mean? How can I fix this?

Re: Colour Spectrum (Odd Error)

Posted: Fri Jan 27, 2012 6:03 am
by MarekkPie
RGB-values are integers from 0-255, so you are both (according to your error) outside the bounds, and using decimal values as an input. (AKA Don't divide by 255.)

Re: Colour Spectrum (Odd Error)

Posted: Fri Jan 27, 2012 6:06 am
by nate890
MarekkPie wrote:RGB-values are integers from 0-255, so you are both (according to your error) outside the bounds, and using decimal values as an input. (AKA Don't divide by 255.)
Oops, didn't notice, was using the same table from other code I wrote. Anyway, that wasn't the error, ended up fixing it.

Re: Colour Spectrum (Odd Error)

Posted: Fri Jan 27, 2012 6:09 am
by MarekkPie
You also don't have a width or a height in your rectangle.

Re: Colour Spectrum (Odd Error)

Posted: Fri Jan 27, 2012 6:11 am
by nate890
MarekkPie wrote:You also don't have a width or a height in your rectangle.
I thought it was rectangle(pos.x,pos.y,size.x,size.y) ?

Anyway, I have this, no error, but doesn't seem to work (Nothing shows)

Code: Select all

love.graphics.rectangle("fill",x/#colours*(i-(x/#colours)),0,x/#colours,y)

Re: Colour Spectrum (Odd Error)

Posted: Fri Jan 27, 2012 6:13 am
by MarekkPie
nate890 wrote:
MarekkPie wrote:You also don't have a width or a height in your rectangle.
I thought it was rectangle(pos.x,pos.y,size.x,size.y) ?

Anyway, I have this, no error, but doesn't seem to work (Nothing shows)

Code: Select all

love.graphics.rectangle("fill",x/#colours*(i-(x/#colours)),0,x/#colours,y)
Sorry, those commas looked like periods to me.

Re: Colour Spectrum (Odd Error)

Posted: Fri Jan 27, 2012 6:14 am
by nate890
Sorry, those commas looked like periods to me.
No problem.

Anyway, do you know why this doesn't seem to show up on the screen? Assuming my calculations are incorrect because I really don't understand how Love2D quite works, yet.

Code: Select all

love.graphics.rectangle("fill",x/#colours*(i-(x/#colours)),0,x/#colours,y)

Re: Colour Spectrum (Odd Error)

Posted: Fri Jan 27, 2012 6:18 am
by MarekkPie
Try not unpacking the colors. Love can read the table as well. It seems as if that's the line that is giving you issues (I'm assuming 24 is the line where the error occurs and there isn't any other code in your file to shift the numbers.)

Re: Colour Spectrum (Odd Error)

Posted: Fri Jan 27, 2012 6:23 am
by nate890
MarekkPie wrote:Try not unpacking the colors. Love can read the table as well. It seems as if that's the line that is giving you issues (I'm assuming 24 is the line where the error occurs and there isn't any other code in your file to shift the numbers.)
Even if it reads the tables, I still don't see nothing. Maybe my formula is incorrect and the rectangles aren't showing up on the screen?

Re: Colour Spectrum (Odd Error)

Posted: Fri Jan 27, 2012 6:27 am
by MarekkPie
So is the error the error code in the first post? Or can you not see anything, but it runs?