-
-
Save jkwok91/17609559910e4b551ac3 to your computer and use it in GitHub Desktop.
spiraly dots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
drawing dots in a circle | |
*/ | |
float colorFloat; | |
float angle; | |
float radius, maxRadius, delta; | |
Dot[] tail; | |
void setup() { | |
size(200, 200); | |
frameRate(12); | |
smooth(); | |
maxRadius = 25; | |
tail = new Dot[15]; | |
for (int i = 0; i < tail.length; i++) { | |
tail[i] = new Dot(radius*cos(angle), radius*sin(angle), colorFloat); | |
} | |
} | |
void draw() { | |
background(0); | |
translate(mouseX, mouseY); | |
for (int i = 0; i < tail.length-1; i++) { | |
tail[i] = tail[i+1]; | |
tail[i].display(i); | |
} | |
radius += delta; | |
delta = (radius == 0) ? 0.5 : ((radius == maxRadius) ? -0.5 : delta); | |
Dot d = new Dot(radius*cos(angle), radius*sin(angle), colorFloat); | |
tail[tail.length-1] = d; | |
d.display(tail.length-1); | |
angle = (angle+.5)%TWO_PI; | |
colorFloat += .5; | |
} | |
class Dot { | |
color c; | |
PVector loc; | |
Dot(float x, float y, float f) { | |
loc = new PVector(x, y); | |
c = getColor(f); | |
} | |
void display(int a) { | |
float alpha = map(a, 0, tail.length-1, 0, 255); | |
stroke(c, alpha); | |
fill(c, alpha); | |
ellipse(loc.x, loc.y, 5, 5); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
resources: | |
http://krazydad.com/tutorials/makecolors.php | |
*/ | |
color getColor(float i) { | |
int center = 205; //pastelly | |
int widthh = 205; | |
double frequency = .3; | |
int red = (int)Math.ceil(Math.sin(frequency*i+0) * widthh + center); | |
int green = (int)Math.ceil(Math.sin(frequency*i+2) * widthh + center); | |
int blue = (int)Math.ceil(Math.sin(frequency*i+4) * widthh + center); | |
return color(red,green,blue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment