I created this picture in processing and I would like to add arrays in it so that there are multiple slug "monsters" on the screen bouncing up and down.
w/o arrays, works fine
float a = 0; //variables for movement
float b = 0;
void setup()
{
size(500, 500); //size of window
background(226); //background color
smooth(); //smooth lines
strokeWeight(2.0); //line thickness
fill(100); //color in option
stroke(0); //line color
}
void draw(){
a = a+1; // sets slug to move forward
b = 20+sin(frameCount/30.0)*20; //sets slug to move up and down
if (a>500){a=-300;} //resets slug
background(200); //background color
fill(0); //color of slug
translate(a,b); //sets slug to move
strokeWeight(2.0); //line thickness
stroke(0); //line color
beginShape(); //Continous Bézier Curves to draw slug
curveVertex(20, 500); // the first control point
curveVertex(10,500);
curveVertex(80,300);
curveVertex(150,230);
curveVertex(210,220);
curveVertex(260,225);
curveVertex(290,240);
curveVertex(300,290);
curveVertex(260,290);
curveVertex(230,280);
curveVertex(210,270);
curveVertex(180,320);
curveVertex(170,380);
curveVertex(200,500);
curveVertex(170, 240); // is also the last control point
endShape();
fill(255);
ellipse(270,260,8,18); //drawing for eyes
ellipse(290,260,8,18);
fill(0);
ellipse(240,200,4,4);
ellipse(255,200,4,4);
fill(0);
triangle(260, 240, 240, 200,270, 240); //drawing for antennas
triangle(275, 240, 255, 200,285, 240);
endShape();
with arrays, not really sure what im doing...
final int NUMOFSLUGS = 5;
float x = 0;
float y = 0;
float [] xpos = new float[NUMOFSLUGS];
float [] ypos = new float[NUMOFSLUGS];
void setup() {
size(500, 500); //size of window
background(226); //background color
smooth(); //smooth lines
strokeWeight(2.0); //line thickness
fill(100); //color in option
stroke(0); //line color
}
void draw() {
changexpos(xpos);
changeypos(ypos);
drawSlug();
for (int i=0; i < xpos.length; i++)
{
drawSlug(xpos[i], ypos[i]); //whats going on here?
}
}
void changexpos (float[] x) {
for (int i=0; i < x.length; i++) {
x[i] = x[i]+1;
}
}
void changeypos (float[] y) {
for (int i=0; i < y.length; i++) {
y[i] = 20+sin(frameCount/30.0)*20;
}
}
void drawSlug() {
background(200); //background color
strokeWeight(1.5);
fill(0);
triangle(260+x, 240+y, 240+x, 200+y, 270+x, 240+y); //drawing for antennas