2019互動技術W7
畫一個圓給移動向量
PVector user;
PVector userV;給一個速度
void setup() {
size(400, 400);畫布
user = new PVector(200, 200);一開始圓心的位置
userV = new PVector(1, 1);移動方向(1,1)方向
}
void draw() {
background(255);
ellipse(user.x, user.y, 100, 100);
user.add(userV);
if (user.x>400-50)userV.x=-1;
if (user.y>400-50)userV.y=-1;碰到畫布邊框反彈
if (user.x<50)userV.x=+1;
if (user.y<50)userV.y=+1;
}
自己畫圖(迷宮集集棒)
PImage imgMap;
void setup() {
size(400, 400);一定要跟圖片項訴大小一樣400*400
imgMap=loadImage("map.png");記得圖片拉入素本
imgMap.loadPixels();
}
void draw() {
background(imgMap);
if (imgMap.pixels[mouseX+mouseY*400]==color(237, 28, 36)) {
background(255, 0, 0);
}
fill(imgMap.pixels[mouseX+mouseY*400]);表示滑鼠碰到的色彩
rect(250, 250, 100, 100);
}
void setup() {
size(400, 400);一定要跟圖片項訴大小一樣400*400
imgMap=loadImage("map.png");記得圖片拉入素本
imgMap.loadPixels();
}
void draw() {
background(imgMap);
if (imgMap.pixels[mouseX+mouseY*400]==color(237, 28, 36)) {
background(255, 0, 0);
}
fill(imgMap.pixels[mouseX+mouseY*400]);表示滑鼠碰到的色彩
rect(250, 250, 100, 100);
}
滑鼠碰到紅線就輸了(變紅色)
很多子彈反彈
int[] value= new int[100];
PVector[]bullet=new PVector[100];
PVector[]bulletV=new PVector[100];
void setup() {
size(500, 500);
for (int i=0; i<100; i++) {
bullet[i]=new PVector(random(500), random(500));
bulletV[i]=new PVector(random(4)-2, random(4)-2);
}
}
void draw() {
background(0);
for (int i=0; i<100; i++) {
fill(255);
bullet[i].add(bulletV[i]);
ellipse(bullet[i].x, bullet[i].y, 5, 5);
if(bullet[i].x<0){bullet[i].x=0;bulletV[i].x=random(2);}
if(bullet[i].x>500){bullet[i].x=500;bulletV[i].x=-random(2);}
if(bullet[i].y<0){bullet[i].y=0;bulletV[i].y=random(2);}
if(bullet[i].x>500){bullet[i].y=500;bulletV[i].y=-random(2);}
}
}




沒有留言:
張貼留言