Vines and Collide

Vines and Collide

6th assignment of the ICM class was to create a class that has some functionality, swap the classes with assigned partner and write a sketch that uses their classes.

As a first step I created a class called Vine and the function of the class is when user drags her mouse clicked the vines start to move and get random colors, when user releases the mouse the vines freeze and become white. Below you can find the video and the code for the class.

Vines from Danara Sarioglu on Vimeo.


Vine[] ourVines = new Vine [100];

void setup(){

size(600,600);
background(0);
for (int x=0; x<100;x++){
ourVines[x]=new Vine(x);
}
}

void draw(){
fill(0,20);
noStroke();
rect(0,0,width,height);
stroke(255,255,204);
for (int x=0; x<100;x++){
ourVines[x].drawVine();
}

}

void mouseDragged(){

//if(abs(mouseX-bendVine.controlX<100){
for (int x=0; x<100;x++){
ourVines[x].bendVine();
}
// }
}

 

class Vine {

float controlX;
float controlY;
float x;
float ystart=0;
float yend=height;
float bend;
float r=255, g=255, b=255;

Vine (float _bend) {

_bend=bend;
x=random(0, width);
controlX=x;
}

void drawVine() {
stroke(r, g, b, 100);
noFill();

bezier(x, ystart, controlX, controlY, controlX, controlY, x, yend);

r=255;
g=255;
b=255;
}

void bendVine() {

controlX=mouseX;
if (abs(mouseX-x)>100) {
controlX=x;
}

controlY=mouseY;
g=random(0, 255);
b=random(0, 255);
}
}


After creating our own classes, I and Cici combined our classes and wrote the sketch below:

Vines and Colide from Danara Sarioglu on Vimeo.


int numofvine = 100;
Vine[] vinearray = new Vine[numofvine];
int numofcollide = 10;
Collide[] collidearray = new Collide[numofcollide];

void setup() {
size(900, 900);

//player.play();

smooth();
for (int i = 0; i < vinearray.length; i++) {
for (int j = 0; j<collidearray.length; j++) {
vinearray[i] = new Vine(random(0, 1000));
collidearray[j] = new Collide(random(0, width), random(0, height));
}
}
}

void draw() {
background(0);
for (int i = 0; i < vinearray.length; i++) {
for (int j = 0; j<collidearray.length; j++) {

vinearray[i].drawVine();
vinearray[i].bendVine();
collidearray[j].drawcoll();
//collidearray[j].move();
// collidearray[j].check(mouseX, mouseY);

}
}
}

void mousePressed(){
// if(collidearray.length > 10){

// collidearray = (Collide[])subset(collidearray,1,10);
// }
collidearray = (Collide[]) append(collidearray, new Collide(mouseX, mouseY));
}

void keyPressed(){
for (int j = 0; j<collidearray.length; j++) {
collidearray[j].fall();
}
}

class Vine {

float controlX;
float controlY;
float x;
float ystart=0;
float yend=height;
float bend;
float r=255, g=255, b=255;

Vine (float _bend) {

_bend=bend;
x=random(0, width);
controlX=x;
}

void drawVine() {
stroke(r, g, b, 100);
noFill();

bezier(x, ystart, controlX, controlY, controlX, controlY, x, yend);

r=255;
g=255;
b=255;
}

void bendVine() {

controlX=mouseX;
if(abs(mouseX-x)>100){
controlX=x;
}
controlY=mouseY;
g=random(0, 255);
b=random(0, 255);
}
}

class Collide {

float x;
float y;
float radius;
boolean collided;
float speed=5;
int direction = 3;

Collide( float startX, float startY ) {
x = startX;
y = startY;
radius = 10;
collided = false;

}

void drawcoll() {

noStroke();
fill(random(0, 255), random(0, 255), random(0, 255));

noStroke();
ellipse( x, y, radius, radius );

}
void fall() {

y=y+speed;

if (y>height) {

y=0;
}
}
}