Created
September 26, 2012 12:38
-
-
Save lizkhoo/3787780 to your computer and use it in GitHub Desktop.
Triangle Swimming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| float x1=0, speedx1 = 1; | |
| float y1=0, speedy1 = 1; | |
| float x2=100, speedx2 = 1; | |
| float y2=100, speedy2 = 1; | |
| float x3=0, speedx3 = 1; | |
| float y3=200, speedy3 = 1; | |
| float r=random(8,19); | |
| float g=random(50,255); | |
| float b=random(50,255); | |
| void setup(){ | |
| size(500,500); | |
| smooth(); | |
| frameRate(25); | |
| background(255); | |
| } | |
| void draw(){ | |
| g = g+1; | |
| b = b+1; | |
| float randIncX1 = random(-1,1); | |
| float randIncY1 = random(-1,1); | |
| float randIncX2 = random(-1,1); | |
| float randIncY2 = random(-1,1); | |
| float randIncX3 = random(-1,1); | |
| float randIncY3 = random(-1,1); | |
| speedx1=speedx1 + randIncX1; | |
| speedy1=speedy1 + randIncY1; | |
| speedx2=speedx2 + randIncX2; | |
| speedy2=speedy2 + randIncY2; | |
| speedx3=speedx3 + randIncX3; | |
| speedy3=speedy3 + randIncY3; | |
| x1 = x1 + speedx1; | |
| y1 = y1 + speedy1; | |
| x2 = x2 + speedx2; | |
| y2 = y2 + speedy2; | |
| x3 = x3 + speedx3; | |
| y3 = y3 + speedy3; | |
| if (x1 >width || x1 <0){ | |
| speedx1 = -speedx1; | |
| } | |
| if (x2 >width || x2 <0){ | |
| speedx2 = -speedx2; | |
| } | |
| if (x3 >width || x3 <0){ | |
| speedx3 = -speedx3; | |
| } | |
| if (y1 >height || y1 <0){ | |
| speedy1 = -speedy1; | |
| } | |
| if (y2 >height || y2 <0){ | |
| speedy2 = -speedy2; | |
| } | |
| if (y3 >width || y3 <0){ | |
| speedy3 = -speedy3; | |
| } | |
| if (g > 255){ | |
| g=50; | |
| } | |
| if (b > 255){ | |
| b=50; | |
| } | |
| noStroke(); | |
| fill(r,g,b); | |
| triangle(x1,y1, x2,y2, x3,y3); | |
| } | |
| void keyPressed(){ | |
| background(255); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment