2024年9月30日 星期一

第四章

1. week04_1_PShape_loadShape_shape

1-1. 練習開啟 svg

1-2. google:taiwan svg 下載 svg 檔(需要有副檔名)

Ps. 檔案總管 - 檢視 - 副檔名

1-3. 開始寫程式

```
size(500, 500);
PShape taiwan = loadShap("Taiwan-icon.svg");
PShape taiwan2 = loadShap("tw.svg");
shape(taiwan);
shape(taiwan2);
```

week04_2_pushMatrix_scale_popMatrix

2-1. 複製 week04_1 的程式碼

2-2. 新增程式碼(修改圖片大小)

```
pushMatrix();
  scale(10);
  shape(taiwan);
popMatrix();

pushMatrix();
  scale(0.5);
  shape(taiwan2);
popMatrix();
```


week04_3_void_setup_void_draw_void_mouseWheel
PShape taiwan, taiwan2;
void setup(){
  size(500, 500);
  taiwan = loadShape("Taiwan-icon.svg");
  taiwan2 = loadShape("tw.svg");
}
float taiwanScale = 1;
void draw(){
  background(#1C56AF);
  pushMatrix();
    scale(10*taiwanScale);
    shape(taiwan);
  popMatrix();

pushMatrix();
  scale(0.5*taiwanScale);
  shape(taiwan2);
popMatrix();
}

void mouseWheel(MouseEvent e){
  float d = e.getCount();
  if(d > 0) taiwanScale *= 1.1;
  else taiwanScale *= 0.9;
}





week04_4_world_svg_float_s_void_mouseWheel
PShape world;
void setup(){
    size(800, 400);
    world = loadShape("world.svg");
}
float s = 0.4;
void draw(){
background(#1C56AF);
scale(s); //改用變數 s 初始值是0.4
shape(world);
}
void mouseWheel(MouseEvent e){
    if(e.getCount()>0) s *= 1.1;
    else s *= 0.9;
}


week04_5_float_x_y_translate_x_y_void_mouseDragged

PShape world;
void setup(){
  size(800, 400);
  world = loadShape("world.svg");
}
float s = 0.4, x = 0, y = 0;
void draw(){
  background(#1C56AF);
  translate(x, y);
  scale(s); //改用變數 s 初始值是0.4
  shape(world);
}
void mouseDragged(){
  x += mouseX - pmouseX;
  y += mouseY - pmouseY;
}

void mouseWheel(MouseEvent e){
  if(e.getCount()>0) s *= 1.1;
  else s *= 0.9;
}


week04_6_better_scale


PShape world;
void setup(){
  size(800, 400);
  world = loadShape("world.svg");
}
float s = 0.4, x = 0, y = 0;
float realX = 0, realY = 0;
void draw(){
  background(#1C56AF);
  translate(x, y);
  scale(s); //改用變數 s 初始值是0.4
  shape(world);
  ellipse(realX, realY, 10, 10);
}
void mouseDragged(){
  x += mouseX - pmouseX;
  y += mouseY - pmouseY;
}

void mouseWheel(MouseEvent e){
  realX = (mouseX - x)/s; //真實座標(mouseX) - 中心)/s
  realY = (mouseY - y)/s; //真實座標(mouseY) - 中心)/s
  float oldS = s;
  if(e.getCount() > 0) s *= 1.1;
  else s *= 0.9;
  x = x + realX*oldS - realX*s;
  y = y + realY*oldS - realY*s;
}


week04_7_carrot01_background_stroke_fill_ellipse

size(600, 500);
background(0);
ellipse(50, 50, 100, 100);
stroke(255);
fill(0);





week04_8_carrot02_void_setup_void_draw_void_mouseDrageed

void setup(){
  size(600, 500);
  background(0);
  stroke(255);
  fill(0);
}

void draw(){
    //ellipse(mouseX, mouseY, 100, 100);
}

float s = 25;
void mousePressed(){
  ellipse(mouseX, mouseY, s, s);
}



week04_9_carrot03_float_s_mouseButton_LEFT_RIGHT
void setup(){
  size(600, 500);
  background(0);
  stroke(255);
  fill(0);
}

void draw(){
    //ellipse(mouseX, mouseY, 100, 100);
}

float s = 25;
void mousePressed(){
  ellipse(mouseX, mouseY, s, s);
  if(mouseButton == LEFT) s *= 1.1;
  if(mouseButton == RIGHT) s *= 0.9;
}


week04_10_carrot04__float_t_cos_t_sin_t
void setup(){
  size(600, 500);
  background(0);
  stroke(255);
  fill(0);
}

void draw(){
    //ellipse(mouseX, mouseY, 100, 100);
}

float s = 25, t = 0;
void mousePressed(){
  ellipse(300 + 200*cos(t), 250 + 200*sin(t), s, s);
  t += 0.06;
  if(mouseButton == LEFT) s *= 1.1;
  if(mouseButton == RIGHT) s *= 0.9;
}





沒有留言:

張貼留言