class Vehicle1{ int c_dia; // vehicle diameter color c; // color float xpos, ypos; // position variables float xspeed_0; // Speed of the shape float yspeed_0; // Speed of the shape int xdirection; // - Left or + Right int ydirection; // - Top or + Bottom // CONSTRUCTOR Vehicle1(int dia, color c_) { c_dia = dia; c = c_; reset(); // reset initial positions, speeds, & directions } void draw() { // Get the "temperature" at the pixel to determine speed int xipos = int(xpos); int yipos = int(ypos); int cp = get(xipos + c_dia/2, yipos + c_dia/2); float temp = red(cp); // Update the position of the shape xpos = xpos + random(-c_dia, c_dia) / 4 + ( xspeed_0 * (temp / 255) * xdirection); ypos = ypos + random(-c_dia, c_dia) / 4 + ( yspeed_0 * (temp / 255) * ydirection); // Test to see if the shape exceeds the boundaries of the screen // If it does, reverse its direction by multiplying by -1 if (xpos + c_dia/2 > width|| xpos - c_dia/2 < 0) { xdirection *= -1; } if (ypos + float(c_dia)/2 > height || ypos - float(c_dia)/2 < 0) { ydirection *= -1; } stroke(0,64,0); fill(c); ellipseMode(CENTER); ellipse(xpos, ypos, c_dia, c_dia); //ellipse(xpos+c_dia/2, ypos+c_dia/2, c_dia, c_dia); if(mousePressed){ reset(); } } void reset(){ xpos = random(.2 * width, .8 * width); //load random starting position ypos = random(.2 * height, .8 * height); xspeed_0 = random(0, 96 / c_dia); yspeed_0 = random(0, 96 / c_dia); float rand_ix = random(-1, 1); if(rand_ix > 0){ xdirection = 1; } else{ xdirection = -1; } float rand_iy = random(-1, 1); if(rand_iy > 0){ ydirection = 1; } else{ ydirection = -1; } } }