Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkwok91/17609559910e4b551ac3 to your computer and use it in GitHub Desktop.
Save jkwok91/17609559910e4b551ac3 to your computer and use it in GitHub Desktop.
spiraly dots
/*
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);
}
}
/*
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