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