color backgroundCirclesColor; color foregroundCirclesColor; int foregroundStroke; float easing = 0.05; float growthEasing = 0.01; float x = 0; float y = 0; boolean showRGB = false; boolean showHSB = false; int time1; int time2; float growth = 0.0; void setup() { time1 = millis()/1000; size(320, 110); noCursor(); backgroundCirclesColor = color(242, 204, 47, 128); foregroundCirclesColor = color(242, 204, 47, 128); foregroundStroke = 255; } void mousePressed() { if (mouseButton == LEFT) { foregroundStroke = 0; foregroundCirclesColor = color(242, 204, 47, 200); } else { strokeWeight(3); foregroundCirclesColor = color(242, 204, 47, 200); } } void keyPressed() { if (key == ' ') { backgroundCirclesColor = color(242, 204, 47, 128); } else if (key == 'h') { showHSB = !showHSB; } else if (key == 'r') { showRGB = !showRGB; } else { int code = int(map(key, 32, 126, 1, 255)); backgroundCirclesColor = color( scaleColor(code + int(random(-25,25))), scaleColor(code + int(random(-25,25))), scaleColor(code + int(random(-25,25))), int(random(255)) ); } } void mouseReleased() { strokeWeight(1); foregroundStroke = 255; foregroundCirclesColor = color(242, 204, 47, 128); } void resetState() { //fill(0, 25); //rect(0, 0, width, height); fill(backgroundCirclesColor); background(0); smooth(); noCursor(); } int scaleColor(int x) { return constrain(x, 0, 255); } void drawBackground() { for (int i = 1; i < 7; i++) { ellipse(60*i - 15, 50, 50, 50); } } void draw() { time2 = millis()/1000; resetState(); drawBackground(); if (showRGB == true) drawColorRGB(2, 2); if (showHSB == true) drawColorHSB(2, 15); drawMouse(); } void drawMouse() { drawMouse(mouseX, mouseY); } void drawMouse(float targetX, float targetY) { pushMatrix(); fill(foregroundCirclesColor); stroke(foregroundStroke); x += (targetX - x) * easing; y += (targetY - y) * easing; translate(x, y); float target = dist(mouseX, mouseY, pmouseX, pmouseY)/5; if (time2 > time1) { target += 10; time1 = time2; } growth += (target - growth) * growthEasing; rotate(radians( mouseX + mouseY + frameCount) ); scale(growth + 0.5); for (int i = 0; i < 4; i++) { rotate(PI/2); ell1(); } popMatrix(); } void drawColorRGB(int x, int y) { color mouseColor = get(mouseX, mouseY); float r = red(mouseColor); float g = green(mouseColor); float b = blue(mouseColor); int boxWidth = 0; pushMatrix(); translate(x, y); // red fill(r, 0, 0); rect(0, 0, r/10, 10); //green fill(0, g, 0); rect(5 + 255/10, 0, g/10, 10); //blue fill(0, 0, b); rect(10 + 255/5, 0, b/10, 10); popMatrix(); } void drawColorHSB(int x, int y) { color mouseColor = get(mouseX, mouseY); colorMode(HSB, 255, 255, 255); float h = hue(mouseColor); float s = saturation(mouseColor); float b = brightness(mouseColor); pushMatrix(); translate(x, y); // hue fill(h, 255, 255); rect(0, 0, h/10, 10); // saturation fill(255, s, 255); rect(5 + 255/10, 0, s/10, 10); // brightness fill(0, 0, b); rect(10 + 255/5, 0, b/10, 10); popMatrix(); colorMode(RGB, 255, 255, 255); } void ell1() { float distance = 25; ellipse( distance, distance, 50, 50 ); }