Advertisement
xeromino

box

Jul 14th, 2016
417
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var angle = 0,
  2.   c = 100;
  3. var img, frms = 400;
  4. var num = 20,
  5.   step = 20,
  6.   offSet = 0,
  7.   rows = 0,
  8.   cols = 0,
  9.   cellSize = 35;
  10. var sz = 0,
  11.   theta = 0;
  12.  
  13. function setup() {
  14.   createCanvas(750, 540, WEBGL);
  15.   img = createGraphics(350, 350);
  16.   rows = img.width / cellSize;
  17.   cols = img.height/ cellSize;
  18. }
  19.  
  20. function draw() {
  21.   background(38);
  22.  
  23.   rotateX(PI + angle);
  24.   rotateZ(angle);
  25.   rotateY(PI - angle);
  26.  
  27.   drawArcs();
  28.   texture(img);
  29.   box(img.width, img.height);
  30.  
  31.   angle += TWO_PI / frms;
  32.  
  33. }
  34.  
  35. function drawArcs() {
  36.   img.background(238);
  37.   for (var i = 0; i <= rows; i++) {
  38.     for (var j = 0; j < cols; j++) {
  39.       var offSet = PI + PI / rows * i + PI / cols * j;
  40.       var x = (i + .5) * cellSize;
  41.       var y = (j + .5) * cellSize;
  42.       var dx = 0; //mouseX - x;
  43.       var dy = 0; //mouseY - y;
  44.       img.noStroke();
  45.       img.fill(38);
  46.       var r = atan2(dy, dx);
  47.       var arcSize = map(sin(theta / 4 + offSet), -1, 1, radians(30), PI);
  48.       sz = cellSize * .90;
  49.       img.push();
  50.       img.translate(x, y);
  51.       img.rotate(r + theta);
  52.       img.arc(0, 0, sz, sz, 0, arcSize);
  53.       img.pop();
  54.     }
  55.   }
  56.   theta += TWO_PI / frms * 4;
  57. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement