I need help with a light function
whenever i start it the drawing wont display on the screen also when i print alpha on the console it says that it constant value of 1 and doesnt change like it should? What do I do?
init = function()
reps = 0
end
update = function()
end
//draw = function()
//screen.setRadialGradient(0, 0, 50, "rgba(255,255,0,1)", "rgba(255,255,200,0)")
//screen.fillRound(0,0,100,100)
//end
drawLight = function(x, y, radi, red, green, blue, a)
r = radi*2
print(r+" diameter")
rgba = "rgba("+red+","+green+","+blue+","+a+")"
print('"'+rgba+'"')
alpha = a
while reps <= radi*2
draw = function()
screen.setColor('"'rgba'"')
screen.drawRound(x, y, r, r,'"'+rgba+'"')
end
draw()
r -= 1
reps+=1
alpha -= reps/0.1
print(radi+" radi")
print(reps+" reps")
print(x+" "+y+" "+r)
print(radius+"radius")
print(alpha+" alpha")
print('"'+rgba+'"')
end
end
drawLight(0,0,25,255,255,0,1)
I think this is right:
init = function()
lightX = 0
lightY = 0
lightRadius = 25
lightRed = 255
lightGreen = 255
lightBlue = 0
lightAlpha = 1
lightReps = 0 // To control the drawing iterations within draw
end
update = function()
// Update logic if needed, e.g., animating lightAlpha
end
draw = function()
// Clear the screen or draw background if needed
// screen.clear()
// Draw the light effect
local currentAlpha = lightAlpha
local currentRadius = lightRadius * 2 // Start with diameter
local stepAlpha = lightAlpha / (lightRadius * 2) // Calculate alpha step
local currentReps = 0
while currentReps < lightRadius * 2 do
local rgba = "rgba(" + lightRed + "," + lightGreen + "," + lightBlue + "," + currentAlpha + ")"
screen.setColor(rgba)
screen.fillRound(lightX, lightY, currentRadius / 2, currentRadius / 2) // Radius for fillRound
currentRadius -= 1
currentAlpha -= stepAlpha
currentReps += 1
end
end
// To initiate the light effect, you would set the global variables
// For example, in init or in response to an event:
// init() // This would set the initial light parameters
And it if does not work, then just show the whole project and it will be easier to fix. :)