Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.video.Movie;
- Movie melies;
- int detail = 6;
- PVector[] verts = new PVector[detail];
- color[] tints = new color[detail];
- PVector center = new PVector();
- float scale;
- float minCutout = 0.1;
- float maxCutout = 0.75;
- float rotSpeed = 0.01;
- void setup() {
- size(512, 256, P3D);
- melies = new Movie(this, "melies.ogv");
- melies.loop();
- noStroke();
- colorMode(HSB, 1.0, 1.0, 1.0, 1.0);
- // Set texture mode to range 0 to 1.
- textureMode(NORMAL);
- // Smooth away anti-aliasing.
- smooth(8);
- center.set(width * 0.5, height * 0.5, 0.0);
- scale = min(width, height) * 0.5;
- float detailToPercent = 1.0 / float(detail);
- for (int i = 0; i < detail; ++i) {
- // Convert from progress through the for-loop
- // to a percentage 0 .. 1.
- float iPrc = i * detailToPercent;
- // Convert from a percentage to an angle
- // around a circumference in the range
- // 0 .. TWO_PI.
- float theta = TWO_PI * iPrc;
- // Convert from polar to Cartesian coordinates.
- float cost = cos(theta);
- float sint = sin(theta);
- // Store Cartesian coordinates in vertices array.
- verts[i] = new PVector(cost, sint);
- // Store tint colors.
- tints[i] = color(iPrc, 1.0, 1.0, 1.0);
- }
- }
- void draw() {
- if (melies.available()) {
- melies.read();
- }
- // The angle by which to rotate the polygon.
- float angle = rotSpeed * frameCount;
- // Cutout size oscillates between min and max.
- float oscillation = 0.5 + cos(angle) * 0.5;
- float cutout = lerp(minCutout, maxCutout, oscillation);
- float innerScaleV = scale * cutout;
- float innerScaleVt = 0.5 * cutout;
- // Will store copies of the original shape.
- PVector v = new PVector();
- PVector vt = new PVector();
- // Draw an opaque white background.
- background(0xffffffff);
- beginShape(QUADS);
- texture(melies);
- for (int i = 0; i < detail; ++i) {
- int j = (i + 1) % detail;
- // Outer left
- v.set(verts[i]).rotate(angle).mult(scale).add(center);
- vt.set(verts[i]).mult(0.5).add(0.5, 0.5);
- tint(tints[i]);
- vertex(v.x, v.y, v.z, vt.x, vt.y);
- // Outer right
- v.set(verts[j]).rotate(angle).mult(scale).add(center);
- vt.set(verts[j]).mult(0.5).add(0.5, 0.5);
- tint(tints[j]);
- vertex(v.x, v.y, v.z, vt.x, vt.y);
- // Inner right
- v.set(verts[j]).rotate(angle).mult(innerScaleV).add(center);
- vt.set(verts[j]).mult(innerScaleVt).add(0.5, 0.5);
- tint(tints[j]);
- vertex(v.x, v.y, v.z, vt.x, vt.y);
- // Inner left
- v.set(verts[i]).rotate(angle).mult(innerScaleV).add(center);
- vt.set(verts[i]).mult(innerScaleVt).add(0.5, 0.5);
- tint(tints[i]);
- vertex(v.x, v.y, v.z, vt.x, vt.y);
- }
- endShape(CLOSE);
- }
Add Comment
Please, Sign In to add comment