void setup(){
size(1000,1000);
img0=loadImage("user0.png");
img1=loadImage("user1.png");
img2=loadImage("user2.png");

int userX=250,userY=250;
void draw(){
background(128);
if(keyPressed&&keyCode==LEFT){
image(img1,userX,userY);
userX--;
}
else if(keyPressed&&keyCode==RIGHT){
image(img2,userX,userY);
userX++;
}
else image(img0,userX,userY);
}
看到火柴人會動來動去像動畫一樣 覺得很有趣

PImage panda;
void setup(){
size(299,168);
panda=loadImage("panda.jpg");
}
int userX=100,userY=140;
void draw(){
background(panda);
ellipse(userX,userY,50,60);
if(keyPressed&&keyCode==UP) userY--;
if(keyPressed&&keyCode==RIGHT) userX++;
}
int []x=new int[1000];
int []y=new int[1000];

color[]c=new color[1000];
int n=0;
void setup(){
size(400,400);
}
void draw(){
background(255);
for(int i=0;i<n;i++){
fill(c[i]);
circle(x[i],y[i],r[i]);
y[i]--;
}
if(mousePressed) r[n-1]++;
}
void mousePressed(){
x[n]=mouseX;
y[n]=mouseY;
r[n]=10;
c[n]=color(random(255),random(255),random(255));
n++;
}
可以變換球的半徑跟顏色,很酷!!!!

class Bubble{
int x;
int y;
int r;
color c;
}
Bubble []b=new Bubble[1000];
int n=0;
void setup(){
size(400,400);
}
void draw(){
background(255);
for(int i=0;i<n;i++){
fill(b[i].c);
circle(b[i].x,b[i].y,b[i].r);
b[i].y--;
}
if(mousePressed) b[n-1].r++;
}
void mousePressed(){
b[n]=new Bubble();
b[n].x=mouseX;
b[n].y=mouseY;
b[n].r=10;
b[n].c=color(random(255),random(255),random(255));
n++;
}
Bubble []b=new Bubble[1000];
int n=0;
void setup(){
size(400,400);
}
void draw(){
background(255);
for(int i=0;i<n;i++){
b[i].drawAndUpdate();
}
if(mousePressed) b[n-1].r++;
}
void mousePressed(){
b[n]=new Bubble(mouseX,mouseY,10);
n++;
}
class Bubble{
int x;
int y;
int r;
color c;
Bubble(int _x,int _y,int _r){
x=_x;y=_y;r=_r;
c=color(random(255),random(255),random(255));
}
void drawAndUpdate(){
fill(c);
circle(x,y,r);
y--;
}
}
PImage img1;
PImage img2;
PImage img3;
PImage img;
void setup(){
size(1000,1000);
img1=loadImage("img1.png");
img2=loadImage("img2.png");
img3=loadImage("img3.png");
img=img1;
}
void draw(){
background(255);
image(img,100,100);
}
void keyPressed(){
if(keyCode==RIGHT) img=img2;
if(keyCode==LEFT) img=img3;
}
void keyReleased(){
img=img1;
}
PImage img1,img2,img3;
PImage img;
float x=100,y=100,vx=0;
void setup(){
size(1000,1000);
img1=loadImage("img1.png");
img2=loadImage("img2.png");
img3=loadImage("img3.png");
img=img1;
}
void draw(){
background(255);
image(img,x,y);
x+=vx;
}
void keyPressed(){
if(keyCode==RIGHT){ img=img2;
vx=+1;}
if(keyCode==LEFT){img=img3;
vx=-1;
}
}
void keyReleased(){
img=img1;
vx=0;
}
PImage img;
float x=10,y=10,vx=3,vy=0;
void setup(){
size(500,500);
img=loadImage("panda.jpg");
}
void draw(){
background(255);
image(img,x,y,100,100);
x+=vx;
y+=vy;
vy+=0.98;
if(x>400) vx=-3;
if(x<0) vx=+3;
if(y>400) vy=-vy*0.8;
}
void setup(){
size(300,200);
}
int angle=45;
void draw(){
background(255);
angle=mouseX;
arc(100,100,100,100,
radians(angle),radians(360-angle),PIE);
}
沒有留言:
張貼留言