import processing.video.*; //Capture video; float targetRed = 255.0; //set some numbers for the target you are chasing float targetGreen = 0.0; float targetBlue = 0.0; PImage gameOver; float xBoundL = -54; // x boundary at the left side, its initial value is entered here. float xBoundR = 694; // x boundary at the right side, its initial value is entered here. float yBoundT = -27; // y boundary at the top, its initial value is entered here. float yBoundB = 508; // y boundary at the bottom, its initial value is entered here. int xFound = 0; // initialize the location of the red tracking ball int yFound = 0; float ball_dir = 1; float ball_size = 5; float h = 60; int xspeed; int yspeed; int zspeed; int xdir =1; int ydir =1; int zdir = 1; int zMin = 0; // z postion when ball is all the way up front int zMax = 200; // z position when the ball is the furthest point back towards you zBall myzBall; //zBall myPaddle; /* void captureEvent(Capture camera) { camera.read(); } */ void setup() { framerate(60); size(640,480, P3D); gameOver = loadImage("GameOver3.gif"); //define size myzBall = new zBall(8,8,20); //myPaddle = new zBall(160,120,-40,0,0,2); //print(Capture.list()); //String s = "IIDC FireWire Video"; //video = new Capture(this, 640, 480, 12); } void draw() { background(#444444); //first we draw the background myzBall.createBall(); myzBall.paddleTracker(); //myzBall.court(); /* if(myzBall.collides(myPaddle)) { zdir *= -1; //break; } else { zdir = 1; } */ //myzBall.createPaddle(); } class zBall { float x = 320; float y = 240; float z = -600; int b1 = 70; int r; zBall (int _xspeed, int _yspeed, int _zspeed) { //int _x, int _y, int _z, int _xspeed, int _yspeed, int _zspeed //x = _x; //y = _y; //z = _z; xspeed = _xspeed; yspeed = _yspeed; zspeed = _zspeed; } void createBall() { pushMatrix(); translate(320,240,-172); lights(); stroke(0); //noFill(); colorMode(RGB); fill(200,200,200,200); //box(640,480, 540); // was 340 depth popMatrix(); pushMatrix(); noStroke(); colorMode(HSB); color c1 = color(80,150,b1,255); fill(c1); lights(); translate(x, y, z); sphere(r); r = 50; x = x + (xdir*xspeed); y = y + (ydir*yspeed); z = z + (zdir*zspeed); if (zdir == 1) { b1 += 2; xBoundL += 1.96667; xBoundR -= 1.96667; yBoundT += 1.41667; yBoundB -= 1.41667; } if (zdir == -1) { b1 -= 2; xBoundL -= 1.96667; xBoundR += 1.96667; yBoundT -= 1.41667; yBoundB += 1.41667; } if (x <= xBoundL) { xdir = 1; } if (x >= xBoundR) { xdir = -1; } if (y <= yBoundT) { ydir = 1; } if (y >= yBoundB) { ydir = -1; } // if ( z >= 170 && z <= 180 && paddleRect.contains(160,120)) //if ( z >= 170 && z <= 180 && xFound > 50 && xFound < 270 && yFound > 40 && yFound < 200) { if (z >= 0 ) { /* pushMatrix(); translate(0,0,-300); image(gameOver,0,0); popMatrix(); */ } if (z <= -600 ) { zdir = 1; } /* if ( z >= 170 && z <= 180 && xFound > 50 && xFound < 270 && yFound > 40 && yFound < 200) { zdir *= -1; } */ float dis = dist(mouseX,mouseY,-50,x,y,z); //println("x = " + x + " y = " + y + " z = " + z + " dis" + dis + " zdir" + zdir); //println("xBoundL :" + xBoundL + " xBoundR :" + xBoundR + " yBoundT :" + yBoundT + " yBoundB :" + yBoundB); //println(xFound + " " + yFound); println(dis); if (dis < h) { zdir *= -1; //pushMatrix(); //translate(0,0,z); //fill(240,20,0,150); //ellipse(xFound,yFound, 150, 150); //popMatrix(); } popMatrix(); pushMatrix(); float ydis = dist(x,y,z,x,yBoundB,z); //println(ydis); float s1; s1 = ydis*.002; //s1 = s1/10; //println(s1); translate(x,y+ydis+40,z); //lights(); color c2 = color(80,20,b1-120,50); fill(c2); scale(0.7+s1, 0.1+s1); sphere(r); popMatrix(); pushMatrix(); translate(0,0,-600); fill(70); noStroke(); strokeWeight(5); rectMode(CENTER); rect(320,240,762,570); popMatrix(); pushMatrix(); translate(0,0,-600); fill(50); noStroke(); //stroke(20); strokeWeight(5); rectMode(CENTER); quad(-465, -350, -60, -44, -60, 525, -465, 825); quad(1105, -350, 700, -44, 700, 525, 1105, 825); popMatrix(); } void paddleTracker() { /* float worldRecord = 800.0; //intialize the worldrecord //Rectangle paddleRect = new Rectangle(0,0,10,10); for(int j=0; j