« Monster Hunter Dominates Japan's Top Sellers For 2008 | Main | CTIN544 assignment4: narrative - your own Luffy »

CTIN544 assignment3: economy

import traer.physics.*;
//import processing.video.*;

//Movie myMovie;

Particle mouse, b, c;
Particle[] others;
ParticleSystem physics;

int counter = 0;//count the number of dollar signs acquired
int number = 500;//the number of particles
int maxDistance = 30;
Attraction[] attr;
int timer = 0;
int maxTime = 300;

PImage img;
PImage img2;
PImage bg;
int pwidth = 114;
int pheight = 114;

boolean handsome = true;

void setup()
{
size(640, 480);
frameRate(24);
//cursor( CROSS );
noCursor();

/* myMovie = new Movie(this, "P1040237.mov");
// Prints the duration of the movie
println(myMovie.duration());
myMovie.play();
myMovie.loop();*/

img = new PImage( 32, 32 );
img = loadImage("dollar.gif");
imageMode(CENTER);
tint( 255, 50 );
img2 = loadImage("bushhandsome.gif");
bg = loadImage("George_Bush_Economic_Recession.jpg");

physics = new ParticleSystem( 0, 0.1 );
mouse = physics.makeParticle();
mouse.makeFixed();
attr = new Attraction [number];

others = new Particle[number];
for ( int i = 0; i < others.length; i++ )
{
others[i] = physics.makeParticle( 1.0, random( 0, width ), random( 0, height ), 0 );
attr[i] = physics.makeAttraction( mouse, others[i], 5000, 50 );
}
}

void draw()
{
mouse.moveTo( mouseX, mouseY, 0 );
physics.tick();

//background( 0 );

//play movie
/*if(myMovie.available()) {
myMovie.read();
}
image(myMovie, 0, 0);*/
image(bg, 320,240);
blend(img2, 0, 0, pwidth, pheight, mouseX-pwidth/2, mouseY-pheight+32, pwidth, pheight, SOFT_LIGHT);
//image(img2, mouseX, mouseY);
for ( int i = 0; i < others.length; i++ )
{
Particle p = others[i];
handleBoundaryCollisions(p);
if (timer==0){
//img2 = loadImage("bushhandsome.gif");
distance(p);
}
image(img,p.position().x(),p.position().y());
}

checkTime();
counter = 0;
}

//bounce back at sides
void handleBoundaryCollisions( Particle p )
{
if ( p.position().x() < 0 || p.position().x() > width )
p.setVelocity( -0.9*p.velocity().x(), p.velocity().y(), 0 );
if ( p.position().y() < 0 || p.position().y() > height )
p.setVelocity( p.velocity().x(), -0.9*p.velocity().y(), 0 );
p.moveTo( constrain( p.position().x(), 0, width ), constrain( p.position().y(), 0, height ), 0 );
}

//calculate distance between p and mouse
void distance(Particle p)
{
float distance = (p.position().x()-mouseX)*(p.position().x()-mouseX) + (p.position().y()-mouseY)*(p.position().y()-mouseY);
if (distance <= maxDistance*0.9){
counter++;
}
if(counter >= number){
for ( int i = 0; i < others.length; i++ )
{
attr[i].setStrength(-5000);
}

img2 = loadImage("bushfinger.gif");
bg = loadImage("homeless.jpg");
handsome = false;
timer = maxTime;
}
}

void checkTime (){
if (timer>0){
timer--;
}
else if (handsome == false){
for ( int i = 0; i < others.length; i++ )
{
attr[i].setStrength(5000);
}
img2 = loadImage("bushhandsome.gif");
bg = loadImage("George_Bush_Economic_Recession.jpg");
handsome = true;
}
}


Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on February 21, 2009 12:03 AM.

The previous post in this blog was Monster Hunter Dominates Japan's Top Sellers For 2008.

The next post in this blog is CTIN544 assignment4: narrative - your own Luffy.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.31