//week14_PFont
size(300, 300);
textSize(50); //50幾號字
text("Hello", 10, 50); //預設字型
PFont font = createFont("Times New Roman", 50);
textFont(font); //換字型
text("Hello", 10, 100); //放下面點
//print(PFont.list()); //列出現在可用類型
//改成 for 迴圈 把全部字型列出來 分行
for(String name : PFont.list()) println(name);
----------------------------------------------------------------------
//week14-2
PFont font1, font2, font3;
void setup(){
size(300,300);
font1 = createFont("Times New Roman Italic", 50);
font2 = createFont("微軟正黑體 Bold", 50);
font3 = createFont("elffont-rock.otf", 50);
}
void draw(){
background(0);
cursor(CROSS);
fill(255);
textFont(font1);
text("Hello 中文", mouseX+20, mouseY-20);
fill(#FF8E8E); //Tool - Color Selector 再配上你要的顏色
textFont(font2);
text("Hello 中文", mouseX+20, mouseY+50);
textFont(font3);
text("ㄅㄆㄇ", mouseX+20, mouseY+100);
}
-------------------------------------------------------------------------------
//week14-3
void setup(){
size(400,400);
}
float [] angle = new float[5];
void draw(){
background(255);
translate(200,350);
ellipse(0,0,12,12); //(0,0)放圖
pushMatrix();
rotate(radians(angle[0]));
rect(0,-5,50,10); //直的棒子
pushMatrix();
translate(50,0);
rotate(radians(angle[1]));
rect(0,-5,50,10);
popMatrix();
popMatrix();
}
void mouseDragged(){
angle[ID] += mouseX - pmouseX;
}
int ID = 0;
void keyPressed(){
if(key=='0') ID = 0;
if(key=='1') ID = 1;
}
----------------------------------------------------------------------------------------------
//week14-5&6
void setup(){
size(400,400);
for(int i=0; i<2; i++){
p[i] = new PVector(200,350-50*i);
}
}
PVector [] p = new PVector[6];
void draw(){
background(255);
for(int i=0; i<2; i++){
if(i>0) line(p[i-1].x, p[i-1].y,p[i].x,p[i].y);
fill(255,0,0);
ellipse(p[i].x,p[i].y,8,8);
fill(0);
text("p:" +i, p[i].x+10, p[i].y);
}
PVector now = new PVector(mouseX, mouseY);
PVector v = PVector.sub(now, p[0]).normalize().mult(50);
p[1].x = p[0].x + v.x;
p[1].y = p[0].y + v.y;
ellipse(mouseX, mouseY, 6, 6);
line(p[0].x, p[0].y, mouseX, mouseY);
}
-----------------------------------------------------------------------------------------------------
//week14-7&8
void setup(){
size(400,400);
for(int i=0; i<6; i++){
p[i] = new PVector(200,350-50*i);
}
}
PVector [] p = new PVector[6];
void draw(){
background(255);
for(int i=0; i<6; i++){
if(i>0) line(p[i-1].x, p[i-1].y,p[i].x,p[i].y);
fill(255,0,0);
ellipse(p[i].x,p[i].y,8,8);
fill(0);
text("p:" +i, p[i].x+10, p[i].y);
}
PVector now = new PVector(mouseX, mouseY);
for(int i=5; i>=0; i--){
PVector v = PVector.sub(now, p[i]).normalize().mult(50);
p[i].x = now.x - v.x;
p[i].y = now.y - v.y;
now = p[i];
}
ellipse(mouseX, mouseY, 6, 6);
//line(p[4].x, p[4].y, mouseX, mouseY);
}
-------------------------------------------------------------------------------
//week14-9
void setup(){
size(400,400);
for(int i=0; i<6; i++){
p[i] = new PVector(200,350-50*i);
}
}
PVector [] p = new PVector[6];
void draw(){
background(255);
for(int i=0; i<6; i++){
if(i>0) line(p[i-1].x, p[i-1].y,p[i].x,p[i].y);
fill(255,0,0);
ellipse(p[i].x,p[i].y,8,8);
fill(0);
text("p:" +i, p[i].x+10, p[i].y);
}
PVector now = new PVector(mouseX, mouseY);
p[5].x = now.x;
p[5].y = now.y;
for(int i=4; i>0; i--){
PVector v = PVector.sub(p[i+1], p[i]).normalize().mult(50);
p[i].x = p[i+1].x - v.x;
p[i].y = p[i+1].y - v.y;
}
for(int i=1; i<=5; i++){
PVector v = PVector.sub(p[i], p[i-1]).normalize().mult(50);
p[i].x = p[i-1].x + v.x;
p[i].y = p[i-1].y + v.y;
}
ellipse(mouseX, mouseY, 6, 6);
//line(p[4].x, p[4].y, mouseX, mouseY);
}





沒有留言:
張貼留言