Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Applying the same texture to multiple shapes

$
0
0
Is this possible? I figured it would save memory but it doesn't seem to work. I can easily just make multiple texture variables but then I'd have to load the same movie 3 times... anyway I'm sure this is possible, here's what I have so far-

  1. import processing.video.*;

  2. Movie waves;

  3. float radius, step;
  4. int points, numShapes;

  5. void setup() {
  6.   size(1280, 720, P2D);
  7.   background(0);

  8.   waves = new Movie(this, "kaleida.mov");
  9.   waves.loop();

  10.   radius = 200;
  11.   points = 3;
  12.   shapes = 3;
  13.   step = TAU / points;
  14. }

  15. void draw() {
  16.   background(0);
  17.  
  18.   for(int h = 0; h < numShapes; h++){
  19.     pushMatrix();
  20.     stroke(255);
  21.     strokeWeight(2);
  22.     translate(width/2, height/2);
  23.     textureMode(NORMAL);
  24.     beginShape();
  25.     texture(waves);
  26.     rotate(h*45);
  27.     for (int i = 0; i < points+1; i++) {
  28.       float theta = step * i;
  29.       float x = (cos(theta) * radius) + radius;
  30.       float y = (sin(theta) * radius) + radius;
  31.       float tx = x/waves.width+0.5;
  32.       float ty = y/waves.height+0.5;

  33.       vertex(x, y, tx, ty);
  34.     }
  35.     endShape();
  36.     popMatrix();
  37.   }

  38.   frame.setTitle(int(frameRate) + " fps");

  39. }

  40. void movieEvent(Movie m) {
  41.   m.read();
  42. }


Viewing all articles
Browse latest Browse all 1768

Trending Articles