1.
size(300,300);
textSize(50);
text("Hello",10,50);//預設字型
PFont font = createFont("Times New Roman",50);
textFont(font);//換字型
text("Hello",10,100);
for( String name : PFont.list()) println(name);//用for迴圈把全部字型印出來
2.
///下載字型後直接點兩下打開安裝,安裝完直接拖進程式即可
PFont font1,font2,font3;
void setup(){
size(300,300);
font1 = createFont("Times New Roman Bold Italic",50);
font2 = createFont("微軟正黑體 Bold",50);
font3 = createFont("elffont-rock.otf",50);
}
void draw(){
background(#C0EBD7);
cursor(CROSS);
fill(0,255,0);
textFont(font1);
text("Hello 中文", mouseX+20,mouseY-20);
fill(#F98D74);
textFont(font2);
text("Hello 中文", mouseX+20,mouseY+50);
textFont(font3);
text("ㄅㄆㄇ", mouseX+20,mouseY+100);
}
4.
void setup(){
size(400,400);
}
float [] angle = new float[5];
void draw(){
background(#C0EBD7);
translate(200,350);
ellipse(0,0,12,12);
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;
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(#C0EBD7);
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(#F98D74);
ellipse(p[i].x,p[i].y,8,8);
fill(#5d8f2c);
text("p:"+i,p[i].x+10,p[i].y);
}
ellipse(mouseX,mouseY,6,6);
line(p[0].x,p[0].y,mouseX,mouseY);
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(#C0EBD7);
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(#F98D74);
ellipse(p[i].x,p[i].y,8,8);
fill(#5d8f2c);
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);
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(#C0EBD7);
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(#F98D74);
ellipse(p[i].x,p[i].y,8,8);
fill(#5d8f2c);
text("p:"+i,p[i].x+10,p[i].y);
}
PVector now = new PVector(mouseX,mouseY);
PVector v = PVector.sub(now,p[4]).normalize().mult(50);
p[5].x = p[4].x+v.x;
p[5].y = p[4].y+v.y;
ellipse(mouseX,mouseY,6,6);
line(p[4].x,p[4].y,mouseX,mouseY);
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(#C0EBD7);
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(#F98D74);
ellipse(p[i].x,p[i].y,8,8);
fill(#5d8f2c);
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);
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(#C0EBD7);
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(#F98D74);
ellipse(p[i].x,p[i].y,8,8);
fill(#5d8f2c);
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(now,p[i]).normalize().mult(50);
p[i].x = now.x-v.x;
p[i].y = now.y-v.y;
now = p[i];
}
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);
void setup(){
size(400,400);
for(int i=0;i<N;i++){
p[i] = new PVector(200,350-L*i);
}
}
int N = 20,L = 300/N;
PVector [] p = new PVector[N];
void draw(){
background(#C0EBD7);
for(int i=0;i<N;i++){
if(i>0) line(p[i-1].x,p[i-1].y,p[i].x,p[i].y);
fill(#F98D74);
ellipse(p[i].x,p[i].y,8,8);
fill(#5d8f2c);
text("p:"+i,p[i].x+10,p[i].y);
}
p[N-1].x = mouseX;
p[N-1].y = mouseY;
for(int i=N-2;i>0;i--){
PVector v = PVector.sub(p[i+1],p[i]).normalize().mult(L);
p[i].x = p[i+1].x-v.x;
p[i].y = p[i+1].y-v.y;
}
for(int i=1;i<N;i++){
PVector v = PVector.sub(p[i],p[i-1]).normalize().mult(L);
p[i].x = p[i-1].x+v.x;
p[i].y = p[i-1].y+v.y;
}
ellipse(mouseX,mouseY,6,6);
沒有留言:
張貼留言