程式設計Week18
印出小鋼彈
程式碼:
PShape gundam;
void setup( )
{
size(500,500,P3D);
gundam=loadShape("Gundam.obj");
}
void draw( )
{
shape(gundam);
}
調整比例
程式碼:
PShape gundam;
void setup( )
{
size(500,500,P3D);
gundam=loadShape("Gundam.obj");
}
void draw( )
{
scale(10,10,10); //比例X,Y,Z
shape(gundam);
}
移位鋼彈
程式碼:
PShape gundam;
void setup( )
{
size(500,500,P3D);
gundam=loadShape("Gundam.obj");
}
void draw( )
{
translate(250,0,0); //移位250
scale(10,10,10);
shape(gundam);
}
旋轉鋼彈
程式碼:
PShape gundam;
void setup( )
{
size(500,500,P3D);
gundam=loadShape("Gundam.obj");
}
void draw( )
{
rotate(1); //旋轉
translate(250,0,0);
scale(10,10,10);
shape(gundam);
}
完整鋼彈
程式碼:
PShape gundam;
void setup( )
{
size(500,500,P3D);
gundam=loadShape("Gundam.obj");
}
void draw( )
{
background(128); //清背景
translate(250,400,0);
scale(10,-10,10);
rotateY(radians(frameCount)); //對Y軸做旋轉
shape(gundam);
}
讀取地球
程式碼:
PImage img;
void setup( )
{
size(300,300,P3D);
img=loadImage("earth.jpg");
}
void draw( )
{
image(img,0,0);
}
畫球
程式碼:
PImage img;
PShape globe;
void setup( )
{
size(300,300,P3D);
img=loadImage("earth.jpg");
globe=createShape(SPHERE,100); //功能shape
}
void draw( )
{
image(img,0,0);
shape(globe); //呼叫shape( )畫球
}
地球貼圖
程式碼:
PImage img;
PShape globe;
void setup( )
{
size(300,300,P3D);
img=loadImage("earth.jpg");
globe=createShape(SPHERE,100);
globe.setTexture(img);
}
void draw()
{
shape(globe);
}
移動地球
程式碼:
PImage img;
PShape globe;
void setup( )
{
size(300,300,P3D);
img=loadImage("earth.jpg");
globe=createShape(SPHERE,100);
globe.setTexture(img);
}
void draw( )
{
translate(300/2,300/2);
shape(globe);
}
完整地球
程式碼:
PImage img;
PShape globe;
void setup( )
{
size(300,300,P3D);
img=loadImage("earth.jpg");
globe=createShape(SPHERE,100);
globe.setStroke(false);
globe.setTexture(img);
}
void draw( )
{
background(128);
noStroke( ); //無框線
translate(width/2,height/2); //300/2,300/2到中間
rotateY(radians(frameCount));
shape(globe);
}
沒有留言:
張貼留言