WEEK 3
step 1-1 中心顯示一點
step 1-2 往左下劃出一條直線
step 1-3 加上背景和亂數
step 1-4 控制點在視窗內飄移
void setup(){size(500,500);dx = random(-1,+1);//亂數往哪裡跑dy = random(-1,+1);//亂數往哪裡跑}float x=250, y=250;float dx=1, dy=1;void draw(){background(0);ellipse(x,y,5,5);x += dx;y += dy;if(x<0 || x>500) dx = -dx;if(y<0 || y>500) dy = -dy;}
step 1-5 20個漂移的球
step 1-6 靠近的球會連出一條線
step 1-7
step 1-8
void setup(){size(500,500);for(int i=0;i<N;i++){x[i] = random(500);y[i] = random(500);dx[i] = random(-1,+1);dy[i] = random(-1,+1);}}int N=40;float [] x = new float[N];float [] y = new float[N];float [] dx = new float[N];float [] dy = new float[N];void draw(){background(0);for(int i=0;i<N;i++){ellipse(x[i], y[i], 5, 5);for(int k=0;k<N;k++){float d = dist(x[i],y[i],x[k],y[k]);stroke(2.55*(100-d));if(d<100){line(x[i],y[i],x[k],y[k]);dx[i] += (x[k]-x[i])*0.00001;dy[i] += (y[k]-y[i])*0.00001;}}x[i] += dx[i];y[i] += dy[i];if(x[i]<0 || x[i]>500) dx[i] = -dx[i];if(y[i]<0 || y[i]>500) dy[i] = -dy[i];}}step 2-1
step 3-1
step 3-3
void setup(){size(300,300);colorMode(HSB, 360, 100, 100);chooseColor();}void mousePressed(){chooseColor();}int I,J;float h, s, b, dh, ds, db;void chooseColor(){h = random(360);s = random(50, 100);b = random(50, 100);I = int(random(5));J = int(random(5));dh = random(-10, +10);ds = random(-10, +10);db = random(-10, +10);}void draw(){background(203, 63, 65);for(int i=0; i<5; i++){for(int j=0; j<5; j++){if(i==I && j==J)fill(h+dh, s+ds, b+db);fill(h,s,b);ellipse(30+j*60, 30+i*60, 60, 60);}}}















沒有留言:
張貼留言