Guest User

Untitled

a guest
Jul 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. 'use strict';
  2.  
  3. let melies = null;
  4. const detail = 6;
  5. const verts = [];
  6. let center = null;
  7. let scale = null;
  8. let minCutout = 0.1;
  9. let maxCutout = 0.75;
  10. let rotSpeed = 0.01;
  11.  
  12. function preload() {
  13. melies = createVideo('assets/melies.ogv', onVideoLoad);
  14. }
  15.  
  16. function onVideoLoad() {
  17. melies.loop();
  18. melies.hide();
  19. }
  20.  
  21. function setup() {
  22. createCanvas(512, 256, WEBGL);
  23. noStroke();
  24.  
  25. center = createVector();
  26. scale = min(width, height) * 0.5;
  27. const detailToPercent = 1.0 / detail;
  28. for (let i = 0; i < detail; ++i) {
  29.  
  30. // Convert from progress through the for-loop
  31. // to a percentage 0 .. 1.
  32. const iPrc = i * detailToPercent;
  33.  
  34. // Convert from a percentage to an angle
  35. // around a circumference in the range
  36. // 0 .. TWO_PI.
  37. const theta = TWO_PI * iPrc;
  38.  
  39. // Convert from polar to Cartesian coordinates.
  40. const cost = cos(theta);
  41. const sint = sin(theta);
  42.  
  43. // Store Cartesian coordinates in vertices array.
  44. verts.push(createVector(cost, sint));
  45. }
  46. }
  47.  
  48. function draw() {
  49.  
  50. // The angle by which to rotate the polygon.
  51. const angle = rotSpeed * frameCount;
  52.  
  53. // Cutout size oscillates between min and max.
  54. const oscillation = 0.5 + cos(angle) * 0.5;
  55. const cutout = lerp(minCutout, maxCutout, oscillation);
  56. const innerScaleV = scale * cutout;
  57. const innerScaleVt = 0.5 * cutout;
  58.  
  59. // Will store copies of the original shape.
  60. const v = createVector();
  61. const vt = createVector();
  62.  
  63. // Draw an opaque white background.
  64. background(255.0);
  65.  
  66. for (let i = 0; i < detail; ++i) {
  67. const j = (i + 1) % detail;
  68. beginShape();
  69. texture(melies);
  70.  
  71. // Outer left
  72. v.set(verts[i]).rotate(angle).mult(scale).add(center);
  73. vt.set(verts[i]).mult(0.5).add(0.5, 0.5);
  74. vertex(v.x, v.y, v.z, vt.x, vt.y);
  75.  
  76. // Outer right
  77. v.set(verts[j]).rotate(angle).mult(scale).add(center);
  78. vt.set(verts[j]).mult(0.5).add(0.5, 0.5);
  79. vertex(v.x, v.y, v.z, vt.x, vt.y);
  80.  
  81. // Inner right
  82. v.set(verts[j]).rotate(angle).mult(innerScaleV).add(center);
  83. vt.set(verts[j]).mult(innerScaleVt).add(0.5, 0.5);
  84. vertex(v.x, v.y, v.z, vt.x, vt.y);
  85.  
  86. // Inner left
  87. v.set(verts[i]).rotate(angle).mult(innerScaleV).add(center);
  88. vt.set(verts[i]).mult(innerScaleVt).add(0.5, 0.5);
  89. vertex(v.x, v.y, v.z, vt.x, vt.y);
  90. endShape(CLOSE);
  91. }
  92. }
Add Comment
Please, Sign In to add comment