//week05-1-a i_love_U
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);
}
}
//week05-1-b i_love_U_translate
size(300,300);
stroke(255,0,0);
//translate(width/2, height/2);
translate(150,150);
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);
}
}
-------------------------------------------------------------------------------
//week05-2
//角度_degress vs 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, 60, 60, 0, now, PIE);
arc(50+j*100, 50+i*100, 40, 40, 0, radians(now*10), PIE);
text(now, j*100, i*100+30);
}
}
----------------------------------------------------------------
//week05-3
void 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弧的 radians
arc(200,200,200,200,0,a, PIE); //把算出的 arc radians 拿來用
textSize(30);
text("radians" + a, 100,100); //dadians 弧度
text("degress" + degrees(a), 100, 130); //degrees 度
}
//week05-3-b
void 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弧的 radians
if(a<0) arc(200,200,200,200,a,0, PIE); //把算出的 arc radians 拿來用
else arc(200,200,200,200,0,a,PIE);//變成360度都可以
textSize(30);
text("radians" + a, 100,100); //dadians 弧度
text("degress" + degrees(a), 100, 130); //degrees 度
}
----------------------------------------------------------------------
//week05-4
//rotate和translate的差異
void setup(){
size(400,400);
}
void draw(){
background(204);
translate(mouseX,mouseY); //跟著滑鼠移動
rotate(radians(frameCount)); //1秒轉60格frame AKA 60度
rect(-50,-5,100,10); //生成一個寬度100的棒子 位置在左上
}
//上面兩行(translate & rect) 如果上下顛倒 會無法使用
-----------------------------------------------------------------------------
//week05-5
//rotate和translate的差異
void setup(){
size(400,400);
}
void draw(){
background(204);
translate(mouseX,mouseY); //跟著滑鼠移動
rotate(radians(frameCount)); //1秒轉60格frame AKA 60度
rect(-50,-5,100,10); //生成一個寬度100的棒子 位置在左上
}
//上面兩行(translate & rect) 如果上下顛倒 會無法使用
------------------------------------------------------------------------------------------
//week05-6
//因為有很多移動、旋轉、大腦會混亂 所以用分階層做事
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();//要固定在左側 -100
translate(width/2-100, height/2);
rotate(radians(frameCount)*10);
rect(-50,-5,100,10);
popMatrix();
//使用pushMatrix和popMatrix來固定 效果類似 大括號{}, 讓指令固定在兩者之間
}
---------------------------------------------------------------------------------
//week05-7 many Matrix
void 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();
}
}
}
沒有留言:
張貼留言