Some help with my color is not changing
Posted: Thu Jan 27, 2022 12:35 am
Hello everyone! I am completely new to lua and love2d, but I am trying to learn--going off some courses that I have purchased and reading. While tinkering with the language, I made a very simple program that bounces a circle off of the walls and then changes its color...or at least is supposed to change color. The weird thing is, it works and changes to a random color if I run this program in repl it, but it does not change to anything other than white if I run it in the actual love2d.exe. Could someone help me understand what is going on that is causing it to not change colors? I can even see that the variables I am using for the rgb is successfully changing. It's just not drawing the circle that way.
In summary: circle moves successfully and changes color successfully in repl.it. Circle moves successfully but does not change colors in love2d.exe.
Much appreciated ahead of time!
In summary: circle moves successfully and changes color successfully in repl.it. Circle moves successfully but does not change colors in love2d.exe.
Much appreciated ahead of time!
Code: Select all
success = love.window.setMode(1280, 720)
math.randomseed(os.time())
minWidth = 50
maxWidth = 1230
minHeight = 50
maxHeight = 670
x = math.random(minWidth, maxWidth) --used for x coord
y = math.random(minHeight, maxHeight) --used for y coord
a = 1
b = 1
r = 255 --red color var
g = 0 --green color var
bc = 0 --blue color var
function love.update()
x = x + a
y = y + b
if x >= maxWidth then
r = math.random(0, 255) --meant to set red to random value once ball bounces
g = math.random(0, 255) --meant to set green to random value once ball bounces
bc = math.random(0, 255) --meant to set blue to random value once ball bounces
if a < 0 then
a = a + -0.5
elseif a > 0 then
a = a + 0.5
end
a = a * -1
elseif x <= minWidth then
r = math.random(0, 255)
g = math.random(0, 255)
bc = math.random(0, 255)
if a < 0 and a > -10 then
a = a + -0.5
elseif a > 0 and a < 10 then
a = a + 0.5
end
a = a * -1
end
if y >= maxHeight then
r = math.random(0, 255)
g = math.random(0, 255)
bc = math.random(0, 255)
if b < 0 and b > -10 then
b = b + -0.5
elseif b > 0 and b < 10 then
b = b + 0.5
end
b = b * -1
elseif y <= minHeight then
r = math.random(0, 255)
g = math.random(0, 255)
bc = math.random(0, 255)
if b < 0 and b > -10 then
b = b + -0.5
elseif b > 0 and b < 10 then
b = b + 0.5
end
b = b * -1
end
end
function love.draw()
love.graphics.print("r "..r.."g "..g.."b "..bc) --printing values of rgb to test the random generation
love.graphics.setColor(r, g, bc) --trying to assign random colors to ball upon bouncing off of boundaries
love.graphics.circle("fill", x, y, 50, 100)
love.graphics.setColor(r, g, bc)
end