|
|
Line 187: |
Line 187: |
|
| |
|
| ==IV: Butterflies== | | ==IV: Butterflies== |
| ==III: Cat Eyes==
| |
| {| border="1"
| |
| |-
| |
| ! style="width: 50%" | Result
| |
| ! style="width: 50%" | Algorithm
| |
| |-
| |
| |[[File:butterflies (Konvertiert)-quicktime.mov]]
| |
| |<source lang=java>
| |
| int num=40; //number of butterflies, but actually around 5 "form" one...
| |
| int stepLength=10; //tempo of them
| |
|
| |
| int x[]= new int [num];
| |
| int y[]= new int [num];
| |
| int w[]= new int [num];
| |
| int h[]= new int [num];
| |
|
| |
| void setup() {
| |
| rectMode(CENTER);
| |
| size(400,1000);
| |
| background(255);
| |
| noStroke();
| |
|
| |
| for(int i=0; i<x.length; i++){
| |
| x[i]=(int)random(width); // random position of the butterflies
| |
| y[i]=(int)random(height);
| |
| w[i]=(int)random(20,80);
| |
| h[i]=(int)random(20,80);
| |
| }
| |
| }
| |
|
| |
| void draw() {
| |
| background(255);
| |
| rectMode(CENTER);
| |
|
| |
|
| |
| for(int i=0; i<x.length-1; i++){
| |
| int newX=x[i]+=random(-stepLength,stepLength); //move the butterflies
| |
| int newY=y[i]+=random(-stepLength,stepLength);
| |
|
| |
| if(newX<0) newX = width;
| |
| else if(newX>width) newX = 0;
| |
| if(newY<0) newY = height; //keep them
| |
| else if(newY>height) newY = height;
| |
|
| |
| x = append(x, newX);
| |
| y = append(y, newY); // I guess this results in "butterfly effect"
| |
|
| |
| if(x.length > num){
| |
| x = subset(x, 1);
| |
| y = subset(y, 1);
| |
|
| |
| rect(x[i],y[i],w[i],h[i]);
| |
| }
| |
| fill(x[i],y[i],150); //mellow colours
| |
| }
| |
| }
| |
| </source>
| |
| |-
| |
| |}
| |