//week04_1_PShape_loadShape-shape
//google下載svg檔
//PImage img = loadImage("image.jpg");上週教的
PShape taiwan = loadShape("Taiwan-icon.svg");
PShape taiwan2 = loadShape("tw.svg");
size(500,500);
shape(taiwan);
shape(taiwan2);
載入svg檔案
//week04_2_pushMatrix_scale_popMatrix
//google下載svg檔
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();
改變他的大小
//week04_3_void_setup_voiddraw_void_wheelMouse //google下載svg檔 PShape taiwan, taiwan2; void setup() { size(500, 500); taiwan = loadShape("Taiwan-icon.svg"); taiwan2 = loadShape("tw.svg"); } float taiwanScale = 1; void draw() { background(#92C2F5); 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_scale_s_void_mouseWheel_s
PShape world;
void setup(){
size(800,400);
world = loadShape("world.svg");
}
float s = 0.4;
void draw(){
background(#92C2F5);
scale(s);
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(#92C2F5); translate(x,y);//加上一個移動量x,y scale(s); shape(world); } void mouseDragged(){ x += mouseX-pmouseX; y += mouseY-pmouseY; } void mouseWheel(MouseEvent e) { if (e.getCount()>0)s *=0.9; else s *=1.1; } 加上滑鼠拖曳的功能
///
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(#92C2F5);
translate(x,y);//加上一個移動量x,y
scale(s);
shape(world);
}
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 *=0.9;
else s *=1.1;
x=x+realX*oldS-realX*s;
y=y+realY*oldS-realY*s;
}
在鼠標的位置(座標)進行放大
//week04_7_carrot01_background_stroke_fill_ellipse size(600,500); background(0); stroke(255); fill(0); ellipse(50,50,100,100);劃一個圈//week04_8_carrot02_void_setup_void_draw_void_mouseDragged void setup(){ size(600,500); background(0); stroke(255); fill(0); } void draw(){ //ellipse(mouseX,mouseY,100,100); } void mousePressed(){ ellipse(mouseX,mouseY,100,100); } 每按一次滑鼠下一個圈圈會越來越大//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_cos_t_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 *=1.1; if(mouseButton==RIGHT)s *=0.9; } 自動畫圓
沒有留言:
張貼留言