Type + Code: Processing For Designers

Page 77

Processing for Designers page >R< odd page {53} >Y—system<

int i=300; void setup() { size(800, 800); background(255); } void draw() { translate(random(i),random(i+10)); rotate(PI/3*i); Ysystem(200, 200, 230, 170, 20, 10); translate(abs(random(i-10)),random(i)); Ysystem(400, 400, 370, 370, 20, 10); }

float R = radians(angle); float new_dist = 0.9*dist*cos(R); float new_cx = ex+dx*new_dist; float new_cy = ey+dy*new_dist; float final_dist = 0.9*dist*sin(R); float dx1 = -dy; float dy1 = dx; float dx2 = dy;

void Ysystem(float sx, float sy, float ex, float ey, int angle, int level) {

float dy2 = -dx; float new_ex1 = new_cx+dx1*final_dist; float new_ey1 = new_cy+dy1*final_dist; float new_ex2 = new_cx+dx2*final_dist;

int new_level = level-1; if(level<10) line(sx,sy,ex,ey); if(mousePressed) { if(level>0) { float dist = sqrt( (sx-ex)*(sx-ex)+(syey)*(sy-ey) ); float dx = (ex-sx)/dist; float dy = (ey-sy)/dist;

float new_ey2 = new_cy+dy2*final_dist; Ysystem(ex, ey, new_ex1, new_ey1, angle, new_level); Ysystem(ex, ey, new_ex2, new_ey2, angle, new_level); } } return; }

Add translate( ); to move, rotate( ); to rotate, and random( ); to randomize the Ysystem( ).


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.