Using PImage to apply color to segments of a torus

Hey, I'm struggling with figuring out how to do this. I think if I am able to find out the current x,y position of the lines being drawn to the screen and pull the color from the same position of the background image, this should work? My problem is how i go about turning this thought into code! It would be super appreciated if someone was able to give me a hand or point me in the right direction!

Thanks :)

Processing 2.2.1 Windows 8

PImage img;
float r = 100;
float w = 300;
float h = 1;

void setup(){
  img = loadImage("a.png");
  size(558,741); //matches png size
  smooth();
}

void draw(){

  background(230);
    translate(width/2, height/2);
      int torus = 100;
      float arclength = 0;

      for (int i = 0; i < torus; i++) {

        arclength += w/2;

        float theta = arclength/r;

        pushMatrix();

        translate(r*cos(theta) , r*sin(theta));
        rotate(theta);

        loadPixels();

        // loc = current x,y pos of torus segments (rect)???

       // float c = img.pixels[loc];
       // fill(c);

        noStroke();
        fill(0);
        rectMode(CENTER);
        rect(0,0,w,h);
        popMatrix();

        arclength += w/2;

   }

       if(mousePressed){
        saveFrame("imagetest2.png");
  }
}
Tagged:
Sign In or Register to comment.