Commit b6f23167 authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

Final Version

parents
//
//boolean isPayingAttention()
//{
// long now = System.nanoTime();
// if (windowingScore()>50&&(attentionScore()>50||now-lastKeyInput<1000000000||now-lastMouseInput<1000000000))
// {
// return true;
// } else
// {
// return false;
// }
//}
//
//int windowingScore()
//{
// if (wasMinimized)
// {
// return 0;
// }
//
// if (foreground)
// {
// return 100;
// }
//
// if (!obscured)
// {
// return 80;
// } else
// {
// return 20;
// }
//}
//
//int attentionScore()
//{
// long now = System.nanoTime();
// if (faces.length>0)
// lastFace = now;
// if (motionDetected)
// lastMotion = now;
// if (faces.length>0&&motionDetected)
// {
// return 100;
// } else if (faces.length>0&&!motionDetected)
// {
// return 80;
// } else if (now-lastFace<1000000000&&motionDetected)
// {
// return 60;
// } else if (now-lastFace<1000000000&&now-lastFace<1000000000)
// {
// return 51;
// } else
// {
// return 0;
// }
//}
//boolean isMinimized(HWND window)
//{
// WINDOWINFO info = new WINDOWINFO();
// User32.INSTANCE.GetWindowInfo(window, info);
//
// if ((info.dwStyle & WS_ICONIC) == WS_ICONIC) {
// return true;
// } else
// {
// return false;
// }
//}
//
//void onKeyInput()
//{
// lastKeyInput = System.nanoTime();
//}
//
//void onMouseInput()
//{
// lastMouseInput = System.nanoTime();
//}
//
//void captureEvent(Capture c) {
// c.read();
//}
//
//boolean hasWhite(PImage image)
//{
// for (int i = 0; i< image.pixels.length; i++)
// {
// if (image.pixels[i]==color(255, 255, 255))
// return true;
// }
// return false;
//}
//
//boolean isObscured()
//{
// HWND currWindow = User32.INSTANCE.GetForegroundWindow();
// int i = 0;
//
// //get all the size/positions of windows above the window of interest
// while (i<1000)
// {
//
// /*if(stateChanged)
// {
// char[] asdf = new char[200];
// User32.INSTANCE.GetWindowText(currWindow, asdf, 200);
// println(Native.toString(asdf));
// }*/
// RECT currRect = new RECT();
// User32.INSTANCE.GetWindowRect(currWindow, currRect);
// User32.INSTANCE.GetWindowText(currWindow, windowText, strBuffSize);
//
// //see we are at the window of interest
// //if we are, save the size/position and exit search
// if (Native.toString(windowText).compareTo(windowTitle) == 0)
// {
// rectOfInterest = currRect;
// if (currWindow!=null)
// windowOfInterest = currWindow;
// break;
// } else
// {
// //add positions/size of current window and get next window
// aboveWindows.add(currRect);
// currWindow = User32.INSTANCE.GetWindow(currWindow, new DWORD(User32.GW_HWNDNEXT));
// i++;
// }
// }
// boolean r = checkOverlap();
// aboveWindows.clear();
// return r;
//}
//
//boolean checkOverlap()
//{
// //compare above window positions to window of interest to see if they overlap
// for (RECT currRect : aboveWindows)
// {
// //four cases of non overlap
// if (rectOfInterest.left > currRect.right) //completely to the right
// {
// continue;
// }
// if (rectOfInterest.right < currRect.left) //completely to the left
// {
// continue;
// }
// if (rectOfInterest.top > currRect.bottom) //completely below
// {
// continue;
// }
// if (rectOfInterest.bottom < currRect.top) //completely above
// {
// continue;
// }
// return true;
// }
// return false;
//}
//
//public class InputReceiver implements NativeKeyListener, NativeMouseInputListener
//{
// AttentionDrawing sketch;
//
// InputReceiver(AttentionDrawing s) {
// try {
// GlobalScreen.registerNativeHook();
// }
// catch (NativeHookException ex) {
// System.err.println("There was a problem registering the native hook.");
// System.err.println(ex.getMessage());
//
// System.exit(1);
// }
// //Add the appropriate listeners for the example object.
// GlobalScreen.addNativeMouseListener(this);
// GlobalScreen.addNativeMouseMotionListener(this);
// GlobalScreen.addNativeKeyListener(this);
//
// sketch = s;
// }
//
// void nativeKeyPressed(NativeKeyEvent e) {
// sketch.onKeyInput();
// }
//
// void nativeKeyReleased(NativeKeyEvent e) {
// sketch.onKeyInput();
// }
//
// void nativeKeyTyped(NativeKeyEvent e) {
// sketch.onKeyInput();
// }
//
// void nativeMouseClicked(NativeMouseEvent e) {
// sketch.onMouseInput();
// }
//
// void nativeMousePressed(NativeMouseEvent e) {
// sketch.onMouseInput();
// }
//
// void nativeMouseReleased(NativeMouseEvent e) {
// sketch.onMouseInput();
// }
//
// void nativeMouseMoved(NativeMouseEvent e) {
// sketch.onMouseInput();
// }
//
// void nativeMouseDragged(NativeMouseEvent e) {
// sketch.onMouseInput();
// }
//}
//
//
// The Nature of Code
// <http://www.shiffman.net/teaching/nature>
// Spring 2012
// Box2DProcessing example
// A fixed boundary class (now incorporates angle)
class Boundary {
// A boundary is a simple rectangle with x,y,width,and height
float x;
float y;
float w;
float h;
// But we also have to make a body for box2d to know about it
Body b;
Boundary(float x_, float y_, float w_, float h_, float a) {
x = x_;
y = y_;
w = w_;
h = h_;
// Define the polygon
PolygonShape sd = new PolygonShape();
// Figure out the box2d coordinates
float box2dW = box2d.scalarPixelsToWorld(w/2);
float box2dH = box2d.scalarPixelsToWorld(h/2);
// We're just a box
sd.setAsBox(box2dW, box2dH);
// Create the body
BodyDef bd = new BodyDef();
bd.type = BodyType.STATIC;
bd.angle = a;
bd.position.set(box2d.coordPixelsToWorld(x, y));
b = box2d.createBody(bd);
// Attached the shape to the body using a Fixture
b.createFixture(sd, 1);
}
// Draw the boundary, it doesn't move so we don't have to ask the Body for location
void display() {
fill(0);
stroke(0);
strokeWeight(1);
rectMode(CENTER);
float a = b.getAngle();
pushMatrix();
translate(x, y);
rotate(-a);
rect(0, 0, w, h);
popMatrix();
}
}
// The Nature of Code
// <http://www.shiffman.net/teaching/nature>
// Spring 2010
// Box2DProcessing example
// A rectangular box
class Box {
// We need to keep track of a Body and a width and height
Body body;
float w;
float h;
int r, g, b;
// Constructor
Box(float x, float y, int r, int g, int b) {
// w = random(4, 16);
// h = random(4, 16);
w = 40;
h=40;
this.r = r;
this.g = g;
this.b = b;
// Add the box to the box2d world
makeBody(new Vec2(x, y), w, h);
}
// This function removes the particle from the box2d world
void killBody() {
box2d.destroyBody(body);
}
// Is the particle ready for deletion?
boolean done() {
// Let's find the screen position of the particle
Vec2 pos = box2d.getBodyPixelCoord(body);
// Is it off the bottom of the screen?
if (pos.y > height+w*h) {
killBody();
return true;
}
return false;
}
// Drawing the box
void display() {
// We look at each body and get its screen position
Vec2 pos = box2d.getBodyPixelCoord(body);
// Get its angle of rotation
float a = body.getAngle();
rectMode(CENTER);
pushMatrix();
translate(pos.x, pos.y);
rotate(-a);
fill(r, g, b);
stroke(0);
rect(0, 0, w, h);
popMatrix();
}
// This function adds the rectangle to the box2d world
void makeBody(Vec2 center, float w_, float h_) {
// Define a polygon (this is what we use for a rectangle)
PolygonShape sd = new PolygonShape();
float box2dW = box2d.scalarPixelsToWorld(w_/2);
float box2dH = box2d.scalarPixelsToWorld(h_/2);
sd.setAsBox(box2dW, box2dH);
// Define a fixture
FixtureDef fd = new FixtureDef();
fd.shape = sd;
// Parameters that affect physics
fd.density = 1;
fd.friction = 0.3;
fd.restitution = 0.5;
// Define the body and make it from the shape
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(box2d.coordPixelsToWorld(center));
body = box2d.createBody(bd);
body.createFixture(fd);
// Give it some initial random velocity
body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
body.setAngularVelocity(random(-5, 5));
}
void applyForce(Vec2 v) {
body.applyForce(v, body.getWorldCenter());
//body.setLinearVelocity(v);
}
}
// The Nature of Code
// <http://www.shiffman.net/teaching/nature>
// Spring 2010
// Box2DProcessing example
// A rectangular box
class Box {
// We need to keep track of a Body and a width and height
Body body;
float w;
float h;
int r,g,b;
// Constructor
Box(float x, float y,int t,int g,int b) {
// w = random(4, 16);
// h = random(4, 16);
w = 40;
h=40;
this.r = r;
this.g = g;
this.b = b;
// Add the box to the box2d world
makeBody(new Vec2(x, y), w, h);
}
// This function removes the particle from the box2d world
void killBody() {
box2d.destroyBody(body);
}
// Is the particle ready for deletion?
boolean done() {
// Let's find the screen position of the particle
Vec2 pos = box2d.getBodyPixelCoord(body);
// Is it off the bottom of the screen?
if (pos.y > height+w*h) {
killBody();
return true;
}
return false;
}
// Drawing the box
void display() {
// We look at each body and get its screen position
Vec2 pos = box2d.getBodyPixelCoord(body);
// Get its angle of rotation
float a = body.getAngle();
rectMode(CENTER);
pushMatrix();
translate(pos.x, pos.y);
rotate(-a);
fill(175);
stroke(0);
rect(0, 0, w, h);
popMatrix();
}
// This function adds the rectangle to the box2d world
void makeBody(Vec2 center, float w_, float h_) {
// Define a polygon (this is what we use for a rectangle)
PolygonShape sd = new PolygonShape();
float box2dW = box2d.scalarPixelsToWorld(w_/2);
float box2dH = box2d.scalarPixelsToWorld(h_/2);
sd.setAsBox(box2dW, box2dH);
// Define a fixture
FixtureDef fd = new FixtureDef();
fd.shape = sd;
// Parameters that affect physics
fd.density = 1;
fd.friction = 0.3;
fd.restitution = 0.5;
// Define the body and make it from the shape
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(box2d.coordPixelsToWorld(center));
body = box2d.createBody(bd);
body.createFixture(fd);
// Give it some initial random velocity
body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
body.setAngularVelocity(random(-5, 5));
}
void applyForce(Vec2 v) {
body.applyForce(v, body.getWorldCenter());
}
}
class Person {
String user;
int r, g, b;
Box box;
float x, y;
ArrayList<Point> points;
Person(String user, int r, int g, int b, float x, float y)
{
this.user = user;
this.r = r;
this.g = g;
this.b = b;
this.x=x;
this.y=y;
box = new Box(x, y, r, g, b);
points = new ArrayList<Point>();
}
void drawTank()
{
Vec2 pos = box2d.getBodyPixelCoord(box.body);
float a = box.body.getAngle();
box.display();
// if(!attention)
points.add(new Point(pos.x, pos.y, a, r, g, b, attention));
}
void drawPoints()
{
ArrayList<Point> rpoints = new ArrayList<Point>(); //<>//
//for(Point a : points)
for (int i=0;i<points.size();i++)
{
Point a= points.get(i);
if (points.indexOf(a) == 1)
{
pushMatrix();
fill(0, 0, 0);
rect(a.x, a.y, 20, 20);
popMatrix();
}
if (!a.seen)
{
if (!attention)
{
a.framesNotSeen++;
}
else a.framesSeen++;
pushMatrix();
if (255 - a.framesNotSeen - a.framesSeen - this.points.indexOf(this)>=145)
fill(r, g, b, 255 - a.framesNotSeen);
else
fill(r, g, b, 145 - a.framesSeen + this.points.indexOf(this));
if (145 - a.framesSeen+ this.points.indexOf(this) <=0)
a.seen = true;
noStroke();
translate(a.x, a.y);
rotate(-a.angle);
rect(0, 0, 20, 20);
popMatrix();
}
if (a.seen)
rpoints.add(a);
}
this.points.removeAll(rpoints);
}
void applyForce(Vec2 force)
{
box.applyForce(force);
}
}
class Person {
String user;
int r,g,b;
Box box;
boolean seen ;
int framesSeen,framesNotSeen;
float x,y;
ArrayList<Point> points;
Person(String user,int r,int g,int b,float x,float y)
{
this.user = user;
this.r = r;
this.g = g;
this.b = b;
this.seen = seen;
this.framesSeen =0;
this. framesNotSeen = 0;
this.x=x;
this.y=y;
box = new Box(x,y);
points = new ArrayList<Point>();
}
void drawTank()
{
box.display();
if(!attention)
{
}
}
}
import java.io.*;
class Point implements Serializable {
float x, y, angle;
int r, g, b;
boolean seen ;
int framesSeen, framesNotSeen;
public Point(float x, float y, float