Interactive Design: Assignment 4

Below is the code for my group’s interactive design project. Together, we all combined our codes and got this end result. My task for this project was the color coding, particle placement and the clear button.

 

 

Code:

ParticleSystem ps;

 

int wpress;

int apress;

int dpress;

int spress;

int gpress;

 

 

class ParticleSystem {

ArrayList<Particle> particles;

PVector origin;

 

ParticleSystem(PVector location) {

origin = location.get();

particles = new ArrayList<Particle>();

}

 

void addParticle() {

particles.add(new Particle(origin));

}

 

void run() {

for (int i = particles.size()-1; i >= 0; i–) {

Particle p = particles.get(i);

p.run();

if (p.isDead()) {

particles.remove(i);

}

}

}

}

class Particle {

PVector location;

PVector velocity;

PVector acceleration;

float lifespan;

int r;

int g;

int b;

 

Particle(PVector l) {

 

acceleration = new PVector(10/100000,10/100000);

velocity = new PVector(xs,ys);

location = l.get();

lifespan = random(400.0,500.0);

if(location.y > 1100){

velocity = new PVector(random(0,815),100);

/*if (keyPressed){

if (key == ‘w’){

r= 255;

g = 0;

b = 0;

 

} else {

r= 0;

g = 0;

b = 0;

}

}

/*if(wpress>1){

r= 255;

g = 0;

b = 0;

} else {

r= 0;

g = 0;

b = 0;

}*/

}

}

 

void run() {

update();

display();

}

void update() {

velocity.add(acceleration);

location.add(velocity);

lifespan -= 1;

}

 

// Method to display

void display() {

 

stroke(255, lifespan);

fill(255,0,0,lifespan);

ellipse((location.x+100)+300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(0,0,255,lifespan);

ellipse((location.x+100)-0,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(221,99,50,lifespan);

ellipse((location.x+100)-300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(200,30,90,lifespan);

ellipse((location.x+100)-600,(location.y-400)-140,20,20);

// if(location.x >= 1100){

//location.x = 1100;

//}if(location.x <= -600){

//location.x = -600;

//}

HandleKeys();

}

void HandleKeys() {

if( keyPressed == true ) {

 

switch(key) {

 

case ‘w’: {

 

PressedW();

break;

 

}

 

case ‘a’: {

 

PressedA();

break;

 

}

 

case ‘s’: {

 

PressedS();

break;

 

}

 

case ‘d’: {

 

PressedD();

break;

 

}

case ‘g’: {

 

PressedG();

break;

 

}

case ‘ ‘: {

 

//PressedSpace();

break;

 

}

 

}

 

}

}

 

void PressedW() {

stroke(255, lifespan);

fill(0,0,255,lifespan);

ellipse((location.x+100)+300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(0,0,255,lifespan);

ellipse((location.x+100)-0,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(0,0,255,lifespan);

ellipse((location.x+100)-300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(0,0,255,lifespan);

ellipse((location.x+100)-600,(location.y-400)-140,20,20);

if(ys >= 2){

ys= 2;

}

}

 

 

void PressedS() {

stroke(255, lifespan);

fill(221,99,50,lifespan);

ellipse((location.x+100)+300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(221,99,50,lifespan);

ellipse((location.x+100)-0,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(221,99,50,lifespan);

ellipse((location.x+100)-300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(221,99,50,lifespan);

ellipse((location.x+100)-600,(location.y-400)-140,20,20);

}

 

void PressedD() {

stroke(255, lifespan);

fill(200,30,90,lifespan);

ellipse((location.x+100)+300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(200,30,90,lifespan);

ellipse((location.x+100)-0,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(200,30,90,lifespan);

ellipse((location.x+100)-300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(200,30,90,lifespan);

ellipse((location.x+100)-600,(location.y-400)-140,20,20);

}

 

void PressedA() {

clear();

lifespan = 0;

}

void PressedG() {

stroke(255, lifespan);

fill(255,0,0,lifespan);

ellipse((location.x+100)+300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(255,0,0,lifespan);

ellipse((location.x+100)-0,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(255,0,0,lifespan);

ellipse((location.x+100)-300,(location.y-400)-140,20,20);

 

stroke(255,lifespan);

fill(255,0,0,lifespan);

ellipse((location.x+100)-600,(location.y-400)-140,20,20);

}

// Is the particle still useful?

boolean isDead() {

if (lifespan < 0.0) {

return true;

} else {

return false;

}

}

}

 

 

float xs;

float ys;

float x = 200;

float y = 0;

float yspeed=5;

 

void setup(){

size(1100,815);

smooth();

 

ps = new ParticleSystem(new PVector(width/2, height/2));

wpress = 0;

apress = 0;

dpress = 0;

spress = 0;

gpress = 0;

}

 

void draw(){

background(0);

fill(255);

//ellipse(mouseX, mouseY, 50, 50);

ps.addParticle();

ps.run();

xs = random(-8, 8);

ys = 8;

if(ys >= 3){

ys= 3;

}

//Handle the keypresses

}

//Handle the keypresses

Advertisements

About schinnery1996

My name is Shanelle Chinnery and I study Digital Media and Animation at Alfred State College. It’s my third year and the last time this bio was updated was on my very first day of college. I had ended off my previous bio with my desire to grow throughout my years here in Alfred State and with my senior year on the horizon, I’m glad to say I’ve definitely grown since that day. With the variety of classes and mediums I’ve experienced during these three years, I’ve learned what grasps my attention and what strays it away. I came into college with an unclear direction of what I wanted to do in my field and to be quite honest, I’m still not sure what direction I’m going in, but I have a better idea. I enjoy the storytelling aspect of animation, but then again I also enjoy animating in 3D and would love to explore the possibility of voice acting. While I’m uncertain about the exact route of my future, I still take great pride in the how much I’ve changed, art wise. I’ve gained knowledge and experience in endless number of programs I never thought I’d be able to work around, I’ve grown accustomed to digital art rather than traditional pencil to paper art, and most importantly, I’m just a better artist in general. I could say that is my favorite achievement and I can’t wait to see what my future holds in this field.
This entry was posted in Interactive and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s