金曜日, 1月 04, 2008

recursion

it's hoba
シンプルなコードで、視覚的に強い。

血が滴るみたいなやつ。
it's hoba: Processing 13

再帰を使って書き直してみた。

//based on hoba's code(http://hobagoogle.blogspot.com/2007/12/processing-13.html)
//rewrite by using recursion
void setup() {
size(800, 450);
background(152);
noStroke();
smooth();
colorMode(HSB);
}

float e, r, var, posx, posy, a, dex, lengh, bri;
int cnt;

void draw() {
}

void mousePressed() {
e = HALF_PI/180*30;
a = 1-sin(e);
r = random(30, 150);
var = random(0.6, 0.9);
dex = random(-0.15, 0.15);
lengh = random(0.8, 1.2);
bri = random(0, 1);
posx = mouseX;
posy = mouseY;
cnt = int(random(30, 200));
fill(2, 247, 80+50*bri);
ellipse(posx, posy+r*HALF_PI/180*var, r/20+r, r/20+r);
blood(posx, posy, r, var, dex, lengh, bri, cnt);
}

void blood(float posxU, float posyU, float rU, float varU,
float dexU, float lenghU, float briU, int cnt) {
fill(2, 247, 80+50*briU, 100-100*a);
ellipse(posxU+dexU*rU, posyU+rU*e*varU, rU/20+rU*a*a, rU/20+rU*a*a);
e += HALF_PI/180;
a = 1-sin(e);
if(cnt>0 && e<=HALF_PI*lenghU) {
blood(posx, posy, r, var, dex, lengh, bri, cnt-1);
}
}

void keyPressed() {
if (key == 'r' || key == 'R') {
background(152);
}
}

0 件のコメント: