Reputation: 229
I was working on an animation on processing. Then, I have a question about the code. Normally, my code is more long. However, I made a simple code which can usefull also for the beginners. My sample code:
void setup() {
size(250, 250);
}
void draw() {
background(102);
translate(100, 100);
beginShape();
vertex(0,0);
vertex(-50, 50);
vertex(0, 100);
endShape();
}
I have to use three vertexes and I want to texture the Shape as in texture()
. How to make that?
Upvotes: 0
Views: 535
Reputation: 176
In order to put an image as a texture on a Shape:
texture()
function when you begin to set up the Shape.(0, 0)
, (0, img.height)
and (img.width, img.height)
.PImage img;
void setup() {
size(250, 250, P2D);
img = loadImage("rectangular_image.jpg");
textureMode(IMAGE);
textureWrap(CLAMP);
}
void draw() {
background(102);
translate(100, 100);
noStroke();
beginShape();
texture(img);
vertex(0, 0, 0, 0);
vertex(-50, 50, 0, img.height);
vertex(0, 100, img.width, img.height);
endShape();
}
Upvotes: 1