2024年9月30日 星期一

Week04 你諸位十連四金啊

 04-1(.svg)

下載 .svg



//week04_1_PShape_load_shape

PShape taiwan = loadShape("Taiwan-icon.svg");

PShape taiwan2 = loadShape("tw.svg");

size(500,500);

shape(taiwan);

shape(taiwan2);



04-2(調整大小)

//week04_2_pushMatrix_scale_popMatrix

size(500, 500);

PShape taiwan = loadShape("Taiwan-icon.svg");

PShape taiwan2 = loadShape("tw.svg");

pushMatrix();

  scale(10);

  shape(taiwan);

popMatrix();


pushMatrix();

  scale(0.5);

  shape(taiwan2);

popMatrix();

04-3(調整大小)

//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(15,88,255);
  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.05;
 else taiwanScale *= 0.95;
}


04-4(世界地圖 調整大小)

//week04_4_world_svg_float_s_scale_s_void_mouseWheel

PShape world;

void setup(){

 size(1000,500);

 world = loadShape("world.svg");

}

float s = 0.5;

void draw(){

 background(#92C2F5);

 scale(s);

 shape(world);

}


void mouseWheel(MouseEvent e){

 if(e.getCount()>0) s *= 1.05;

 else s *= 0.95;

}


04-5(世界地圖 調整位置)

//week04_5_world_svg_translate_XY
PShape world;
void setup(){
 size(1000,500);
 world = loadShape("world.svg");
}
float s = 0.5,x=0,y=0;
void draw(){
 background(#92C2F5);
 translate(x,y);
 scale(s);
 shape(world);
}
void mouseDragged(){
 x +=mouseX-pmouseX;
 y +=mouseY-pmouseY;
}


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


04-6(世界地圖 以鼠標調整位置)

//week04_6_world_svg_better_scale

PShape world;

void setup() {

  size(1000, 500);

  world = loadShape("world.svg");

}

float s = 0.5, x=0, y=0;

float realX = 0, realY = 0;

void draw() {

  background(#92C2F5);

  translate(x, y);

  scale(s);

  shape(world);

  ellipse(realX, realY, 10/s, 10/s);

  noStroke();

  fill(255,0,0);

}

void mouseDragged() {

  x +=mouseX-pmouseX;

  y +=mouseY-pmouseY;

}



void mouseWheel(MouseEvent e) {

  realX = (mouseX -x) /s;

  realY = (mouseY -y) /s;

  float oldS = s;

  if (e.getCount()>0) s *= 1.05;

  else s *= 0.95;

  x = x +realX*oldS - realX*s;

  y = y +realY*oldS - realY*s;

}


04-7(圈)

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



04-8(可控的圈)

//week04_8_carrot02_void_setup_void_draw_void_mousePressed

void setup() {

  size(600, 500);

  background(0);

  stroke(255);

  fill(0);

}

void draw() {

  //

}


void mousePressed() {

  ellipse(mouseX, mouseY, 99, 99);

}


04-9(可控大小的圈)

//week04_9_carrot03_left_right_button

void setup() {

  size(600, 500);

  background(0);

  stroke(255);

  fill(0);

}

void draw() {

  //

}

float s = 25;

void mousePressed() {

  ellipse(mouseX, mouseY, s, s);

  if(mouseButton==LEFT) s = s*1.1;

  if(mouseButton==RIGHT) s = s*0.9;

}



04-a(圈組成圈)

//week04_a_carrot04_cos_sin_t

void setup() {

  size(600, 500);

  background(0);

  stroke(255);

  fill(0);

}

void draw() {

  //

}

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 = s*1.1;

  if (mouseButton==RIGHT) s = s*0.9;

}




沒有留言:

張貼留言