Advertisement
xeromino

sine3

Feb 11th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. int elements = 100;
  2. int[] colors = new int[elements];
  3. color[] palette = {
  4.   #490A3D, #BD1550, #E97F02, #F8CA00, #8A9B0F
  5. }
  6. ;
  7. float sz, theta, offset, x, y, l;
  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 = map(sin(theta+offset), -1, 1, 0, 1);
  27.     if (y>0.5) {
  28.       l = 100;
  29.     } else {
  30.       l = 10;
  31.     }
  32.     stroke(palette[colors[i]]);
  33.     strokeWeight(sz);
  34.     line(x, height/2 - l/2, x, height/2 +l/2);
  35.   }
  36.   theta += 0.0523*2;
  37.  
  38.   //if (frameCount%2==0 && frameCount<61) saveFrame("image-###.gif");
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement