week03
第一個程式
///設定中文
///設定點線面 void setup() { size(500,500);///設定視窗大小 } float x=250, y=250; void draw() { ellipse(x,y,5,5); ///劃一個點 }
第二個程式
void setup() { size(500,500);///設定視窗大小 } float x=250, y=250; float dx=1, dy=1;///新增變數 void draw() { ellipse(x,y,5,5); ///劃一個點 x += dx;///加上使其移動 y += dy; }第三個程式
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; }第四個程式
void setup() { size(500,500);///設定視窗大小 for(int i=0; i<20; i++) { x[i] = random(500);//新增隨機變數 y[i] = random(500); dx[i] = random(-1, +1); dy[i] = random(-1, +1); } ///dx = random(-10, +10);///新增亂數往哪跑 ///dy = random(-10, +10); } float [] x = new float[20];//新增陣列 float [] y = new float[20]; float [] dx = new float[20]; float [] dy = new float[20]; //float x=250, y=250; //float dx=1, dy=1;///新增變數 void draw() { background(0); for(int i=0; i<20; i++)//新增迴圈 { ellipse(x[i],y[i],5,5); ///劃一個點 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]; } }第五個程式
void setup() { size(500,500);///設定視窗大小 for(int i=0; i<20; i++) { x[i] = random(500);//新增隨機變數 y[i] = random(500); dx[i] = random(-1, +1); dy[i] = random(-1, +1); } ///dx = random(-10, +10);///新增亂數往哪跑 ///dy = random(-10, +10); } float [] x = new float[20];//新增陣列 float [] y = new float[20]; float [] dx = new float[20]; float [] dy = new float[20]; //float x=250, y=250; //float dx=1, dy=1;///新增變數 void draw() { background(0); for(int i=0; i<20; i++)//新增迴圈 { ellipse(x[i],y[i],5,5); ///劃一個點 for(int k=0; k<20; k++)///畫線 { stroke(255,255,255); if(dist(x[i],y[i], x[k], y[k])<100) line(x[i],y[i], x[k], y[k]); } 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]; } }第六個程式
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); } ///dx = random(-10, +10);///新增亂數往哪跑 ///dy = random(-10, +10); } int N=40;//使點數固定 float [] x = new float[N];//新增陣列 float [] y = new float[N]; float [] dx = new float[N]; float [] dy = new float[N]; //float x=250, y=250; //float dx=1, dy=1;///新增變數 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]); } 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]; } }第七個程式
void setup() { size(500,500);///設定視窗大小 for(int i=0; i<N; i++) { x[i] = random(500);//新增隨機變數 y[i] = random(500); dx[i] = random(-3, +3); dy[i] = random(-3, +3); } ///dx = random(-10, +10);///新增亂數往哪跑 ///dy = random(-10, +10); } int N=40;//使點數固定 float [] x = new float[N];//新增陣列 float [] y = new float[N]; float [] dx = new float[N]; float [] dy = new float[N]; //float x=250, y=250; //float dx=1, dy=1;///新增變數 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.0003);//新增吸引力 dy[i] += ((y[k]-y[i])*0.0003); } } 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]; } }第八個程式
void setup() { size(500, 500); colorMode(HSB, 360, 100, 100); } void draw() { background(frameCount%360, 55, 100); }第九個程式
size(400, 400); colorMode(HSB, 400); for (int i=0; i<400; i++) { for (int j=0; j<400; j++) { stroke(i, 400, 400); point(i, j); } }第十個程式
void setup() { size(300, 300); colorMode(HSB, 360, 100, 100); chooseColor(); } float h, s, b; void chooseColor() { h=random(360); s=random(100); b=random(100); } void draw() { background(#3D66A7); for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { ellipse(30+j*60, 30+i*60, 60, 60); } } }第十一個程式
void setup() { size(300, 300); colorMode(HSB, 360, 100, 100); chooseColor(); } void mousePressed() { chooseColor(); } float h, s, b; void chooseColor() { h=random(360); s=random(100); b=random(100); } void draw() { background(203, 65, 65); for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { fill(h,s,b); ellipse(30+j*60, 30+i*60, 60, 60); } } }第十二個程式
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(100); b=random(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, 65, 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); else fill(h, s, b); ellipse(30+j*60, 30+i*60, 60, 60); } } }
沒有留言:
張貼留言