Image() function with 4 points

Hello,

Reference:
https://processing.org/reference/texture_.html

Example:

PImage img;

float x1, y1, x2, y2, x3, y3, x4, y4;

void setup() 
  {
  size(200, 200, P3D);
  img = loadImage("https://cdn.theatlantic.com/thumbor/jb3UdKqcmt1JleWOqNj8UWRxcFk=/0x591:2832x2184/976x549/media/img/mt/2017/10/Pict1_Ursinia_calendulifolia/original.jpg");
  noStroke();
  }

void draw() 
  {
  background(0);
  
  int r = 10;
  float th = (frameCount%360)*(TAU/360);
  
  x1 = 50+r*cos(th);
  y1 = 50+r*sin(th);

  x2 = 150-r*cos(th);
  y2 = 50-r*sin(th);
  
  x3 = 150+r*cos(th);
  y3 = 150+r*sin(th);

  x4 = 50-r*cos(th);
  y4 = 150-r*sin(th);
  
  beginShape(QUAD);
  texture(img);
  vertex(x1, y1, 0, 0);
  vertex(x2, y2, img.width, 0);
  vertex(x3, y3, img.width, img.height);
  vertex(x4, y4, 0, img.height);
  endShape();
  }

flowers

:)

3 Likes