1.//week05-1_ILoveYou
size(300,300); stroke(255,0,0); for(int xx=0;xx<300;xx++){ for(int yy=0;yy<300;yy++){ float x=(xx-150)/100.0; float y=-(yy-150)/100.0; float d=x*x+y*y-1; if(d*d*d-x*x*y*y*y<0) point(xx,yy); } }1b.//week05-1b_ILoveYousize(300,300); stroke(255,0,0); translate(width/2,height/2); for(int xx=-150;xx<150;xx++){ for(int yy=-150;yy<150;yy++){ float x=xx/100.0; float y=-yy/100.0; float d=x*x+y*y-1; if(d*d*d-x*x*y*y*y<0) point(xx,yy); } }2.//week05-2_for_for_ellipse_arc_radians_360
//角度 degrees radians size(600,600); background(0); for(int i=0;i<6;i++){ for(int j=0;j<6;j++){ int now=i*6+j; ellipse(50+j*100,50+i*100,80,80); arc(50+j*100,50+i*100,40,40,0,radians(now*10),PIE); text(now,j*100,i*100+30); } }
3.//week05-3_atan2_dy_dx_text_radians_degreesvoid setup(){ size(400,400); } void draw(){ background(128); line(200,200,400,200); line(200,200,mouseX,mouseY); float dx=mouseX-200,dy=mouseY-200; float a=atan2(dy,dx); arc(200,200,200,200,0,a,PIE); textSize(30); text("radians: "+a,100,100); text("degrees: "+degrees(a),100,130); }3b.//week05-3b_atan2_dy_dx_text_radians_degreesvoid setup(){ size(400,400); } void draw(){ background(128); line(200,200,400,200); line(200,200,mouseX,mouseY); float dx=mouseX-200,dy=mouseY-200; float a=atan2(dy,dx); if(a<0) arc(200,200,200,200,a,0,PIE); else arc(200,200,200,200,0,a,PIE); textSize(30); text("radians: "+a,100,50); text("degrees: "+degrees(a),100,80); }
4.//week05-4_translate_mouseX_mouseY_rotate_radians_frameCount//比較rotate 與 translate順序 void setup(){ size(400,400); } void draw(){ background(204); //畫東西之前的translate()才有效果 //畫圖時 會照著之前 [累積的移動、旋轉] translate(mouseX,mouseY);//跟著滑鼠走 rotate(radians(frameCount));//1秒60個frame 轉60度 rect(-50,-5,100,10);//寬度100 左上角 }
5.//week05-5_rotate_radians_frameCount_translate_mouseX_mouseY//比較rotate 與 translate順序 void setup(){ size(400,400); } void draw(){ background(204); //畫東西之前的translate()才有效果 //畫圖時 會照著之前 [累積的移動、旋轉] rotate(radians(frameCount));//1秒60個frame 轉60度 translate(mouseX,mouseY);//跟著滑鼠走 rect(-50,-5,100,10);//寬度100 左上角 }
6.Bad//week05-6_pushMatrix_popMatrix_bad//多層移動 push pop 分階層做事 void setup(){ size(400,400); } void draw(){ background(204); translate(width/2,height/2); rotate(radians(frameCount)*10); rect(-50,-5,100,10); translate(width/2-100,height/2); rotate(radians(frameCount)*10); rect(-50,-5,100,10); }good//week05-6_pushMatrix_popMatrix_good //多層移動 push pop 分階層做事 void setup(){ size(400,400); } void draw(){ background(204); pushMatrix(); translate(width/2,height/2); rotate(radians(frameCount)*10); rect(-50,-5,100,10); popMatrix(); pushMatrix(); translate(width/2-100,height/2); rotate(radians(frameCount)*10); rect(-50,-5,100,10); popMatrix(); }7.//week05-7_many_pushMatrix_popMatrixvoid setup(){ size(500,500); } void draw(){ background(204); for(int x=50;x<500;x+=100){ for(int y=50;y<500;y+=100){ pushMatrix(); translate(x,y); rotate(radians(frameCount)); rect(-50,-5,100,10); popMatrix(); } } }
沒有留言:
張貼留言