Advertisement
xeromino

sineCurve

Feb 11th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. int elements = 50;
  2. int[] colors = new int[elements];
  3. color[] palette = {
  4.   #490A3D, #BD1550, #E97F02, #F8CA00, #8A9B0F
  5. }
  6. ;
  7. float sz, theta, offset, x, y;
  8.  
  9. void setup() {
  10.   size(500, 300);
  11.   sz=width/elements;
  12.  
  13.   for (int i=0; i<elements; i++) {
  14.     colors[i] = (int) random(0, 5);
  15.   }
  16. }
  17.  
  18. void draw() {
  19.   background(20);
  20.   stroke(220);
  21.   line(0, height/2, width, height/2);
  22.  
  23.   for (int i=0; i<colors.length; i++) {
  24.     offset = (TWO_PI/elements)*i*3;
  25.     x = sz/2 + i*sz;
  26.     y = height/2+ map(sin(theta+offset), -1, 1, -50, 50);
  27.     fill(palette[colors[i]]);
  28.     noStroke();
  29.     ellipse(x, y, sz, sz);
  30.   }
  31.   theta += 0.0523*2;
  32.  
  33.   if (frameCount%2==0 && frameCount<61) saveFrame("image-###.gif");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement