Hello everybody!
I have a code where I call values randomly by using math.random command.The composer giving values randomly but with the least difference which I don’t want.I want composer to give values with larger difference.How can I achieve that?
Here’s the code
display.setStatusBar( display.HiddenStatusBar ) local Timer local loop local a = 3 local ao = 0.5 local function aa() a = a + 1 print(a) end Timer = timer.performWithDelay ( 10000, aa , 0) local myRectangle = display.newRect(140, -120, 30, 180 ) myRectangle.strokeWidth = 3 myRectangle:setFillColor( ao) myRectangle:setStrokeColor( 1, 0, 0 ) local myRectangle1 = display.newRect(70, -120, 30, 180 ) myRectangle1.strokeWidth = 3 myRectangle1:setFillColor( ao ) myRectangle1:setStrokeColor( 1, 0, 0 ) local myRectangle2 = display.newRect(210, -120, 30, 180 ) myRectangle2.strokeWidth = 3 myRectangle2:setFillColor( ao ) myRectangle2:setStrokeColor( 1, 0, 0 ) local myRectangle3 = display.newRect(280, -120, 30, 180 ) myRectangle3.strokeWidth = 3 myRectangle3:setFillColor( ao ) myRectangle3:setStrokeColor( 1, 0, 0 ) function moveBars(self, event) if self.y \> 670 then ao = math.random(0.6, 1) self.y = math.random( -400, -150) print ( self.y) else self.y = self.y + a end end myRectangle.enterFrame = moveBars Runtime:addEventListener("enterFrame",myRectangle) myRectangle1.enterFrame = moveBars Runtime:addEventListener("enterFrame",myRectangle1) myRectangle2.enterFrame = moveBars Runtime:addEventListener("enterFrame",myRectangle2) myRectangle3.enterFrame = moveBars Runtime:addEventListener("enterFrame",myRectangle3)
Here’s the corona simulator output values which were printed.
18:30:16.581 Copyright (C) 2009-2016 C o r o n a L a b s I n c . 18:30:16.581 Version: 3.0.0 18:30:16.581 Build: 2016.2906 18:30:16.591 Platform: SM-G900S / x86 / 6.1 / Intel(R) HD Graphics 2500 / 4.0.0 - Build 10.18.10.3431 / 2016.2906 / en\_US | US | en\_US | en 18:30:16.591 Loading project from: C:\Users\Prashant\Documents\Corona Projects\parallax 18:30:16.591 Project sandbox folder: C:\Users\Prashant\AppData\Local\Corona Labs\Corona Simulator\Sandbox\parallax-9EE48529A19BCF5EBA9048F904C9B20D\Documents 18:30:24.692 -239 --- random value of rectangle 1 18:30:24.692 -215 ---- random value of rectangle 2 18:30:24.692 -186 -----random value of rectangle 3 18:30:24.692 -229 ------random value of rectangle 4 18:30:26.632 4 18:30:31.782 -245------random value of rectangle 1 18:30:31.992 -295----random value of rectangle 2 18:30:32.112 -200-----random value of rectangle 3 18:30:32.172 -285---random value of rectangle 4 18:30:36.673 5 18:30:38.543 -161---random value of rectangle 1 18:30:38.543 -248---random value of rectangle 2 18:30:39.063 -244---random value of rectangle 3 18:30:39.133 -253---random value of rectangle 4
As you can see the difference between the values of rectangle1 is not large.(values are -239, -245,-161).I have coded in such a way that the composer has to give any values between -400 & -150.
But I want to make composer to choose random values with some difference.How can I do that? Or have you any other idea? If so, please share.
.