Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int dirx = 0;
- int diry = 1;
- int x = 0;
- int y = 0;
- int omx = 0;
- int omy = 0;
- color[] tra = { color(91, 207, 250), color(245, 171, 185), color(255, 255, 255)};
- void setup()
- {
- size(displayWidth,displayHeight);
- x = round(random(round(width/5)) * 5);
- y = round(random(round(height/5)) * 5);
- frameRate(5000);
- background(0);
- noStroke();
- }
- void draw()
- {
- if(mouseX != 0 && mouseX < 100 && mouseY < 100 && mouseX != omx)
- {
- background (0);
- x = round(random(round(width/5)) * 5);
- y = round(random(round(height/5)) * 5);
- randDir();
- omx = mouseX;
- }
- color col = get(x,y);
- if(col == tra[2])
- {
- changeDir(1);
- fill(tra[0]);
- }
- else if(col == tra[0])
- {
- changeDir(1);
- fill(tra[1]);
- }
- else if(col == tra[1])
- {
- changeDir(-1);
- fill(tra[2]);
- }
- else
- {
- changeDir(-1);
- fill(tra[0]);
- }
- rect(x,y,10,10);
- x += dirx * 10;
- y += diry * 10;
- }
- void changeDir(int h)
- {
- if(dirx == 1){dirx = 0; diry = h; return;}
- if(dirx == -1){dirx = 0; diry = -h; return;}
- if(diry == 1){diry = 0; dirx = -h; return;}
- if(diry == -1){diry = 0; dirx = h; return;}
- }
- void randDir()
- {
- dirx = 0;
- diry = 0;
- boolean r1 = random(1) > .5;
- boolean r2 = random(1) > .5;
- if(r1)
- {
- if(r2)
- {
- diry = 1;
- }
- else
- {
- diry = -1;
- }
- }
- else
- {
- if(r2)
- {
- dirx = 1;
- }
- else
- {
- dirx = -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement