Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. import processing.video.Movie;
  2.  
  3. Movie melies;
  4. int detail = 6;
  5. PVector[] verts = new PVector[detail];
  6. color[] tints = new color[detail];
  7. PVector center = new PVector();
  8. float scale;
  9. float minCutout = 0.1;
  10. float maxCutout = 0.75;
  11. float rotSpeed = 0.01;
  12.  
  13. void setup() {
  14. size(512, 256, P3D);
  15. melies = new Movie(this, "melies.ogv");
  16. melies.loop();
  17. noStroke();
  18. colorMode(HSB, 1.0, 1.0, 1.0, 1.0);
  19.  
  20. // Set texture mode to range 0 to 1.
  21. textureMode(NORMAL);
  22.  
  23. // Smooth away anti-aliasing.
  24. smooth(8);
  25.  
  26. center.set(width * 0.5, height * 0.5, 0.0);
  27. scale = min(width, height) * 0.5;
  28. float detailToPercent = 1.0 / float(detail);
  29. for (int i = 0; i < detail; ++i) {
  30.  
  31. // Convert from progress through the for-loop
  32. // to a percentage 0 .. 1.
  33. float iPrc = i * detailToPercent;
  34.  
  35. // Convert from a percentage to an angle
  36. // around a circumference in the range
  37. // 0 .. TWO_PI.
  38. float theta = TWO_PI * iPrc;
  39.  
  40. // Convert from polar to Cartesian coordinates.
  41. float cost = cos(theta);
  42. float sint = sin(theta);
  43.  
  44. // Store Cartesian coordinates in vertices array.
  45. verts[i] = new PVector(cost, sint);
  46.  
  47. // Store tint colors.
  48. tints[i] = color(iPrc, 1.0, 1.0, 1.0);
  49. }
  50. }
  51.  
  52. void draw() {
  53. if (melies.available()) {
  54. melies.read();
  55. }
  56.  
  57. // The angle by which to rotate the polygon.
  58. float angle = rotSpeed * frameCount;
  59.  
  60. // Cutout size oscillates between min and max.
  61. float oscillation = 0.5 + cos(angle) * 0.5;
  62. float cutout = lerp(minCutout, maxCutout, oscillation);
  63. float innerScaleV = scale * cutout;
  64. float innerScaleVt = 0.5 * cutout;
  65.  
  66. // Will store copies of the original shape.
  67. PVector v = new PVector();
  68. PVector vt = new PVector();
  69.  
  70. // Draw an opaque white background.
  71. background(0xffffffff);
  72. beginShape(QUADS);
  73. texture(melies);
  74.  
  75. for (int i = 0; i < detail; ++i) {
  76. int j = (i + 1) % detail;
  77.  
  78. // Outer left
  79. v.set(verts[i]).rotate(angle).mult(scale).add(center);
  80. vt.set(verts[i]).mult(0.5).add(0.5, 0.5);
  81. tint(tints[i]);
  82. vertex(v.x, v.y, v.z, vt.x, vt.y);
  83.  
  84. // Outer right
  85. v.set(verts[j]).rotate(angle).mult(scale).add(center);
  86. vt.set(verts[j]).mult(0.5).add(0.5, 0.5);
  87. tint(tints[j]);
  88. vertex(v.x, v.y, v.z, vt.x, vt.y);
  89.  
  90. // Inner right
  91. v.set(verts[j]).rotate(angle).mult(innerScaleV).add(center);
  92. vt.set(verts[j]).mult(innerScaleVt).add(0.5, 0.5);
  93. tint(tints[j]);
  94. vertex(v.x, v.y, v.z, vt.x, vt.y);
  95.  
  96. // Inner left
  97. v.set(verts[i]).rotate(angle).mult(innerScaleV).add(center);
  98. vt.set(verts[i]).mult(innerScaleVt).add(0.5, 0.5);
  99. tint(tints[i]);
  100. vertex(v.x, v.y, v.z, vt.x, vt.y);
  101. }
  102. endShape(CLOSE);
  103. }
Add Comment
Please, Sign In to add comment