From e8cf271de63d46391ee7bced41af9379f676dfef Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 22 Nov 2012 12:57:05 +0000 Subject: [PATCH] implement arc drawing modes (issue #711) --- core/src/processing/core/PConstants.java | 15 +++---- core/src/processing/core/PGraphics.java | 45 ++++++++++++------- core/src/processing/core/PGraphicsJava2D.java | 25 +++++++++-- core/src/processing/core/PImage.java | 6 +++ core/todo.txt | 34 ++++++++------ 5 files changed, 83 insertions(+), 42 deletions(-) diff --git a/core/src/processing/core/PConstants.java b/core/src/processing/core/PConstants.java index 1d41ee6a4..7d9e0f497 100644 --- a/core/src/processing/core/PConstants.java +++ b/core/src/processing/core/PConstants.java @@ -225,14 +225,6 @@ public interface PConstants { public final static int DODGE = 1 << 12; public final static int BURN = 1 << 13; - // colour component bitmasks - - public static final int ALPHA_MASK = 0xff000000; - public static final int RED_MASK = 0x00ff0000; - public static final int GREEN_MASK = 0x0000ff00; - public static final int BLUE_MASK = 0x000000ff; - - // for messages static final int CHATTER = 0; @@ -317,6 +309,13 @@ public interface PConstants { static final int DIAMETER = 3; + // arc drawing modes + + //static final int OPEN = 1; // shared + static final int CHORD = 2; + static final int PIE = 3; + + // vertically alignment modes for text /** Default vertical alignment for text placement */ diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 641dddede..383c4de3c 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -2569,6 +2569,12 @@ public class PGraphics extends PImage implements PConstants { */ public void arc(float a, float b, float c, float d, float start, float stop) { + arc(a, b, c, d, start, stop, 0); + } + + + public void arc(float a, float b, float c, float d, + float start, float stop, int mode) { float x = a; float y = b; float w = c; @@ -2589,26 +2595,31 @@ public class PGraphics extends PImage implements PConstants { y = b - d/2f; } - // make sure this loop will exit before starting while - if (Float.isInfinite(start) || Float.isInfinite(stop)) return; -// while (stop < start) stop += TWO_PI; - if (stop < start) return; // why bother + // make sure the loop will exit before starting while + if (!Float.isInfinite(start) && !Float.isInfinite(stop)) { + // ignore equal and degenerate cases + if (stop > start) { + // make sure that we're starting at a useful point + while (start < 0) { + start += TWO_PI; + stop += TWO_PI; + } - // make sure that we're starting at a useful point - while (start < 0) { - start += TWO_PI; - stop += TWO_PI; + if (stop - start > TWO_PI) { + start = 0; + stop = TWO_PI; + } + arcImpl(x, y, w, h, start, stop, mode); + } } - - if (stop - start > TWO_PI) { - start = 0; - stop = TWO_PI; - } - - arcImpl(x, y, w, h, start, stop); } +// protected void arcImpl(float x, float y, float w, float h, +// float start, float stop) { +// } + + /** * Start and stop are in radians, converted by the parent function. * Note that the radians can be greater (or less) than TWO_PI. @@ -2616,11 +2627,11 @@ public class PGraphics extends PImage implements PConstants { * and the user will still collect $200. */ protected void arcImpl(float x, float y, float w, float h, - float start, float stop) { + float start, float stop, int mode) { + showMissingWarning("arc"); } - ////////////////////////////////////////////////////////////// // BOX diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index 31dbb986c..d613f862f 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -782,7 +782,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { @Override protected void arcImpl(float x, float y, float w, float h, - float start, float stop) { + float start, float stop, int mode) { // 0 to 90 in java would be 0 to -90 for p5 renderer // but that won't work, so -90 to 0? @@ -801,15 +801,32 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { // } float sweep = stop - start; - // stroke as Arc2D.OPEN, fill as Arc2D.PIE + // The defaults, before 2.0b7, were to stroke as Arc2D.OPEN, and then fill + // using Arc2D.PIE. That's a little wonky, but it's here for compatability. + int fillMode = Arc2D.PIE; + int strokeMode = Arc2D.OPEN; + + if (mode == OPEN) { + fillMode = Arc2D.OPEN; + //strokeMode = Arc2D.OPEN; + + } else if (mode == PIE) { + //fillMode = Arc2D.PIE; + strokeMode = Arc2D.PIE; + + } else if (mode == CHORD) { + fillMode = Arc2D.CHORD; + strokeMode = Arc2D.CHORD; + } + if (fill) { //System.out.println("filla"); - arc.setArc(x, y, w, h, start, sweep, Arc2D.PIE); + arc.setArc(x, y, w, h, start, sweep, fillMode); fillShape(arc); } if (stroke) { //System.out.println("strokey"); - arc.setArc(x, y, w, h, start, sweep, Arc2D.OPEN); + arc.setArc(x, y, w, h, start, sweep, strokeMode); strokeShape(arc); } } diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index b2996011f..cf109e4e0 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -160,6 +160,12 @@ public class PImage implements PConstants, Cloneable { private int[] blurKernel; private int[][] blurMult; + // colour component bitmasks (moved from PConstants in 2.0b7) + public static final int ALPHA_MASK = 0xff000000; + public static final int RED_MASK = 0x00ff0000; + public static final int GREEN_MASK = 0x0000ff00; + public static final int BLUE_MASK = 0x000000ff; + ////////////////////////////////////////////////////////////// diff --git a/core/todo.txt b/core/todo.txt index fd9acbe07..d4d2ced3f 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -11,6 +11,19 @@ X remove blend(), add blendMode() X http://code.google.com/p/processing/issues/detail?id=1385 o implement a more efficient version of blend() o http://code.google.com/p/processing/issues/detail?id=120 +o Problem with beginShape()/endShape() when using multiple contours +X http://code.google.com/p/processing/issues/detail?id=1396 +X just a documentation issue +A PShape and lights results in more lit vertices +A http://code.google.com/p/processing/issues/detail?id=1342 +A Implement anisotropic filtering when using OPENGL +A http://code.google.com/p/processing/issues/detail?id=502 +X move _MASK constants out of PConstants and into PImage + +_ how should stroke work w/ arcs? +X decision: we should do pie, you can make the other kind w/o it +_ add an additional parameter for the others +_ http://code.google.com/p/processing/issues/detail?id=711 cleanup/earlier by Andres @@ -39,11 +52,14 @@ A set() requires updatePixels() with OpenGL A http://code.google.com/p/processing/issues/detail?id=89 A chopping out triangles in OpenGL (though it's only 2D drawing) A http://code.google.com/p/processing/issues/detail?id=193 +A shared interface for 3D view data across desktop/Android +A http://code.google.com/p/processing/issues/detail?id=970 +A Distortion of 2D shapes when sphereDetail() is used +A http://code.google.com/p/processing/issues/detail?id=762 +A OPENGL renderer stops rendering after text is written using textMode(SCREEN) +A http://code.google.com/p/processing/issues/detail?id=710 -_ Problem with beginShape()/endShape() when using multiple contours -_ http://code.google.com/p/processing/issues/detail?id=1396 - _ createShape() not yet implemented for 2.0 _ http://code.google.com/p/processing/issues/detail?id=1400 @@ -350,12 +366,6 @@ _ toColorArray(), toColorArray(float[])... _ load/save methods.. is it save("blah.svg") or saveSVG("blah.svg") X also works that way with tables X decision: useExtension() or something like that -_ how should stroke work w/ arcs? -_ has an effect elliptical arc -_ http://code.google.com/p/processing/issues/detail?id=130 -X decision: we should do pie, you can make the other kind w/o it -_ add an additional parameter for the others -_ http://code.google.com/p/processing/issues/detail?id=711 _ require people to put things in the data folder _ make sure that loadXxxx() methods are used after init() _ nasty errors when loadImage/Font/createFont/etc used outside @@ -584,6 +594,8 @@ _ for PShape, need to be able to set the origin (flash people) CORE / PShapeSVG +_ implement A and a (elliptical arcs) +_ http://code.google.com/p/processing/issues/detail?id=130 _ implement support for SVG gradients from Inkscape _ http://code.google.com/p/processing/issues/detail?id=1142 _ need to handle