ノイズグリッドを作る
void setup(){ size(500,500); smooth(); background(255); float xStart = random(10); float xNoise = xStart; float yNoise = random(10); for(int y = 0;y <= height;y++){ yNoise += 0.1; xNoise = xStart; for(int x = 0;x <= width;x++){ xNoise += 0.1; int alpha = int(noise(xNoise,yNoise) * 255); stroke(0,alpha); line(x,y,x+1,y+1); } } }
短い直線を引いて、その透明度を変えて模様を作っています。
四角で描画
float xStart,xNoise,yNoise; void setup(){ size(500,500); smooth(); background(255); xStart = random(10); xNoise = xStart; 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)); } } } void drawPoint(float x,float y,float noiseFactor){ float len = 10 * noiseFactor; rect(x,y,len,len); }
描画部分を関数にしました。そしてrectを使ってlineではなく、長方形で描画しました。
線を回転させる
毛のような模様ができました。
void drawPoint(float x,float y,float noiseFactor){ pushMatrix(); translate(x,y); rotate(noiseFactor * radians(360)); stroke(0,150); line(0,0,20,0); popMatrix(); }
pushMatrix(),popMatrix()を使って座標の保存を行っています。これのおかげでtranslateがいつも絶対座標で指定できます。またtranslateしているのでlineの始点は(0,0)で大丈夫になり、考えやすくなっています。
・参考
3. 座標の保存 – pushMatrix, popMatrix(processing 3D入門) | Yasushi Noguchi Class
円を使って雲の模様
void drawPoint(float x,float y,float noiseFactor){ pushMatrix(); translate(x,y); rotate(noiseFactor * radians(360)); 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(); }
grey,alpha,ellipseを駆使すれば、雲のような模様を作ることが出来ます。
草っぽい模様
float xStart,xNoise,yNoise; void setup(){ size(500,500); smooth(); background(255); xStart = random(10); xNoise = xStart; yNoise = random(10); for(int y = 0;y <= height;y+=50){ yNoise += 0.1; xNoise = xStart; for(int x = 0;x <= width;x+=2){ xNoise += 0.1; drawPoint(x,y,noise(xNoise,yNoise)); } } } void drawPoint(float x,float y,float noiseFactor){ pushMatrix(); translate(x,y); rotate(noiseFactor * radians(30)); float edgeSize = noiseFactor * 3; float grey = 150 + (noiseFactor * 120); float red = 21 + (noiseFactor * 10); float blue = 219 + (noiseFactor * 20); float green = 21 + (noiseFactor * 100); float alpha = 150 + (noiseFactor * 120); float startPoint = noiseFactor * 50; stroke(red,blue,green); line(startPoint,startPoint,edgeSize,edgeSize); popMatrix(); }
回転角を少なくし、x,yループの変化量を変えてみました。あと色をグリーンにしました。