Advertisement
xeromino

sun

Mar 11th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. float radius, theta, lx, ly, sz = 5;
  2. int num = 120, step = 4, fc;
  3. float[] scal = new float[num];
  4. PVector[] dots = new PVector[num];
  5. boolean save = false;
  6.  
  7. void setup() {
  8.   size(500, 500);
  9.   background(20);
  10.   fill(#FFA41A);
  11.   //noFill();
  12.   stroke(#FFA41A);
  13.   strokeWeight(1);
  14.   strokeJoin(ROUND);
  15.   radius = width*.25;
  16.  
  17.   createSpikeyThing();
  18. }
  19.  
  20. void draw() {
  21.   background(20);
  22.  
  23.   drawSpikeyThing();
  24.   theta += 0.0523;
  25.  
  26.   if (save) {
  27.   if (frameCount%4==0 && frameCount<fc+121) saveFrame("image-###.gif");
  28.   }
  29. }
  30.  
  31. void createSpikeyThing() {
  32.  
  33.   float angle = 3*PI/2;
  34.  
  35.   for (int i=0; i<num; i++) {
  36.     if (i%(step)==0) {
  37.       scal[i] = random(1.1, 1.4);
  38.     }
  39.     else {
  40.       scal[i] = 1;
  41.     }
  42.     float px = width/2 + sin(angle)*radius*scal[i];
  43.     float py = height/2 + cos(angle)*radius*scal[i];
  44.     dots[i]= new PVector(px, py);
  45.     angle+=TWO_PI/num;
  46.   }
  47. }
  48.  
  49. void drawSpikeyThing() {
  50.  
  51.   float c = 0;
  52.   for (int i=0; i<num; i++) {
  53.     if (i%(step)==0) {
  54.       float s = map(sin(theta+(TWO_PI/step)*c), -1, 1, 1, 1.4);
  55.       dots[i].x = width/2 + sin(3*PI/2 + i*(TWO_PI/num))*radius*scal[i]*s;
  56.       dots[i].y = height/2 + cos(3*PI/2 + i*(TWO_PI/num))*radius*scal[i]*s;
  57.       c++;
  58.     }
  59.   }
  60.  
  61.   beginShape();
  62.   for (int i=0; i<num; i++) {
  63.     if (i==0) vertex(dots[i].x, dots[i].y);
  64.     vertex(dots[i].x, dots[i].y);
  65.     if (i==num-1) vertex(dots[i].x, dots[i].y);
  66.   }
  67.   endShape(CLOSE);
  68. }
  69.  
  70. void mouseReleased() {
  71.   createSpikeyThing();
  72. }
  73.  
  74. void keyPressed() {
  75.   fc = frameCount;
  76.   save = true;
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement