extrapixel
Full Member
Offline
Posts: 210
Switzerland
Re: 'Remix' my sketch
Reply #3 - Jun 7th , 2008, 5:17am
my 2 lines. unfortunately "copy for web" messed up the code.. so here it is plain: // list that holds circles ArrayList circles; // number of circles to create initially int circleCount = 40; // max and min size of circles float maxSize = 25; float minSize = 5; // max speed for circles float speed = .8; float counter = 0.0; color colors[] = { color(255,0,0,20), color(0,6), color(0,6)}; void setup() { size(250, 250); //background(255); noStroke(); smooth(); // fill the circles list with circle objects circles = new ArrayList(); for (int i=0; i<circleCount; i++) { // pick a color from the color list color circleColor = colors[(int)random(colors.length)]; // add the circle to circles list circles.add(new Circle(random(width), random(height), random(maxSize - minSize) + minSize, circleColor)); } background(0); loadPixels(); } void draw() { counter += .075; // loop through each pixel float disn; Circle circ; for(int y=0; y<height; y++) { for(int x=0; x<width; x++) { // choose a random circle circ = (Circle) circles.get((int)random(circles.size())); // find distance from current pixel to circle disn = dist(x, y, circ.x, circ.y); // if the pixel is inside the circle, than set that pixel's color if(disn < circ.r) { pixels[y*width+x] = lerpColor(pixels[y*width+x], circ.c, disn/(circ.r)); } } } updatePixels(); // loop through the circle objects in circles list for (int i=0; i<circles.size(); i++) { Circle circle = (Circle) circles.get(i); // move circles circle.move(); // draw circle's outlines circle.display(); } } class Circle { // x and y position, radius, x and y velocities float x, y, r, rbase, vx, vy, offset; // circle color color c; Circle(float _x, float _y, float _r, color _c) { x = _x; y = _y; rbase = _r; r = _r; c = _c; vx = random(-speed, speed); vy = random(-speed, speed); offset = random(0,10); } // draw circle void display() { noFill(); stroke(random(50,255)); ellipse(x, y, r*2, r*2); } // move circle void move() { // oscillate the radius r = rbase + sin(counter+offset)*15; // bounce against the sides if (x - r/4 < 0) { x = r/4 + 1; vx *= -1; } else if (x + r/4 > width) { x = width - r/4 - 1; vx *= -1; } if (y - r/4 < 0) { y = r/4 + 1; vy *= -1; } else if (y + r/4 > height) { y = height - r/4 - 1; vy *= -1; } // add velocities to position x += vx; y += vy; } }