Original Post
I'm not 100% sure if this is the right area to post this, but I'm trying to come up with an equation in Lua.
The problem is that I want a circle to appear randomly within a range of numbers. The idea being that it reappears elsewhere on screen randomly, but I want the whole button to be on screen. I don 't have any part of the image to be cropped off by the screen. Here's the relevant code that I came up with:
Now I've figured out that the most I want the width to be between 40 and 280. I also want to the height to be between 40 and 440. So what equation would I have to put in on the last line of code to get that result?
The problem is that I want a circle to appear randomly within a range of numbers. The idea being that it reappears elsewhere on screen randomly, but I want the whole button to be on screen. I don 't have any part of the image to be cropped off by the screen. Here's the relevant code that I came up with:
randomButton = display.newCircle(0, 0, 40)
-- Makes the circle red (R, G, B)
randomButton:setFillColor(200, 0, 0)
-- Gets the height and width of the screen on the current platform
local _H = display.contentHeight; local _W = display.contentWidth
-- Puts the randomButton at the center of the screen to start
randomButton.x = _W/2; randomButton.y = _H/2;
-- Sets a reference point point for the randomButton in the middle of the circle
randomButton:setReferencePoint(display.CenterReferencePoint)
randomButton:setFillColor (math.random(255) , math.random(255), math.random(255))
randomButton.x = math.random(_W) randomButton.y = math.random(_H)
Now I've figured out that the most I want the width to be between 40 and 280. I also want to the height to be between 40 and 440. So what equation would I have to put in on the last line of code to get that result?