Random
in
Programming Questions
•
1 year ago
According to the following code, what's the meaning of this code ?
I want to know the exact boundary of random() method
- if(random(100)<3)
{
dx += random(1)-0.5;
dy += random(1)-0.5;
}
float x,y, dx,dy;
float s,ds;
int SZ = 512;
void setup()
{
size(SZ,SZ,P3D);
x= SZ/2; y = SZ/2;
s=1; ds=.002; dx=1; dy=1;
colorMode(HSB, TWO_PI, 1,1);
background(0,0,0);
noStroke();
rectMode(CENTER);
}
float s,ds;
int SZ = 512;
void setup()
{
size(SZ,SZ,P3D);
x= SZ/2; y = SZ/2;
s=1; ds=.002; dx=1; dy=1;
colorMode(HSB, TWO_PI, 1,1);
background(0,0,0);
noStroke();
rectMode(CENTER);
}
void draw()
{
//backgroud(0,0,0);
fill(((x+y)/100)%TWO_PI, 1, 1);
translate(x,y);
scale(s,s);
for(int k=0; k<20; k++)
{
rotate((x+y)/100.);
rotateX(x/100.);
rotateY(y/100.);
rect(0,0,100,50);
// ellipse(0,0,100,50);
}
s=s+ds;
x=x+dx;
y=y+dy;
if( s > 2 || s < 0.75) ds = -ds;
if(x <= 0 || x >= width-1) dx = -dx;
if(y <= 0 || y >=height-1) dy = -dy;
if(random(100)<3)
{
dx += random(1)-0.5;
dy += random(1)-0.5;
}
}
1