maandag 18 april 2011

Modifying / Editing polygons in stead of creating new polygons.

I was recreating polygons in my programs and read that that might slow down the performance so I looked up how to modify / edit polygons.

See example of how this can be done below.

 

import java.awt.*;
import java.applet.*;

public class changepolygonpoints extends Applet {

 public void init() {
 }

 public void paint(Graphics g) {

  g.drawString("Modifying polygons", 50, 60 );

     Polygon p = new Polygon(new int[]{100,100,150},new int[]{100,200,150},3);

       g.drawPolygon(p);

  //loop through the x array of the polygon
       for(int x=0;x < p.npoints ; x++)
        {
         p.xpoints[x] = p.xpoints[x]+100;
       }
       g.drawPolygon(p);

 }
}

Geen opmerkingen:

Een reactie posten