//import webcam
import processing.video.*;
Capture video;
//import image
PImage btn;
PImage ending;
float t=0;
//contitional switches and actions variable
int bounceaction=0;
int bounceaction2=0;
int bounceswitch=0;
int bounceswitch2=0;
int snakeaction=0;
int snakeaction2=0;
int snakeswitch=0;
int snakeswitch2=0;
int end=0;
//button variable
int button=0; //button triger
int bx=500; //button x position
int by=300; //button y position
//bounching ball variable
float x = 100;
float y = 100;
float xspeed = 3;
float yspeed = 1;
//snake variable
int[] xpos =new int[50];
int[] ypos =new int[50];
int i =0;
//time restart variable
float countdown=millis();
boolean switchs=true;
//bouncing ball function
void bounce(){
x =
x + xspeed;
y =
y + yspeed;
if
((x > width) || (x < 0)) {
xspeed = xspeed * -1;
}
if
((y > height) || (y < 0)) {
yspeed = yspeed * -1;
}
noStroke();
fill(255-random(255),255-i*5,random(255));
ellipse(x,y,60,60);
}
void bounce2() {
bounce();
if
((x+x > width) ) {
xspeed = xspeed * -1;
}
if
((y+y > height) ) {
yspeed = yspeed * -1;
}
fill(random(255),0+i*20,255);
ellipse(x+x,y+y,60,60);
}
void bounce3() {
if
((x*1.5 > width) ) {
xspeed = xspeed * -1;
}
if
((y*1.5 > height) ) {
yspeed = yspeed * -1;
}
fill(0+random(255),0+i*5,random(255));
ellipse(x*1.5,y*1.5,60,60);
}
//snake funtion
void snake(){
for
(int i=0; i < xpos.length-1; i++){
xpos[i]=xpos[i+1];
ypos[i]=ypos[i+1];
}
xpos[xpos.length-1] = mouseX;
ypos[ypos.length-1] = mouseY;
for (int i =0; i < xpos.length; i++){
noStroke();
fill(255-random(255),255-i*5,random(255));
ellipse(xpos[i],ypos[i],i,i);
}
}
void snake2 (){
for
(int i =0; i < xpos.length; i++){
noStroke();
fill(255-random(255),255-i*5,random(255));
ellipse(xpos[i],ypos[i],i,i);
fill(random(255),0+i*20,255);
rect(xpos[i]+100,ypos[i]+100,i,i);
}
}
void snake3 (){
for
(int i =0; i < xpos.length; i++){
noStroke();
fill(255-random(255),255-i*5,random(255));
ellipse(xpos[i],ypos[i],i,i);
fill(0+random(255),0+i*5,random(255));
ellipse(xpos[i]-300,ypos[i]-150,i+50,i+20);
fill(random(255),0+i*20,255);
rect(xpos[i]+100,ypos[i]+100,i,i);
}
}
void restart(){
if
(millis()-countdown > 15000) {
switchs=true;
button=5;
bounceaction=0;
bounceaction2=0;
bounceswitch=0;
bounceswitch2=0;
snakeaction=0;
snakeaction2=0;
snakeswitch=0;
snakeswitch2=0;
webcam();
}
}
void setup() {
size(800,600);
video = new Capture(this,800,600,15);
}
void webcam() {
if (video.available()) {
video.read();
}
image(video,0,0);
}
void mousePressed() { //conditional logic
that triggered after mousepress
if
(switchs){
if
(!(((mouseX > ( bx+100))||(mouseY > (by+120)))||((mouseX <
bx)||(mouseY < by))))
button= int (random(0.5,4.5));
}
if
(bounceswitch==1) //swicthes and actions condition for bouncing ball
bounceaction=1;
if
(bounceswitch2==1)
bounceaction2=1;
if
(snakeswitch==1) //swicthes and actions condition for snake
snakeaction=1;
if
(snakeswitch2==1)
snakeaction2=1;
if
(end==3) //ending condition 1 (black screen)
button=3;
if
(end==4)
button=4; //ending condition 2 (text)
}
void draw() {
webcam();
btn= loadImage("button.png"); //button image
image(btn,bx,by);
if
(button==1){ //bouncing ball
webcam();
bounce();
end=int (random(1,4.4));
bounceswitch=1;
switchs=false;
}
if
(bounceaction==1){
bounce2();
end=int (random(1,4.4));
bounceswitch2=1;
}
if
(bounceaction2==1){
bounce3();
end=int (random(3,4));
}
if
(button==2){ //snake
webcam();
snake();
end=int (random(1,4.4));
snakeswitch=1;
switchs=false;
}
if
(snakeaction==1){
snake2();
end=int (random(1,4.4));
snakeswitch2=1;
}
if
(snakeaction2==1){
snake3();
end=int (random(3,4));
}
if
(button==3){ //ending 1
background (0);
ending= loadImage("ending 1.png"); //ending image
tint (t);
image(ending,0,0);
t=t+40;
restart();
}
if
(button==4){ //ending 2
background (0);
tint (255);
restart();
}
if
(button==5){
webcam();
btn= loadImage("button.png"); //button image
image(btn,bx,by);
if (!(((mouseX > ( bx+100))||(mouseY > (by+120)))||((mouseX <
bx)||(mouseY < by)))&&(mousePressed==true)){
button= int (random(0.5,4.5));
countdown=millis();
}
}
}
No comments:
Post a Comment