Using Sutherland Hodgman Clipping Algorithm
in
Contributed Library Questions
•
4 months ago
Hie!
I have this following code - a modified version of Toxiclibs Example:
- import toxi.color.*;
- import toxi.geom.*;
- import toxi.processing.*;
- // number of vertices in each polygon
- int num=8;
- List<ColoredPolygon> polygons = new ArrayList<ColoredPolygon>();
- ToxiclibsSupport gfx;
- void setup() {
- size(680, 382);
- noStroke();
- smooth();
- gfx=new ToxiclibsSupport(this);
- }
- void draw() {
- background(255);
- // iterate over all polygon created so far
- for (ColoredPolygon p : polygons) {
- // apply vertex smoothing
- //p.smooth(0.01,0.05);
- // and draw
- stroke(p.col.toARGB());
- gfx.polygon2D(p);
- }
- }
- // create a new polygon around the mouse position using a random radius for each vertex
- void mousePressed() {
- // pick a random bright color and set its alpha to 50-80%
- TColor col=ColorRange.BRIGHT.getColor().setAlpha(random(0.5, 0.8));
- // add randomized vertices
- ColoredPolygon poly=new ColoredPolygon(col);
- float radius=random(50,100);
- for (int i=0; i<num; i++) {
- poly.add(Vec2D.fromTheta((float)i/num*TWO_PI).scaleSelf(random(0.2, 1)*radius).addSelf(mouseX, mouseY));
- }
- // add poly to list of polygons
- polygons.add(poly);
- }
- // extend the standard Polygon2D class to include color information
- class ColoredPolygon extends Polygon2D {
- ReadonlyTColor col;
- public ColoredPolygon(ReadonlyTColor col) {
- this.col=col;
- }
- }
Could someone please help me with the above mentioned code?
1