ICM WK6 Array&ArrayLists

The way I set it up is, replacement or addition to this array is number will have choice of two paths of movement: “butterfly all over” or “bee upper half” of the screen.

I started with say 100, if the number is below 15, then shows the image of bee, which stays only he upper half of screen.

The rest, will play image of butterfly, which will fly all over of screen.

If you want to add more objects, either play with numbers, or redefine the the number range.

Main Tab

//Fly
PImage sky;
PImage bee;
PImage butterfly;
Fly[]Flyings=new Fly[100];
//float i;

void setup() {
size(800,600);
smooth();
sky=loadImage(“sky.jpg”);
butterfly=loadImage(“butterfly.jpg”);
bee=loadImage(“bee.jpg”);

for (int i=0;i<100;i++){
Flyings[i]= new Fly(color(random(255),random(255),random(255)),random(5));
}
}

void draw () {
image(sky,0,0);
for(int i=0; i<50;i++){
Flyings[i].display(i);
Flyings[i].move();

}
}

 

Class_Fly

float y;
float diameter;
float x_increment, y_increment;
color c;
//float x_bee;
float y_bee;

Fly(color temp_c, float temp_speed){
x=width;//butterfly x
y=height/2;//butterfly y
diameter=25;
c = temp_c;
x_increment = y_increment =temp_speed ;
//float x_bee =width/3;
float y_bee =height/3;

}

void display(int num){
fill(c);
stroke(255);
strokeWeight (0);

if (num<15){
tint(255,100);
image(bee,x,y_bee,diameter,diameter);

}
else{

tint(255,100);
image(butterfly,x,y,diameter, diameter);
}
}
void move(){
x = x + x_increment;
y = y + y_increment;

//x_bee= x_bee+x_increment;
y_bee= y_bee+y_increment;
if (x > width || x < 0) { //i
x_increment = x_increment *-1;
}
if (y > height || y < 0) {
y_increment = y_increment *-1;

}
}
}

Screen Shot 2014-10-21 at 7.49.49 AM

Leave a Reply