| Random position (no smooth motion)?
• | | | |
 | Random position (no smooth motion)?
by Filip Nordling on Jul 23, 2012 at 7:17:33 pm |
Hi there,
I am trying to make a layer to randomly move position around the screen (even off screen), but with no smooth motion. Basically at one second it should be at x=500 and the other second at x=1250. But it should stay at x=500 until that second has passed to the other. It should be like a blink, and not move to x=1250 during the milliseconds. See what I mean? So no movements, just randomly position itself to another random place on the screen during random seconds.
Thanks in advance,
Filip
| | | | |
• | | | |  | Re: Random position (no smooth motion)? by Dan Ebberts on Jul 23, 2012 at 7:36:58 pm |
This should give you a new x position between 500 and 1250 every second:
minX = 500;
maxX = 1250;
seed = Math.floor(time);
seedRandom(seed,true);
x = random(minX,maxX);
[x,value[1],value[2]]
Dan
| | | | |
• | | | |  | Re: Random position (no smooth motion)? by Filip Nordling on Jul 23, 2012 at 7:41:51 pm |
Thanks for the quick answer!
In addition, is there a way to also control the amount of time it should take until it swaps to another position? I believe it's just a minor change in your code, but I'm not sure which...
Thanks again!
| | | | |
• | | | |  | Re: Random position (no smooth motion)? by Dan Ebberts on Jul 23, 2012 at 7:59:16 pm |
Well, not a minor change, but this should do it:
minX = 500;
maxX = 1250;
minDelay = 1;
maxDelay = 5;
tEnd = 0;
n = 0;
seedRandom(n, true);
while (time >= tEnd){
n++;
seedRandom(n,true);
dur = random(minDelay, maxDelay);
tEnd += dur;
}
x = random(minX,maxX);
[x,value[1]]
Dan
| | | | |
• | | | |  | Re: Random position (no smooth motion)? by Filip Nordling on Jul 23, 2012 at 8:09:26 pm |
Awesome, thanks!
Last question. The Y position. I'd like to do the same thing there, but somehow it doesn't do anything to Y if I add another line with the same code as the X ones. How come?
Thanks
| | | | |
• | | | |  | Re: Random position (no smooth motion)? by Dan Ebberts on Jul 23, 2012 at 8:24:42 pm |
Like this maybe?
minX = 500;
maxX = 1250;
minY = 0;
maxY = 1000;
minDelay = 1;
maxDelay = 5;
tEnd = 0;
n = 0;
seedRandom(n, true);
while (time >= tEnd){
n++;
seedRandom(n,true);
dur = random(minDelay, maxDelay);
tEnd += dur;
}
random([minX,minY],[maxX,maxY]);
Dan
| | | | |
• | | | |  | Re: Random position (no smooth motion)? by Filip Nordling on Jul 23, 2012 at 8:34:43 pm |
Yepp, that's it!
Thanks a ton!
| | | | |
| |
|