Created
June 26, 2014 01:36
-
-
Save KentaKomai/936895a6059ac872ee25 to your computer and use it in GitHub Desktop.
マウスに向かってくる
This file contains 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
int length = 1000; | |
float[] x = new float[length]; | |
float[] y = new float[length]; | |
float[] speedX = new float[length]; | |
float[] speedY = new float[length]; | |
float[] speedRate = new float[length]; | |
void setup(){ | |
size(1000, 700); | |
colorMode(HSB, 100); | |
background(99); | |
frameRate(30); | |
for(int i=0; i<length; i++){ | |
x[i] = random(width); | |
y[i] = random(height); | |
speedX[i] = speedY[i] = 0; | |
speedRate[i] = random(0.001, 0.01); | |
} | |
} | |
void draw(){ | |
background(99); | |
for(int i=0; i<length; i++){ | |
speedX[i] = (mouseX - x[i]) * speedRate[i]; | |
speedY[i] = (mouseY - y[i]) * speedRate[i]; | |
x[i] += speedX[i]; | |
y[i] += speedY[i]; | |
drawBug(i); | |
} | |
} | |
void drawBug(int i){ | |
pushMatrix(); | |
translate(x[i], y[i]); | |
rotate( atan2(mouseY- y[i], mouseX-x[i]) ); | |
noStroke(); | |
rectMode(CENTER); | |
fill(12, 50, 99); | |
rect(0,0, 10, 5); | |
fill(20); | |
rect(5,0, 5,5); | |
popMatrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment