generative_noise_if01
float xstart, xnoise, ystart, ynoise; float xstartNoise, ystartNoise; void setup() { size(500, 500); smooth(); background(255); frameRate(6); xstartNoise = random(20); ystartNoise = random(20); xstart = random(10); ystart = random(10); } void draw() { background(255); xstartNoise += 0.01; ystartNoise += 0.01; xstart += (noise(xstartNoise)*0.5) - 0.25; ystart += (noise(ystartNoise)*0.5) - 0.25; xnoise = xstart; ynoise = ystart; for (int y = 0; y <= height; y += 5) { ynoise += 0.1; xnoise = xstart; for (int x = 0; x <= width; x += 5) { xnoise += 0.1; if (frameCount%2 ==0) { drawPoint1(x, y, noise(xnoise, ynoise)); } else { drawPoint2(x, y, noise(xnoise, ynoise)); } } } } void drawPoint1(float x, float y, float noiseFactor) { pushMatrix(); translate(x, y); rotate(noiseFactor*radians(540)); noStroke(); float edgeSize = noiseFactor*35; float grey = 150 + (noiseFactor*120); float alph = 150 + (noiseFactor*120); fill(grey, alph); ellipse(0, 0, edgeSize, edgeSize/2); popMatrix(); } void drawPoint2(float x, float y, float noiseFactor) { pushMatrix(); translate(x+noiseFactor, y+noiseFactor); rotate(noiseFactor*radians(frameCount%360)); stroke(random(255), random(255), random(255)); line(0, 0, 20, 0); popMatrix(); }
久しぶりのスケッチ.3日あげないと久しぶり感がある.今回も写経して,その後,書いたコードを切り替えるためにif
をつかった.
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
で確認することが大切ということを知った.
generative_noise03
float xstart, xnoise, ynoise; int num = 2; void setup() { size(500, 500); smooth(); background(0); frameRate(1); float xstart =random(10); float xnoise = xstart; float ynoise = random(10); } void draw() { for (int y = 0; y < height; y+=5 ) { ynoise += 0.1; xnoise = xstart; for (int x = 0; x <= width; x +=5) { xnoise += 0.1; num = int(random(0, 2)); switch(num) { case 1: drawPoint0(x, y, noise(xnoise, ynoise)); break; case 2: drawPoint1(x, y, noise(xnoise, ynoise)); break; } } } } void drawPoint0(float x, float y, float noiseFactor) { float len = 10*noiseFactor; rect(x, y, len, len); } void drawPoint1(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(); }
switch
をつかって描くパターンを切り替えようとしたけど失敗.最初は3つのパターンの切り替えだったのでswitch
をつかったのだけど,2つのパターンの切り替えだったら別の方法がある気がしている.いずれにしても失敗でした.歯医者のためタイムアップ.
generative_noise02
float xstart, xnoise, ystart, ynoise; void setup() { size(500, 500); colorMode(HSB, 360, 100, 100); smooth(); background(0, 0, 100); frameRate(24); mousePressed(); } void draw() { background(0, 0, 0); xstart += 0.01; ystart += 0.01; xnoise = xstart; ynoise = ystart; for (int y = 0; y <= height; y +=5) { ynoise += 0.1; xnoise += xstart; for (int x = 0; x <= width; x += 5) { xnoise += 0.1; drawPoint(x, y, noise(xnoise, ynoise)); } } } void drawPoint(float x, float y, float noiseFactor) { pushMatrix(); translate(x, y); rotate(noiseFactor * radians(540)); noStroke(); float edgeSize = noiseFactor*35; float grey = 150 + (noiseFactor*120); float alph = 150 + (noiseFactor*120); fill((xstart+ystart)*15, frameCount%100, grey, alph); ellipse(0, 0, edgeSize, edgeSize/2); popMatrix(); } void mousePressed() { xstart = random(10); ystart = random(10); }
今日も写経の時間.昨日の宿題はまた後日.写経したのち,mousePressed
を入れて,クリックするたびにあたらしいパターンになるようにして,色をつけた.今は写経の時間.写経しながら,復習と次のことを考える.
generative_noise01
float xstart, xnoise, ynoise; void setup() { size(500, 500); smooth(); background(0); 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; drawPoint(x, y, noise(xnoise, ynoise)); drawPoint2(x, y, noise(xnoise, ynoise)); drawPoint3(x, y, noise(xnoise, ynoise)); } } } 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(); }
教科書にしているGenerative Artの写経.変えたところはvoid drawPoint
に番号をつけて,写経したすべてのノイズパターンを同時にひょうじしたところ.つまり,単に写経.明日はクリックするたびに1,2,3を切り替えたい.もしくは,教科書の写経を進める.以前よりもrotate
がすんなりと受け入れられた.
PVector_ellipse06
PVector pos; PVector vel; float rad; float noise = 0.1; void setup() { size(500, 500); colorMode(HSB, 360, 100, 100, 100); smooth(); } void draw() { rad = radians(frameCount); float x = (100*cos(rad)) + noise; float y = (100*sin(rad)) + noise; pos = new PVector(x, y); vel = new PVector(random(-10, 10), random(-10, 10)); pos.add(vel); ellipse(pos.x, pos.y, 10, 10); noise = noise + 0.1; }
螺旋を描こうとしたけど失敗.見事に失敗.
PVector_curveVertex02
PVector pos; void setup() { size(500, 500); colorMode(HSB, 360, 100, 100); smooth(); noStroke(); mousePressed(); } void draw() { background(random(360), 100, 100); fill(random(360), 100, 100); beginShape(); curveVertex(pos.x, pos.y); curveVertex(random(100, 400), random(100, 400)); curveVertex(random(10, 400), random(100, 400)); curveVertex(random(100, 400), random(100, 400)); curveVertex(random(100, 400), random(100, 400)); curveVertex(random(100, 400), random(100, 400)); curveVertex(random(100, 400), random(100, 400)); curveVertex(pos.x, pos.y); endShape(); noLoop(); } void mousePressed() { pos = new PVector(random(100, 400), random(100, 400)) ; noLoop(); } void mouseReleased() { loop(); }
ラファエル・ローゼンダールのterminal object .com by rafaël rozendaal, 2016 collection of anne and many ameri, deep sadness .com by rafaël rozendaal, 2014
のようなものがつくりたくて,書いてみた.まずloop
noLoop
の使い方がわからず,ずっと描画が繰り返されていた.loop
noLoop
の位置を色々変えていたら,狙ったとおりのクリックしたらひとつの図形が描画されるができた.でも,背景と図形の色の組み合わせや図形のかたちはローゼンダールの作品のようにはならない.難しい.