Color Bars
Filed under: sketches
movingBars
final int numBars = 20; ColorBar[] bars = new ColorBar[numBars]; int RandInt (int minVal, int maxVal) { return int(random(minVal, maxVal+1)); } void setup() { size(600, 300); colorMode(HSB, 360); frameRate(30); for (int i=0; i < numBars; i++) { bars[i] = new ColorBar(RandInt(240, 360), RandInt(minWidth, maxWidth)); } } void draw() { background(0); for (int i=0; i < numBars; i++) { bars[i].drawBar(); } if ( (frameCount % 450 == 0) && (frameCount % 900 != 0) ) { // println("CHANGE!"); for (int i=0; i < numBars; i++) { bars[i].updateSpeed(1, RandInt(2, 4)); } } if (frameCount % 900 == 0) { // println("CHANGE!"); for (int i=0; i < numBars; i++) { bars[i].updateSpeed(1, RandInt(5, 7)); } } }
ColorBar
final int minWidth = 1;
final int maxWidth = 30;
class ColorBar {
float x; // x position
int w; // width of bar
float speed; // rate of motion
color c; // bar color
ColorBar (int barHue, int barWidth) {
x = RandInt(0, width-barWidth);
w = barWidth;
speed = map(w, minWidth, maxWidth, 4, 1);
float a = map(barWidth, minWidth, maxWidth, 360, 120);
c = color (barHue, 360, 360, a);
}
void drawBar() {
noStroke();
fill(c);
rect(x, 0, w, height);
moveBar();
}
void moveBar() {
// if (frameCount % speed == 0) {
x += speed;
if (x > width)
x = 0 - w;
// }
}
void updateSpeed (int newMin, int newMax) {
speed = map (w, minWidth, maxWidth, newMax, newMin);
}
}
bene posted on April 1st, 2008
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed