圖片需丟進程式碼裡面
PImage img; 設定圖檔名為img
Size(300,168); 視窗大小
img = loadImage("image.png"); 將圖片讀img
image( img , 0, 0) 圖片位置
PImage img; 圖檔img
PImage img1; 圖檔img1
size( 300, 168); 視窗大小
img = loadImage("image.png"); 圖片讀入img
img1 = loadImage("image2.png"); 圖片讀入img2
image( img, 0, 0); img位置
image( img1, 100, 100, 40 ,48); img1位置以及縮放大小
PImage img;
PImage img1;
void setup()
{
size( 300, 168);
img = loadImage("image.png");
img1 = loadImage("image2.png");
}
void draw()
{
image( img, 0, 0);
image( img1, mouseX-54/2, mouseY-49/2, 40 ,48);
}
img1的位置隨著滑鼠位置移動
void setup()
{
size( 800, 400);
background = loadImage("bg.png"); 背景圖
people = loadImage("l.png"); 人物圖
}
int x=0; 設定x值
void draw()
{
if(mouseX>700) x--; 當鼠標大於700背景圖向左移動
image( background, x, 0, 1500, 400);
背景圖並不大所以將大小放大
image( people, mouseX-40/2, mouseY-48/2, 40 ,48);
人物縮小並隨者滑鼠移動
}
-----------------------------------------------------------------------------------
float x=250, y=200;
float vx=1.0, vy=2.5; 移動速度
void setup()
{
size(500,400);
}
void draw()
{
ellipse( x, y, 10, 10); 球的位置和大小
x+=vx; 球的水平移動
y+=vy; 球的垂直移動
if(x>500 || x<0) vx = -vx; 當球移動到視窗外時將移動方向改變
if(y>400 || y<0) vy = -vy;
}
這是尚未完成的程式碼void setup()
{
size(500,400);
}
void draw()
{
background(255);
if(mousePressed)line( mouseX, mouseY, x, y);
當滑鼠按下時開始畫線
ellipse( x, y, 10, 10);
x+=vx;
y+=vy;
if(x>500 || x<0) vx = -vx;
if(y>400 || y<0) vy = -vy;
}
void mouseReleased()
{
vx = x-mouseX; vy = y-mouseY; 當滑鼠放開時開始移動
}
float x=250, y=200;
float vx=1.3, vy=-14; 初始向左移動並向下掉落
void setup()
{
size(500,400);
}
void draw()
{
//background(255); 將背景消除後會顯示軌跡
ellipse( x, y, 10, 10);
x+=vx;
y+=vy;
vy +=0.98; 添加重力
if(x>500 || x<0) vx = -vx*0.85; 撞向牆壁時移動速度減慢
if(y>400 || y<0) vy = -vy*0.85;
}
沒有留言:
張貼留言