玩電玩學程式!!!
先把五個檔案放進空白新頁面

左上有個迷你鋼彈

PShape gundam;
void setup()
{
size(500,500,P3D);
gundam = loadShape("Gundam.obj");
} ///不要把檔名打錯,會壞掉
void draw()
{
shape(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);//移動
scale(10,10,10);
shape(gundam);
}
奇怪的旋轉角度(壞掉版本)
PShape gundam;
void setup()
{
size(500,500,P3D);
gundam = loadShape("Gundam.obj");
}
void draw()
{
rotate(1);//單位是radians(弧度) //旋轉
translate(250,0,0);
scale(10,10,10);
shape(gundam);
}
各種旋轉(part1)
PShape gundam;
void setup()
{
size(500,500,P3D);
gundam = loadShape("Gundam.obj");
}
void draw()
{
rotateY(radians(frameCount));
translate(250,0,0);
scale(10,10,10);//x,y,z
shape(gundam);
}
各種旋轉(part2)
PShape gundam;
void setup()
{
size(500,500,P3D);
gundam = loadShape("Gundam.obj");
}
void draw()
{
rotate(radians(frameCount));
translate(250,0,0);
scale(10,10,10);//x,y,z
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);//放大10倍,但y變負的,先對y軸旋轉
rotateY(radians(frameCount));
shape(gundam);
}
轉動的地球
PShape globe;
void setup(){
size(300,300,P3D);///寬300高300
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移到中間
rotateY(radians(frameCount));
shape(globe);
}
步驟如下:
↓↓↓↓↓↓↓
讀圖檔
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);
}
void draw()
{
image(img,0,0);
//sphere(100);//原本只畫圓球,不能改
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()
{
//image(img,0,0);
//sphere(100);
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()
{
//image(img,0,0);
//sphere(100);
translate(width/2,height/2);
///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();
//image(img,0,0);
//sphere(100);
translate(width/2,height/2);
rotateY(radians(frameCount));
shape(globe);
}
心得:
今天是這學期最後一堂課,老師仔細講了每一個步驟,其中我最喜歡鋼彈的部分,看它在旋轉真的很療癒。












沒有留言:
張貼留言