mirror of
https://github.com/processing/processing4.git
synced 2026-02-13 18:35:37 +01:00
implement arc drawing modes (issue #711)
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user