Hi,
1) How can I make a PImage object from a Polygon, i.e.,
- Poly p;
- void setup() {
- int[] x = { 20, 40, 40, 60, 60, 20 };
- int[] y = { 20, 20, 40, 40, 60, 60 };
- p = new Poly(x, y, 6);
- }
- void draw(){
- background(255);
- if (p.contains(mouseX, mouseY)) {
- fill(255, 0, 0);
- } else {
- fill(255);
- }
- p.drawMe();
- }
- /*
- The class inherit all the fields, constructors and functions
- of the java.awt.Polygon class, including contains(), xpoint,ypoint,npoint
- */
- class Poly extends java.awt.Polygon {
- public Poly(int[] x,int[] y, int n) {
- //call the java.awt.Polygon constructor
- super(x, y, n);
- }
- void drawMe() {
- beginShape();
- for (int i = 0; i < npoints; i++) {
- vertex(xpoints[i], ypoints[i]);
- }
- endShape(CLOSE);
- }
- }
How can I save the entire polygon in draw function above in a PImage so that I can manipulate with it?
2) I am moving this polygon throughout the screen and its in say white color and my entire screen in black. Can I code such that the white pixels in the above is eaten away by the program to make is black in color?
Any help or links regarding the above is appreciated.
Many thanks in advance,
Debu
1