generative_noise04
float xstart, xnoise, ynoise; int state = -1; void setup() { size(500, 500); smooth(); background(255); frameRate(5); mousePressed(); } void draw() { float xstart =random(10); float xnoise = xstart; float ynoise = random(10); for (int y = 0; y < height; y+=5 ) { ynoise += 0.1; xnoise = xstart; for (int x = 0; x <= width; x +=5) { xnoise += 0.1; switch(state) { case 1: drawPoint(x, y, noise(xnoise, ynoise)); break; case 0: drawPoint2(x, y, noise(xnoise, ynoise)); break; case 2: drawPoint3(x, y, noise(xnoise, ynoise)); break; } } } } void drawPoint(float x, float y, float noiseFactor) { float len = 10*noiseFactor; rect(x, y, len, len); } void drawPoint2(float x, float y, float noiseFactor) { pushMatrix(); translate(x, y); rotate(noiseFactor * radians(360)); stroke(0, 150); line(0, 0, 20, 0); popMatrix(); } void drawPoint3(float x, float y, float noiseFactor) { pushMatrix(); translate(x, y); rotate(noiseFactor*radians(540)); float edgeSize = noiseFactor*35; float grey = 150 + (noiseFactor*120); float alpha = 150+(noiseFactor*120); noStroke(); fill(grey, alpha); ellipse(0, 0, edgeSize, edgeSize/2); popMatrix(); } void mousePressed() { state += 1; if (state>2) { state =0; } println(state); }
昨日のやり直し.昨日,switch
はできていたみたいです.switch
に入れて状態を決定する数の決め方が間違っていた.println
で値を確認すればすぐに解決することであった.あとは表示するパターンの順番も影響していたので,そこを変えた.その結果,最初にやりたかった,マウスでクリックするたびにパターンが変わるようになった.問題が出てきたら,ネットで調べることが重要で,さらに,変数を使うなら値をprintln
で確認することが大切ということを知った.