propane 2.7.2-java → 2.8.0.pre-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/CHANGELOG.md +1 -1
- data/README.md +10 -8
- data/Rakefile +1 -1
- data/lib/propane/app.rb +3 -3
- data/lib/propane/version.rb +1 -1
- data/lib/{processing-core.jar → propane-2.8.0.jar} +0 -0
- data/library/control_panel/control_panel.rb +3 -2
- data/pom.rb +89 -88
- data/pom.xml +75 -46
- data/propane.gemspec +1 -2
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/{monkstone → main/java/monkstone}/ColorUtil.java +0 -0
- data/src/{monkstone → main/java/monkstone}/MathToolModule.java +0 -0
- data/src/{monkstone → main/java/monkstone}/PropaneLibrary.java +0 -0
- data/src/{monkstone → main/java/monkstone}/core/LibraryProxy.java +0 -0
- data/src/{monkstone → main/java/monkstone}/fastmath/Deglut.java +0 -0
- data/src/{monkstone → main/java/monkstone}/fastmath/package-info.java +0 -0
- data/src/{monkstone → main/java/monkstone}/filechooser/Chooser.java +0 -0
- data/src/{monkstone → main/java/monkstone}/noise/SimplexNoise.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/CustomHorizontalSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/CustomVerticalSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SimpleHorizontalSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SimpleSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SimpleVerticalSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/Slider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SliderBar.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SliderGroup.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/WheelHandler.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/AppRender.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/JRender.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/ShapeRender.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/package-info.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/vec2/Vec2.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/vec2/package-info.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/vec3/Vec3.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/vec3/package-info.java +0 -0
- data/src/{monkstone → main/java/monkstone}/videoevent/VideoInterface.java +0 -0
- data/src/{monkstone → main/java/monkstone}/videoevent/package-info.java +0 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3029 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +377 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1567 -0
- data/src/main/java/processing/core/PApplet.java +15709 -0
- data/src/main/java/processing/core/PConstants.java +527 -0
- data/src/main/java/processing/core/PFont.java +1098 -0
- data/src/main/java/processing/core/PGraphics.java +8467 -0
- data/src/main/java/processing/core/PImage.java +3438 -0
- data/src/main/java/processing/core/PMatrix.java +208 -0
- data/src/main/java/processing/core/PMatrix2D.java +534 -0
- data/src/main/java/processing/core/PMatrix3D.java +877 -0
- data/src/main/java/processing/core/PShape.java +3445 -0
- data/src/main/java/processing/core/PShapeOBJ.java +469 -0
- data/src/main/java/processing/core/PShapeSVG.java +1787 -0
- data/src/main/java/processing/core/PStyle.java +63 -0
- data/src/main/java/processing/core/PSurface.java +161 -0
- data/src/main/java/processing/core/PSurfaceNone.java +374 -0
- data/src/main/java/processing/core/PVector.java +1063 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +125 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/src/main/resources/license.txt +508 -0
- data/vendors/Rakefile +5 -20
- metadata +115 -33
- data/lib/propane.jar +0 -0
@@ -0,0 +1,3445 @@
|
|
1
|
+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
+
|
3
|
+
/*
|
4
|
+
Part of the Processing project - http://processing.org
|
5
|
+
|
6
|
+
Copyright (c) 2006-10 Ben Fry and Casey Reas
|
7
|
+
|
8
|
+
This library is free software; you can redistribute it and/or
|
9
|
+
modify it under the terms of the GNU Lesser General Public
|
10
|
+
License version 2.1 as published by the Free Software Foundation.
|
11
|
+
|
12
|
+
This library is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General
|
18
|
+
Public License along with this library; if not, write to the
|
19
|
+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
20
|
+
Boston, MA 02111-1307 USA
|
21
|
+
*/
|
22
|
+
|
23
|
+
package processing.core;
|
24
|
+
|
25
|
+
import java.util.HashMap;
|
26
|
+
import java.util.Map;
|
27
|
+
|
28
|
+
import processing.core.PApplet;
|
29
|
+
|
30
|
+
|
31
|
+
/**
|
32
|
+
* ( begin auto-generated from PShape.xml )
|
33
|
+
*
|
34
|
+
* Datatype for storing shapes. Processing can currently load and display
|
35
|
+
* SVG (Scalable Vector Graphics) shapes. Before a shape is used, it must
|
36
|
+
* be loaded with the <b>loadShape()</b> function. The <b>shape()</b>
|
37
|
+
* function is used to draw the shape to the display window. The
|
38
|
+
* <b>PShape</b> object contain a group of methods, linked below, that can
|
39
|
+
* operate on the shape data.
|
40
|
+
* <br /><br />
|
41
|
+
* The <b>loadShape()</b> function supports SVG files created with Inkscape
|
42
|
+
* and Adobe Illustrator. It is not a full SVG implementation, but offers
|
43
|
+
* some straightforward support for handling vector data.
|
44
|
+
*
|
45
|
+
* ( end auto-generated )
|
46
|
+
* <h3>Advanced</h3>
|
47
|
+
*
|
48
|
+
* In-progress class to handle shape data, currently to be considered of
|
49
|
+
* alpha or beta quality. Major structural work may be performed on this class
|
50
|
+
* after the release of Processing 1.0. Such changes may include:
|
51
|
+
*
|
52
|
+
* <ul>
|
53
|
+
* <li> addition of proper accessors to read shape vertex and coloring data
|
54
|
+
* (this is the second most important part of having a PShape class after all).
|
55
|
+
* <li> a means of creating PShape objects ala beginShape() and endShape().
|
56
|
+
* <li> load(), update(), and cache methods ala PImage, so that shapes can
|
57
|
+
* have renderer-specific optimizations, such as vertex arrays in OpenGL.
|
58
|
+
* <li> splitting this class into multiple classes to handle different
|
59
|
+
* varieties of shape data (primitives vs collections of vertices vs paths)
|
60
|
+
* <li> change of package declaration, for instance moving the code into
|
61
|
+
* package processing.shape (if the code grows too much).
|
62
|
+
* </ul>
|
63
|
+
*
|
64
|
+
* <p>For the time being, this class and its shape() and loadShape() friends in
|
65
|
+
* PApplet exist as placeholders for more exciting things to come. If you'd
|
66
|
+
* like to work with this class, make a subclass (see how PShapeSVG works)
|
67
|
+
* and you can play with its internal methods all you like.</p>
|
68
|
+
*
|
69
|
+
* <p>Library developers are encouraged to create PShape objects when loading
|
70
|
+
* shape data, so that they can eventually hook into the bounty that will be
|
71
|
+
* the PShape interface, and the ease of loadShape() and shape().</p>
|
72
|
+
*
|
73
|
+
* @webref shape
|
74
|
+
* @usage Web & Application
|
75
|
+
* @see PApplet#loadShape(String)
|
76
|
+
* @see PApplet#createShape()
|
77
|
+
* @see PApplet#shapeMode(int)
|
78
|
+
* @instanceName sh any variable of type PShape
|
79
|
+
*/
|
80
|
+
public class PShape implements PConstants {
|
81
|
+
protected String name;
|
82
|
+
protected Map<String,PShape> nameTable;
|
83
|
+
|
84
|
+
// /** Generic, only draws its child objects. */
|
85
|
+
// static public final int GROUP = 0;
|
86
|
+
// GROUP now inherited from PConstants, and is still zero
|
87
|
+
|
88
|
+
// These constants were updated in 3.0b6 so that they could be distinguished
|
89
|
+
// from others in PConstants and improve how some typos were handled.
|
90
|
+
// https://github.com/processing/processing/issues/3776
|
91
|
+
/** A line, ellipse, arc, image, etc. */
|
92
|
+
static public final int PRIMITIVE = 101;
|
93
|
+
/** A series of vertex, curveVertex, and bezierVertex calls. */
|
94
|
+
static public final int PATH = 102;
|
95
|
+
/** Collections of vertices created with beginShape(). */
|
96
|
+
static public final int GEOMETRY = 103;
|
97
|
+
/** The shape type, one of GROUP, PRIMITIVE, PATH, or GEOMETRY. */
|
98
|
+
protected int family;
|
99
|
+
|
100
|
+
/** ELLIPSE, LINE, QUAD; TRIANGLE_FAN, QUAD_STRIP; etc. */
|
101
|
+
protected int kind;
|
102
|
+
|
103
|
+
protected PMatrix matrix;
|
104
|
+
|
105
|
+
protected int textureMode;
|
106
|
+
|
107
|
+
/** Texture or image data associated with this shape. */
|
108
|
+
protected PImage image;
|
109
|
+
|
110
|
+
public static final String OUTSIDE_BEGIN_END_ERROR =
|
111
|
+
"%1$s can only be called between beginShape() and endShape()";
|
112
|
+
|
113
|
+
public static final String INSIDE_BEGIN_END_ERROR =
|
114
|
+
"%1$s can only be called outside beginShape() and endShape()";
|
115
|
+
|
116
|
+
public static final String NO_SUCH_VERTEX_ERROR =
|
117
|
+
"%1$s vertex index does not exist";
|
118
|
+
|
119
|
+
static public final String NO_VERTICES_ERROR =
|
120
|
+
"getVertexCount() only works with PATH or GEOMETRY shapes";
|
121
|
+
|
122
|
+
public static final String NOT_A_SIMPLE_VERTEX =
|
123
|
+
"%1$s can not be called on quadratic or bezier vertices";
|
124
|
+
|
125
|
+
static public final String PER_VERTEX_UNSUPPORTED =
|
126
|
+
"This renderer does not support %1$s for individual vertices";
|
127
|
+
|
128
|
+
/**
|
129
|
+
* ( begin auto-generated from PShape_width.xml )
|
130
|
+
*
|
131
|
+
* The width of the PShape document.
|
132
|
+
*
|
133
|
+
* ( end auto-generated )
|
134
|
+
* @webref pshape:field
|
135
|
+
* @usage web_application
|
136
|
+
* @brief Shape document width
|
137
|
+
* @see PShape#height
|
138
|
+
*/
|
139
|
+
public float width;
|
140
|
+
/**
|
141
|
+
* ( begin auto-generated from PShape_height.xml )
|
142
|
+
*
|
143
|
+
* The height of the PShape document.
|
144
|
+
*
|
145
|
+
* ( end auto-generated )
|
146
|
+
* @webref pshape:field
|
147
|
+
* @usage web_application
|
148
|
+
* @brief Shape document height
|
149
|
+
* @see PShape#width
|
150
|
+
*/
|
151
|
+
public float height;
|
152
|
+
|
153
|
+
public float depth;
|
154
|
+
|
155
|
+
PGraphics g;
|
156
|
+
|
157
|
+
// set to false if the object is hidden in the layers palette
|
158
|
+
protected boolean visible = true;
|
159
|
+
|
160
|
+
/** Retained shape being created with beginShape/endShape */
|
161
|
+
protected boolean openShape = false;
|
162
|
+
|
163
|
+
protected boolean openContour = false;
|
164
|
+
|
165
|
+
protected boolean stroke;
|
166
|
+
protected int strokeColor;
|
167
|
+
protected float strokeWeight; // default is 1
|
168
|
+
protected int strokeCap;
|
169
|
+
protected int strokeJoin;
|
170
|
+
|
171
|
+
protected boolean fill;
|
172
|
+
protected int fillColor;
|
173
|
+
|
174
|
+
protected boolean tint;
|
175
|
+
protected int tintColor;
|
176
|
+
|
177
|
+
protected int ambientColor;
|
178
|
+
protected boolean setAmbient;
|
179
|
+
protected int specularColor;
|
180
|
+
protected int emissiveColor;
|
181
|
+
protected float shininess;
|
182
|
+
|
183
|
+
protected int sphereDetailU, sphereDetailV;
|
184
|
+
protected int rectMode;
|
185
|
+
protected int ellipseMode;
|
186
|
+
|
187
|
+
/** Temporary toggle for whether styles should be honored. */
|
188
|
+
protected boolean style = true;
|
189
|
+
|
190
|
+
/** For primitive shapes in particular, params like x/y/w/h or x1/y1/x2/y2. */
|
191
|
+
protected float[] params;
|
192
|
+
|
193
|
+
protected int vertexCount;
|
194
|
+
/**
|
195
|
+
* When drawing POLYGON shapes, the second param is an array of length
|
196
|
+
* VERTEX_FIELD_COUNT. When drawing PATH shapes, the second param has only
|
197
|
+
* two variables.
|
198
|
+
*/
|
199
|
+
protected float[][] vertices;
|
200
|
+
|
201
|
+
protected PShape parent;
|
202
|
+
protected int childCount;
|
203
|
+
protected PShape[] children;
|
204
|
+
|
205
|
+
|
206
|
+
/** Array of VERTEX, BEZIER_VERTEX, and CURVE_VERTEX calls. */
|
207
|
+
protected int vertexCodeCount;
|
208
|
+
protected int[] vertexCodes;
|
209
|
+
/** True if this is a closed path. */
|
210
|
+
protected boolean close;
|
211
|
+
|
212
|
+
// ........................................................
|
213
|
+
|
214
|
+
// internal color for setting/calculating
|
215
|
+
protected float calcR, calcG, calcB, calcA;
|
216
|
+
protected int calcRi, calcGi, calcBi, calcAi;
|
217
|
+
protected int calcColor;
|
218
|
+
protected boolean calcAlpha;
|
219
|
+
|
220
|
+
/** The current colorMode */
|
221
|
+
public int colorMode; // = RGB;
|
222
|
+
|
223
|
+
/** Max value for red (or hue) set by colorMode */
|
224
|
+
public float colorModeX; // = 255;
|
225
|
+
|
226
|
+
/** Max value for green (or saturation) set by colorMode */
|
227
|
+
public float colorModeY; // = 255;
|
228
|
+
|
229
|
+
/** Max value for blue (or value) set by colorMode */
|
230
|
+
public float colorModeZ; // = 255;
|
231
|
+
|
232
|
+
/** Max value for alpha set by colorMode */
|
233
|
+
public float colorModeA; // = 255;
|
234
|
+
|
235
|
+
/** True if colors are not in the range 0..1 */
|
236
|
+
boolean colorModeScale; // = true;
|
237
|
+
|
238
|
+
/** True if colorMode(RGB, 255) */
|
239
|
+
boolean colorModeDefault; // = true;
|
240
|
+
|
241
|
+
/** True if contains 3D data */
|
242
|
+
protected boolean is3D = false;
|
243
|
+
|
244
|
+
protected boolean perVertexStyles = false;
|
245
|
+
|
246
|
+
// should this be called vertices (consistent with PGraphics internals)
|
247
|
+
// or does that hurt flexibility?
|
248
|
+
|
249
|
+
|
250
|
+
// POINTS, LINES, xLINE_STRIP, xLINE_LOOP
|
251
|
+
// TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN
|
252
|
+
// QUADS, QUAD_STRIP
|
253
|
+
// xPOLYGON
|
254
|
+
// static final int PATH = 1; // POLYGON, LINE_LOOP, LINE_STRIP
|
255
|
+
// static final int GROUP = 2;
|
256
|
+
|
257
|
+
// how to handle rectmode/ellipsemode?
|
258
|
+
// are they bitshifted into the constant?
|
259
|
+
// CORNER, CORNERS, CENTER, (CENTER_RADIUS?)
|
260
|
+
// static final int RECT = 3; // could just be QUAD, but would be x1/y1/x2/y2
|
261
|
+
// static final int ELLIPSE = 4;
|
262
|
+
//
|
263
|
+
// static final int VERTEX = 7;
|
264
|
+
// static final int CURVE = 5;
|
265
|
+
// static final int BEZIER = 6;
|
266
|
+
|
267
|
+
|
268
|
+
// fill and stroke functions will need a pointer to the parent
|
269
|
+
// PGraphics object.. may need some kind of createShape() fxn
|
270
|
+
// or maybe the values are stored until draw() is called?
|
271
|
+
|
272
|
+
// attaching images is very tricky.. it's a different type of data
|
273
|
+
|
274
|
+
// material parameters will be thrown out,
|
275
|
+
// except those currently supported (kinds of lights)
|
276
|
+
|
277
|
+
// pivot point for transformations
|
278
|
+
// public float px;
|
279
|
+
// public float py;
|
280
|
+
|
281
|
+
|
282
|
+
/**
|
283
|
+
* @nowebref
|
284
|
+
*/
|
285
|
+
public PShape() {
|
286
|
+
this.family = GROUP;
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
/**
|
291
|
+
* @nowebref
|
292
|
+
*/
|
293
|
+
public PShape(int family) {
|
294
|
+
this.family = family;
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
/**
|
299
|
+
* @nowebref
|
300
|
+
*/
|
301
|
+
public PShape(PGraphics g, int family) {
|
302
|
+
this.g = g;
|
303
|
+
this.family = family;
|
304
|
+
|
305
|
+
// Style parameters are retrieved from the current values in the renderer.
|
306
|
+
textureMode = g.textureMode;
|
307
|
+
|
308
|
+
colorMode(g.colorMode,
|
309
|
+
g.colorModeX, g.colorModeY, g.colorModeZ, g.colorModeA);
|
310
|
+
|
311
|
+
// Initial values for fill, stroke and tint colors are also imported from
|
312
|
+
// the renderer. This is particular relevant for primitive shapes, since is
|
313
|
+
// not possible to set their color separately when creating them, and their
|
314
|
+
// input vertices are actually generated at rendering time, by which the
|
315
|
+
// color configuration of the renderer might have changed.
|
316
|
+
fill = g.fill;
|
317
|
+
fillColor = g.fillColor;
|
318
|
+
|
319
|
+
stroke = g.stroke;
|
320
|
+
strokeColor = g.strokeColor;
|
321
|
+
strokeWeight = g.strokeWeight;
|
322
|
+
strokeCap = g.strokeCap;
|
323
|
+
strokeJoin = g.strokeJoin;
|
324
|
+
|
325
|
+
tint = g.tint;
|
326
|
+
tintColor = g.tintColor;
|
327
|
+
|
328
|
+
setAmbient = g.setAmbient;
|
329
|
+
ambientColor = g.ambientColor;
|
330
|
+
specularColor = g.specularColor;
|
331
|
+
emissiveColor = g.emissiveColor;
|
332
|
+
shininess = g.shininess;
|
333
|
+
|
334
|
+
sphereDetailU = g.sphereDetailU;
|
335
|
+
sphereDetailV = g.sphereDetailV;
|
336
|
+
|
337
|
+
// bezierDetail = pg.bezierDetail;
|
338
|
+
// curveDetail = pg.curveDetail;
|
339
|
+
// curveTightness = pg.curveTightness;
|
340
|
+
|
341
|
+
rectMode = g.rectMode;
|
342
|
+
ellipseMode = g.ellipseMode;
|
343
|
+
|
344
|
+
// normalX = normalY = 0;
|
345
|
+
// normalZ = 1;
|
346
|
+
//
|
347
|
+
// normalMode = NORMAL_MODE_AUTO;
|
348
|
+
|
349
|
+
// To make sure that the first vertex is marked as a break.
|
350
|
+
// Same behavior as in the immediate mode.
|
351
|
+
// breakShape = false;
|
352
|
+
|
353
|
+
if (family == GROUP) {
|
354
|
+
// GROUP shapes are always marked as ended.
|
355
|
+
// shapeCreated = true;
|
356
|
+
// TODO why was this commented out?
|
357
|
+
}
|
358
|
+
}
|
359
|
+
|
360
|
+
|
361
|
+
public PShape(PGraphics g, int kind, float... params) {
|
362
|
+
this(g, PRIMITIVE);
|
363
|
+
setKind(kind);
|
364
|
+
setParams(params);
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
public void setFamily(int family) {
|
369
|
+
this.family = family;
|
370
|
+
}
|
371
|
+
|
372
|
+
|
373
|
+
public void setKind(int kind) {
|
374
|
+
this.kind = kind;
|
375
|
+
}
|
376
|
+
|
377
|
+
|
378
|
+
public void setName(String name) {
|
379
|
+
this.name = name;
|
380
|
+
}
|
381
|
+
|
382
|
+
|
383
|
+
public String getName() {
|
384
|
+
return name;
|
385
|
+
}
|
386
|
+
|
387
|
+
/**
|
388
|
+
* ( begin auto-generated from PShape_isVisible.xml )
|
389
|
+
*
|
390
|
+
* Returns a boolean value "true" if the image is set to be visible,
|
391
|
+
* "false" if not. This is modified with the <b>setVisible()</b> parameter.
|
392
|
+
* <br/> <br/>
|
393
|
+
* The visibility of a shape is usually controlled by whatever program
|
394
|
+
* created the SVG file. For instance, this parameter is controlled by
|
395
|
+
* showing or hiding the shape in the layers palette in Adobe Illustrator.
|
396
|
+
*
|
397
|
+
* ( end auto-generated )
|
398
|
+
* @webref pshape:method
|
399
|
+
* @usage web_application
|
400
|
+
* @brief Returns a boolean value "true" if the image is set to be visible, "false" if not
|
401
|
+
* @see PShape#setVisible(boolean)
|
402
|
+
*/
|
403
|
+
public boolean isVisible() {
|
404
|
+
return visible;
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
/**
|
409
|
+
* ( begin auto-generated from PShape_setVisible.xml )
|
410
|
+
*
|
411
|
+
* Sets the shape to be visible or invisible. This is determined by the
|
412
|
+
* value of the <b>visible</b> parameter.
|
413
|
+
* <br/> <br/>
|
414
|
+
* The visibility of a shape is usually controlled by whatever program
|
415
|
+
* created the SVG file. For instance, this parameter is controlled by
|
416
|
+
* showing or hiding the shape in the layers palette in Adobe Illustrator.
|
417
|
+
*
|
418
|
+
* ( end auto-generated )
|
419
|
+
* @webref pshape:mathod
|
420
|
+
* @usage web_application
|
421
|
+
* @brief Sets the shape to be visible or invisible
|
422
|
+
* @param visible "false" makes the shape invisible and "true" makes it visible
|
423
|
+
* @see PShape#isVisible()
|
424
|
+
*/
|
425
|
+
public void setVisible(boolean visible) {
|
426
|
+
this.visible = visible;
|
427
|
+
}
|
428
|
+
|
429
|
+
|
430
|
+
/**
|
431
|
+
* ( begin auto-generated from PShape_disableStyle.xml )
|
432
|
+
*
|
433
|
+
* Disables the shape's style data and uses Processing's current styles.
|
434
|
+
* Styles include attributes such as colors, stroke weight, and stroke
|
435
|
+
* joints.
|
436
|
+
*
|
437
|
+
* ( end auto-generated )
|
438
|
+
* <h3>Advanced</h3>
|
439
|
+
* Overrides this shape's style information and uses PGraphics styles and
|
440
|
+
* colors. Identical to ignoreStyles(true). Also disables styles for all
|
441
|
+
* child shapes.
|
442
|
+
* @webref pshape:method
|
443
|
+
* @usage web_application
|
444
|
+
* @brief Disables the shape's style data and uses Processing styles
|
445
|
+
* @see PShape#enableStyle()
|
446
|
+
*/
|
447
|
+
public void disableStyle() {
|
448
|
+
style = false;
|
449
|
+
|
450
|
+
for (int i = 0; i < childCount; i++) {
|
451
|
+
children[i].disableStyle();
|
452
|
+
}
|
453
|
+
}
|
454
|
+
|
455
|
+
|
456
|
+
/**
|
457
|
+
* ( begin auto-generated from PShape_enableStyle.xml )
|
458
|
+
*
|
459
|
+
* Enables the shape's style data and ignores Processing's current styles.
|
460
|
+
* Styles include attributes such as colors, stroke weight, and stroke
|
461
|
+
* joints.
|
462
|
+
*
|
463
|
+
* ( end auto-generated )
|
464
|
+
*
|
465
|
+
* @webref pshape:method
|
466
|
+
* @usage web_application
|
467
|
+
* @brief Enables the shape's style data and ignores the Processing styles
|
468
|
+
* @see PShape#disableStyle()
|
469
|
+
*/
|
470
|
+
public void enableStyle() {
|
471
|
+
style = true;
|
472
|
+
|
473
|
+
for (int i = 0; i < childCount; i++) {
|
474
|
+
children[i].enableStyle();
|
475
|
+
}
|
476
|
+
}
|
477
|
+
|
478
|
+
|
479
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
480
|
+
|
481
|
+
|
482
|
+
// protected void checkBounds() {
|
483
|
+
// if (width == 0 || height == 0) {
|
484
|
+
// // calculate bounds here (also take kids into account)
|
485
|
+
// width = 1;
|
486
|
+
// height = 1;
|
487
|
+
// }
|
488
|
+
// }
|
489
|
+
|
490
|
+
|
491
|
+
/**
|
492
|
+
* Get the width of the drawing area (not necessarily the shape boundary).
|
493
|
+
*/
|
494
|
+
public float getWidth() {
|
495
|
+
//checkBounds();
|
496
|
+
return width;
|
497
|
+
}
|
498
|
+
|
499
|
+
|
500
|
+
/**
|
501
|
+
* Get the height of the drawing area (not necessarily the shape boundary).
|
502
|
+
*/
|
503
|
+
public float getHeight() {
|
504
|
+
//checkBounds();
|
505
|
+
return height;
|
506
|
+
}
|
507
|
+
|
508
|
+
|
509
|
+
/**
|
510
|
+
* Get the depth of the shape area (not necessarily the shape boundary). Only makes sense for 3D PShape subclasses,
|
511
|
+
* such as PShape3D.
|
512
|
+
*/
|
513
|
+
public float getDepth() {
|
514
|
+
//checkBounds();
|
515
|
+
return depth;
|
516
|
+
}
|
517
|
+
|
518
|
+
|
519
|
+
|
520
|
+
/*
|
521
|
+
// TODO unapproved
|
522
|
+
protected PVector getTop() {
|
523
|
+
return getTop(null);
|
524
|
+
}
|
525
|
+
|
526
|
+
|
527
|
+
protected PVector getTop(PVector top) {
|
528
|
+
if (top == null) {
|
529
|
+
top = new PVector();
|
530
|
+
}
|
531
|
+
return top;
|
532
|
+
}
|
533
|
+
|
534
|
+
|
535
|
+
protected PVector getBottom() {
|
536
|
+
return getBottom(null);
|
537
|
+
}
|
538
|
+
|
539
|
+
|
540
|
+
protected PVector getBottom(PVector bottom) {
|
541
|
+
if (bottom == null) {
|
542
|
+
bottom = new PVector();
|
543
|
+
}
|
544
|
+
return bottom;
|
545
|
+
}
|
546
|
+
*/
|
547
|
+
|
548
|
+
|
549
|
+
/**
|
550
|
+
* Return true if this shape is 2D. Defaults to true.
|
551
|
+
*/
|
552
|
+
public boolean is2D() {
|
553
|
+
return !is3D;
|
554
|
+
}
|
555
|
+
|
556
|
+
|
557
|
+
/**
|
558
|
+
* Return true if this shape is 3D. Defaults to false.
|
559
|
+
*/
|
560
|
+
public boolean is3D() {
|
561
|
+
return is3D;
|
562
|
+
}
|
563
|
+
|
564
|
+
|
565
|
+
public void set3D(boolean val) {
|
566
|
+
is3D = val;
|
567
|
+
}
|
568
|
+
|
569
|
+
|
570
|
+
// /**
|
571
|
+
// * Return true if this shape requires rendering through OpenGL. Defaults to false.
|
572
|
+
// */
|
573
|
+
// // TODO unapproved
|
574
|
+
// public boolean isGL() {
|
575
|
+
// return false;
|
576
|
+
// }
|
577
|
+
|
578
|
+
|
579
|
+
///////////////////////////////////////////////////////////
|
580
|
+
|
581
|
+
//
|
582
|
+
|
583
|
+
// Drawing methods
|
584
|
+
|
585
|
+
public void textureMode(int mode) {
|
586
|
+
if (!openShape) {
|
587
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "textureMode()");
|
588
|
+
return;
|
589
|
+
}
|
590
|
+
|
591
|
+
textureMode = mode;
|
592
|
+
}
|
593
|
+
|
594
|
+
public void texture(PImage tex) {
|
595
|
+
if (!openShape) {
|
596
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "texture()");
|
597
|
+
return;
|
598
|
+
}
|
599
|
+
|
600
|
+
image = tex;
|
601
|
+
}
|
602
|
+
|
603
|
+
public void noTexture() {
|
604
|
+
if (!openShape) {
|
605
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "noTexture()");
|
606
|
+
return;
|
607
|
+
}
|
608
|
+
|
609
|
+
image = null;
|
610
|
+
}
|
611
|
+
|
612
|
+
|
613
|
+
// TODO unapproved
|
614
|
+
protected void solid(boolean solid) {
|
615
|
+
}
|
616
|
+
|
617
|
+
|
618
|
+
/**
|
619
|
+
* @webref shape:vertex
|
620
|
+
* @brief Starts a new contour
|
621
|
+
* @see PShape#endContour()
|
622
|
+
*/
|
623
|
+
public void beginContour() {
|
624
|
+
if (!openShape) {
|
625
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "beginContour()");
|
626
|
+
return;
|
627
|
+
}
|
628
|
+
|
629
|
+
if (family == GROUP) {
|
630
|
+
PGraphics.showWarning("Cannot begin contour in GROUP shapes");
|
631
|
+
return;
|
632
|
+
}
|
633
|
+
|
634
|
+
if (openContour) {
|
635
|
+
PGraphics.showWarning("Already called beginContour().");
|
636
|
+
return;
|
637
|
+
}
|
638
|
+
openContour = true;
|
639
|
+
beginContourImpl();
|
640
|
+
}
|
641
|
+
|
642
|
+
|
643
|
+
protected void beginContourImpl() {
|
644
|
+
if (vertexCodes == null) {
|
645
|
+
vertexCodes = new int[10];
|
646
|
+
} else if (vertexCodes.length == vertexCodeCount) {
|
647
|
+
vertexCodes = PApplet.expand(vertexCodes);
|
648
|
+
}
|
649
|
+
vertexCodes[vertexCodeCount++] = BREAK;
|
650
|
+
}
|
651
|
+
|
652
|
+
|
653
|
+
/**
|
654
|
+
* @webref shape:vertex
|
655
|
+
* @brief Ends a contour
|
656
|
+
* @see PShape#beginContour()
|
657
|
+
*/
|
658
|
+
public void endContour() {
|
659
|
+
if (!openShape) {
|
660
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "endContour()");
|
661
|
+
return;
|
662
|
+
}
|
663
|
+
|
664
|
+
if (family == GROUP) {
|
665
|
+
PGraphics.showWarning("Cannot end contour in GROUP shapes");
|
666
|
+
return;
|
667
|
+
}
|
668
|
+
|
669
|
+
if (!openContour) {
|
670
|
+
PGraphics.showWarning("Need to call beginContour() first.");
|
671
|
+
return;
|
672
|
+
}
|
673
|
+
endContourImpl();
|
674
|
+
openContour = false;
|
675
|
+
}
|
676
|
+
|
677
|
+
|
678
|
+
protected void endContourImpl() {
|
679
|
+
}
|
680
|
+
|
681
|
+
|
682
|
+
public void vertex(float x, float y) {
|
683
|
+
if (vertices == null) {
|
684
|
+
vertices = new float[10][2];
|
685
|
+
} else if (vertices.length == vertexCount) {
|
686
|
+
vertices = (float[][]) PApplet.expand(vertices);
|
687
|
+
}
|
688
|
+
vertices[vertexCount++] = new float[] { x, y };
|
689
|
+
|
690
|
+
if (vertexCodes == null) {
|
691
|
+
vertexCodes = new int[10];
|
692
|
+
} else if (vertexCodes.length == vertexCodeCount) {
|
693
|
+
vertexCodes = PApplet.expand(vertexCodes);
|
694
|
+
}
|
695
|
+
vertexCodes[vertexCodeCount++] = VERTEX;
|
696
|
+
|
697
|
+
if (x > width) {
|
698
|
+
width = x;
|
699
|
+
}
|
700
|
+
if (y > height) {
|
701
|
+
height = y;
|
702
|
+
}
|
703
|
+
}
|
704
|
+
|
705
|
+
|
706
|
+
public void vertex(float x, float y, float u, float v) {
|
707
|
+
}
|
708
|
+
|
709
|
+
|
710
|
+
public void vertex(float x, float y, float z) {
|
711
|
+
vertex(x, y); // maybe? maybe not?
|
712
|
+
}
|
713
|
+
|
714
|
+
|
715
|
+
public void vertex(float x, float y, float z, float u, float v) {
|
716
|
+
}
|
717
|
+
|
718
|
+
|
719
|
+
public void normal(float nx, float ny, float nz) {
|
720
|
+
}
|
721
|
+
|
722
|
+
|
723
|
+
public void attribPosition(String name, float x, float y, float z) {
|
724
|
+
}
|
725
|
+
|
726
|
+
public void attribNormal(String name, float nx, float ny, float nz) {
|
727
|
+
}
|
728
|
+
|
729
|
+
|
730
|
+
public void attribColor(String name, int color) {
|
731
|
+
}
|
732
|
+
|
733
|
+
|
734
|
+
public void attrib(String name, float... values) {
|
735
|
+
}
|
736
|
+
|
737
|
+
|
738
|
+
public void attrib(String name, int... values) {
|
739
|
+
}
|
740
|
+
|
741
|
+
|
742
|
+
public void attrib(String name, boolean... values) {
|
743
|
+
}
|
744
|
+
|
745
|
+
|
746
|
+
/**
|
747
|
+
* @webref pshape:method
|
748
|
+
* @brief Starts the creation of a new PShape
|
749
|
+
* @see PApplet#endShape()
|
750
|
+
*/
|
751
|
+
public void beginShape() {
|
752
|
+
beginShape(POLYGON);
|
753
|
+
}
|
754
|
+
|
755
|
+
|
756
|
+
public void beginShape(int kind) {
|
757
|
+
this.kind = kind;
|
758
|
+
openShape = true;
|
759
|
+
}
|
760
|
+
|
761
|
+
/**
|
762
|
+
* @webref pshape:method
|
763
|
+
* @brief Finishes the creation of a new PShape
|
764
|
+
* @see PApplet#beginShape()
|
765
|
+
*/
|
766
|
+
public void endShape() {
|
767
|
+
endShape(OPEN);
|
768
|
+
}
|
769
|
+
|
770
|
+
|
771
|
+
public void endShape(int mode) {
|
772
|
+
if (family == GROUP) {
|
773
|
+
PGraphics.showWarning("Cannot end GROUP shape");
|
774
|
+
return;
|
775
|
+
}
|
776
|
+
|
777
|
+
if (!openShape) {
|
778
|
+
PGraphics.showWarning("Need to call beginShape() first");
|
779
|
+
return;
|
780
|
+
}
|
781
|
+
|
782
|
+
close = (mode==CLOSE);
|
783
|
+
|
784
|
+
// this is the state of the shape
|
785
|
+
openShape = false;
|
786
|
+
}
|
787
|
+
|
788
|
+
|
789
|
+
//////////////////////////////////////////////////////////////
|
790
|
+
|
791
|
+
// STROKE CAP/JOIN/WEIGHT
|
792
|
+
|
793
|
+
|
794
|
+
public void strokeWeight(float weight) {
|
795
|
+
if (!openShape) {
|
796
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "strokeWeight()");
|
797
|
+
return;
|
798
|
+
}
|
799
|
+
|
800
|
+
strokeWeight = weight;
|
801
|
+
}
|
802
|
+
|
803
|
+
public void strokeJoin(int join) {
|
804
|
+
if (!openShape) {
|
805
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "strokeJoin()");
|
806
|
+
return;
|
807
|
+
}
|
808
|
+
|
809
|
+
strokeJoin = join;
|
810
|
+
}
|
811
|
+
|
812
|
+
public void strokeCap(int cap) {
|
813
|
+
if (!openShape) {
|
814
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "strokeCap()");
|
815
|
+
return;
|
816
|
+
}
|
817
|
+
|
818
|
+
strokeCap = cap;
|
819
|
+
}
|
820
|
+
|
821
|
+
|
822
|
+
//////////////////////////////////////////////////////////////
|
823
|
+
|
824
|
+
// FILL COLOR
|
825
|
+
|
826
|
+
|
827
|
+
public void noFill() {
|
828
|
+
if (!openShape) {
|
829
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "noFill()");
|
830
|
+
return;
|
831
|
+
}
|
832
|
+
|
833
|
+
fill = false;
|
834
|
+
fillColor = 0x0;
|
835
|
+
|
836
|
+
if (!setAmbient) {
|
837
|
+
ambientColor = fillColor;
|
838
|
+
}
|
839
|
+
}
|
840
|
+
|
841
|
+
|
842
|
+
public void fill(int rgb) {
|
843
|
+
if (!openShape) {
|
844
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()");
|
845
|
+
return;
|
846
|
+
}
|
847
|
+
|
848
|
+
fill = true;
|
849
|
+
colorCalc(rgb);
|
850
|
+
fillColor = calcColor;
|
851
|
+
|
852
|
+
if (!setAmbient) {
|
853
|
+
ambientColor = fillColor;
|
854
|
+
}
|
855
|
+
}
|
856
|
+
|
857
|
+
|
858
|
+
public void fill(int rgb, float alpha) {
|
859
|
+
if (!openShape) {
|
860
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()");
|
861
|
+
return;
|
862
|
+
}
|
863
|
+
|
864
|
+
fill = true;
|
865
|
+
colorCalc(rgb, alpha);
|
866
|
+
fillColor = calcColor;
|
867
|
+
|
868
|
+
if (!setAmbient) {
|
869
|
+
ambientColor = fillColor;
|
870
|
+
}
|
871
|
+
}
|
872
|
+
|
873
|
+
|
874
|
+
public void fill(float gray) {
|
875
|
+
if (!openShape) {
|
876
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()");
|
877
|
+
return;
|
878
|
+
}
|
879
|
+
|
880
|
+
fill = true;
|
881
|
+
colorCalc(gray);
|
882
|
+
fillColor = calcColor;
|
883
|
+
|
884
|
+
if (!setAmbient) {
|
885
|
+
ambientColor = fillColor;
|
886
|
+
}
|
887
|
+
}
|
888
|
+
|
889
|
+
|
890
|
+
public void fill(float gray, float alpha) {
|
891
|
+
if (!openShape) {
|
892
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()");
|
893
|
+
return;
|
894
|
+
}
|
895
|
+
|
896
|
+
fill = true;
|
897
|
+
colorCalc(gray, alpha);
|
898
|
+
fillColor = calcColor;
|
899
|
+
|
900
|
+
if (!setAmbient) {
|
901
|
+
ambient(fillColor);
|
902
|
+
setAmbient = false;
|
903
|
+
}
|
904
|
+
|
905
|
+
if (!setAmbient) {
|
906
|
+
ambientColor = fillColor;
|
907
|
+
}
|
908
|
+
}
|
909
|
+
|
910
|
+
|
911
|
+
public void fill(float x, float y, float z) {
|
912
|
+
if (!openShape) {
|
913
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()");
|
914
|
+
return;
|
915
|
+
}
|
916
|
+
|
917
|
+
fill = true;
|
918
|
+
colorCalc(x, y, z);
|
919
|
+
fillColor = calcColor;
|
920
|
+
|
921
|
+
if (!setAmbient) {
|
922
|
+
ambientColor = fillColor;
|
923
|
+
}
|
924
|
+
}
|
925
|
+
|
926
|
+
|
927
|
+
public void fill(float x, float y, float z, float a) {
|
928
|
+
if (!openShape) {
|
929
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "fill()");
|
930
|
+
return;
|
931
|
+
}
|
932
|
+
|
933
|
+
fill = true;
|
934
|
+
colorCalc(x, y, z, a);
|
935
|
+
fillColor = calcColor;
|
936
|
+
|
937
|
+
if (!setAmbient) {
|
938
|
+
ambientColor = fillColor;
|
939
|
+
}
|
940
|
+
}
|
941
|
+
|
942
|
+
|
943
|
+
//////////////////////////////////////////////////////////////
|
944
|
+
|
945
|
+
// STROKE COLOR
|
946
|
+
|
947
|
+
|
948
|
+
public void noStroke() {
|
949
|
+
if (!openShape) {
|
950
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "noStroke()");
|
951
|
+
return;
|
952
|
+
}
|
953
|
+
|
954
|
+
stroke = false;
|
955
|
+
}
|
956
|
+
|
957
|
+
|
958
|
+
public void stroke(int rgb) {
|
959
|
+
if (!openShape) {
|
960
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()");
|
961
|
+
return;
|
962
|
+
}
|
963
|
+
|
964
|
+
stroke = true;
|
965
|
+
colorCalc(rgb);
|
966
|
+
strokeColor = calcColor;
|
967
|
+
}
|
968
|
+
|
969
|
+
|
970
|
+
public void stroke(int rgb, float alpha) {
|
971
|
+
if (!openShape) {
|
972
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()");
|
973
|
+
return;
|
974
|
+
}
|
975
|
+
|
976
|
+
stroke = true;
|
977
|
+
colorCalc(rgb, alpha);
|
978
|
+
strokeColor = calcColor;
|
979
|
+
}
|
980
|
+
|
981
|
+
|
982
|
+
public void stroke(float gray) {
|
983
|
+
if (!openShape) {
|
984
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()");
|
985
|
+
return;
|
986
|
+
}
|
987
|
+
|
988
|
+
stroke = true;
|
989
|
+
colorCalc(gray);
|
990
|
+
strokeColor = calcColor;
|
991
|
+
}
|
992
|
+
|
993
|
+
|
994
|
+
public void stroke(float gray, float alpha) {
|
995
|
+
if (!openShape) {
|
996
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()");
|
997
|
+
return;
|
998
|
+
}
|
999
|
+
|
1000
|
+
stroke = true;
|
1001
|
+
colorCalc(gray, alpha);
|
1002
|
+
strokeColor = calcColor;
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
|
1006
|
+
public void stroke(float x, float y, float z) {
|
1007
|
+
if (!openShape) {
|
1008
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()");
|
1009
|
+
return;
|
1010
|
+
}
|
1011
|
+
|
1012
|
+
stroke = true;
|
1013
|
+
colorCalc(x, y, z);
|
1014
|
+
strokeColor = calcColor;
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
|
1018
|
+
public void stroke(float x, float y, float z, float alpha) {
|
1019
|
+
if (!openShape) {
|
1020
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "stroke()");
|
1021
|
+
return;
|
1022
|
+
}
|
1023
|
+
|
1024
|
+
stroke = true;
|
1025
|
+
colorCalc(x, y, z, alpha);
|
1026
|
+
strokeColor = calcColor;
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
|
1030
|
+
//////////////////////////////////////////////////////////////
|
1031
|
+
|
1032
|
+
// TINT COLOR
|
1033
|
+
|
1034
|
+
|
1035
|
+
public void noTint() {
|
1036
|
+
if (!openShape) {
|
1037
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "noTint()");
|
1038
|
+
return;
|
1039
|
+
}
|
1040
|
+
|
1041
|
+
tint = false;
|
1042
|
+
}
|
1043
|
+
|
1044
|
+
|
1045
|
+
public void tint(int rgb) {
|
1046
|
+
if (!openShape) {
|
1047
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()");
|
1048
|
+
return;
|
1049
|
+
}
|
1050
|
+
|
1051
|
+
tint = true;
|
1052
|
+
colorCalc(rgb);
|
1053
|
+
tintColor = calcColor;
|
1054
|
+
}
|
1055
|
+
|
1056
|
+
|
1057
|
+
public void tint(int rgb, float alpha) {
|
1058
|
+
if (!openShape) {
|
1059
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()");
|
1060
|
+
return;
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
tint = true;
|
1064
|
+
colorCalc(rgb, alpha);
|
1065
|
+
tintColor = calcColor;
|
1066
|
+
}
|
1067
|
+
|
1068
|
+
|
1069
|
+
public void tint(float gray) {
|
1070
|
+
if (!openShape) {
|
1071
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()");
|
1072
|
+
return;
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
tint = true;
|
1076
|
+
colorCalc(gray);
|
1077
|
+
tintColor = calcColor;
|
1078
|
+
}
|
1079
|
+
|
1080
|
+
|
1081
|
+
public void tint(float gray, float alpha) {
|
1082
|
+
if (!openShape) {
|
1083
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()");
|
1084
|
+
return;
|
1085
|
+
}
|
1086
|
+
|
1087
|
+
tint = true;
|
1088
|
+
colorCalc(gray, alpha);
|
1089
|
+
tintColor = calcColor;
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
|
1093
|
+
public void tint(float x, float y, float z) {
|
1094
|
+
if (!openShape) {
|
1095
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()");
|
1096
|
+
return;
|
1097
|
+
}
|
1098
|
+
|
1099
|
+
tint = true;
|
1100
|
+
colorCalc(x, y, z);
|
1101
|
+
tintColor = calcColor;
|
1102
|
+
}
|
1103
|
+
|
1104
|
+
|
1105
|
+
public void tint(float x, float y, float z, float alpha) {
|
1106
|
+
if (!openShape) {
|
1107
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "tint()");
|
1108
|
+
return;
|
1109
|
+
}
|
1110
|
+
|
1111
|
+
tint = true;
|
1112
|
+
colorCalc(x, y, z, alpha);
|
1113
|
+
tintColor = calcColor;
|
1114
|
+
}
|
1115
|
+
|
1116
|
+
|
1117
|
+
//////////////////////////////////////////////////////////////
|
1118
|
+
|
1119
|
+
// Ambient set/update
|
1120
|
+
|
1121
|
+
public void ambient(int rgb) {
|
1122
|
+
if (!openShape) {
|
1123
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "ambient()");
|
1124
|
+
return;
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
setAmbient = true;
|
1128
|
+
colorCalc(rgb);
|
1129
|
+
ambientColor = calcColor;
|
1130
|
+
}
|
1131
|
+
|
1132
|
+
|
1133
|
+
public void ambient(float gray) {
|
1134
|
+
if (!openShape) {
|
1135
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "ambient()");
|
1136
|
+
return;
|
1137
|
+
}
|
1138
|
+
|
1139
|
+
setAmbient = true;
|
1140
|
+
colorCalc(gray);
|
1141
|
+
ambientColor = calcColor;
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
|
1145
|
+
public void ambient(float x, float y, float z) {
|
1146
|
+
if (!openShape) {
|
1147
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "ambient()");
|
1148
|
+
return;
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
setAmbient = true;
|
1152
|
+
colorCalc(x, y, z);
|
1153
|
+
ambientColor = calcColor;
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
|
1157
|
+
//////////////////////////////////////////////////////////////
|
1158
|
+
|
1159
|
+
// Specular set/update
|
1160
|
+
|
1161
|
+
public void specular(int rgb) {
|
1162
|
+
if (!openShape) {
|
1163
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "specular()");
|
1164
|
+
return;
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
colorCalc(rgb);
|
1168
|
+
specularColor = calcColor;
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
|
1172
|
+
public void specular(float gray) {
|
1173
|
+
if (!openShape) {
|
1174
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "specular()");
|
1175
|
+
return;
|
1176
|
+
}
|
1177
|
+
|
1178
|
+
colorCalc(gray);
|
1179
|
+
specularColor = calcColor;
|
1180
|
+
}
|
1181
|
+
|
1182
|
+
|
1183
|
+
public void specular(float x, float y, float z) {
|
1184
|
+
if (!openShape) {
|
1185
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "specular()");
|
1186
|
+
return;
|
1187
|
+
}
|
1188
|
+
|
1189
|
+
colorCalc(x, y, z);
|
1190
|
+
specularColor = calcColor;
|
1191
|
+
}
|
1192
|
+
|
1193
|
+
|
1194
|
+
//////////////////////////////////////////////////////////////
|
1195
|
+
|
1196
|
+
// Emissive set/update
|
1197
|
+
|
1198
|
+
public void emissive(int rgb) {
|
1199
|
+
if (!openShape) {
|
1200
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "emissive()");
|
1201
|
+
return;
|
1202
|
+
}
|
1203
|
+
|
1204
|
+
colorCalc(rgb);
|
1205
|
+
emissiveColor = calcColor;
|
1206
|
+
}
|
1207
|
+
|
1208
|
+
|
1209
|
+
public void emissive(float gray) {
|
1210
|
+
if (!openShape) {
|
1211
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "emissive()");
|
1212
|
+
return;
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
colorCalc(gray);
|
1216
|
+
emissiveColor = calcColor;
|
1217
|
+
}
|
1218
|
+
|
1219
|
+
|
1220
|
+
public void emissive(float x, float y, float z) {
|
1221
|
+
if (!openShape) {
|
1222
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "emissive()");
|
1223
|
+
return;
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
colorCalc(x, y, z);
|
1227
|
+
emissiveColor = calcColor;
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
|
1231
|
+
//////////////////////////////////////////////////////////////
|
1232
|
+
|
1233
|
+
// Shininess set/update
|
1234
|
+
|
1235
|
+
public void shininess(float shine) {
|
1236
|
+
if (!openShape) {
|
1237
|
+
PGraphics.showWarning(OUTSIDE_BEGIN_END_ERROR, "shininess()");
|
1238
|
+
return;
|
1239
|
+
}
|
1240
|
+
|
1241
|
+
shininess = shine;
|
1242
|
+
}
|
1243
|
+
|
1244
|
+
///////////////////////////////////////////////////////////
|
1245
|
+
|
1246
|
+
//
|
1247
|
+
|
1248
|
+
// Bezier curves
|
1249
|
+
|
1250
|
+
|
1251
|
+
public void bezierDetail(int detail) {
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
|
1255
|
+
public void bezierVertex(float x2, float y2,
|
1256
|
+
float x3, float y3,
|
1257
|
+
float x4, float y4) {
|
1258
|
+
if (vertices == null) {
|
1259
|
+
vertices = new float[10][];
|
1260
|
+
} else if (vertexCount + 2 >= vertices.length) {
|
1261
|
+
vertices = (float[][]) PApplet.expand(vertices);
|
1262
|
+
}
|
1263
|
+
vertices[vertexCount++] = new float[] { x2, y2 };
|
1264
|
+
vertices[vertexCount++] = new float[] { x3, y3 };
|
1265
|
+
vertices[vertexCount++] = new float[] { x4, y4 };
|
1266
|
+
|
1267
|
+
// vertexCodes must be allocated because a vertex() call is required
|
1268
|
+
if (vertexCodes.length == vertexCodeCount) {
|
1269
|
+
vertexCodes = PApplet.expand(vertexCodes);
|
1270
|
+
}
|
1271
|
+
vertexCodes[vertexCodeCount++] = BEZIER_VERTEX;
|
1272
|
+
|
1273
|
+
if (x4 > width) {
|
1274
|
+
width = x4;
|
1275
|
+
}
|
1276
|
+
if (y4 > height) {
|
1277
|
+
height = y4;
|
1278
|
+
}
|
1279
|
+
}
|
1280
|
+
|
1281
|
+
|
1282
|
+
public void bezierVertex(float x2, float y2, float z2,
|
1283
|
+
float x3, float y3, float z3,
|
1284
|
+
float x4, float y4, float z4) {
|
1285
|
+
}
|
1286
|
+
|
1287
|
+
|
1288
|
+
public void quadraticVertex(float cx, float cy,
|
1289
|
+
float x3, float y3) {
|
1290
|
+
if (vertices == null) {
|
1291
|
+
vertices = new float[10][];
|
1292
|
+
} else if (vertexCount + 1 >= vertices.length) {
|
1293
|
+
vertices = (float[][]) PApplet.expand(vertices);
|
1294
|
+
}
|
1295
|
+
vertices[vertexCount++] = new float[] { cx, cy };
|
1296
|
+
vertices[vertexCount++] = new float[] { x3, y3 };
|
1297
|
+
|
1298
|
+
// vertexCodes must be allocated because a vertex() call is required
|
1299
|
+
if (vertexCodes.length == vertexCodeCount) {
|
1300
|
+
vertexCodes = PApplet.expand(vertexCodes);
|
1301
|
+
}
|
1302
|
+
vertexCodes[vertexCodeCount++] = QUADRATIC_VERTEX;
|
1303
|
+
|
1304
|
+
if (x3 > width) {
|
1305
|
+
width = x3;
|
1306
|
+
}
|
1307
|
+
if (y3 > height) {
|
1308
|
+
height = y3;
|
1309
|
+
}
|
1310
|
+
}
|
1311
|
+
|
1312
|
+
|
1313
|
+
public void quadraticVertex(float cx, float cy, float cz,
|
1314
|
+
float x3, float y3, float z3) {
|
1315
|
+
}
|
1316
|
+
|
1317
|
+
|
1318
|
+
///////////////////////////////////////////////////////////
|
1319
|
+
|
1320
|
+
//
|
1321
|
+
|
1322
|
+
// Catmull-Rom curves
|
1323
|
+
|
1324
|
+
public void curveDetail(int detail) {
|
1325
|
+
}
|
1326
|
+
|
1327
|
+
public void curveTightness(float tightness) {
|
1328
|
+
}
|
1329
|
+
|
1330
|
+
public void curveVertex(float x, float y) {
|
1331
|
+
}
|
1332
|
+
|
1333
|
+
public void curveVertex(float x, float y, float z) {
|
1334
|
+
}
|
1335
|
+
|
1336
|
+
|
1337
|
+
|
1338
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
1339
|
+
|
1340
|
+
|
1341
|
+
/*
|
1342
|
+
boolean strokeSaved;
|
1343
|
+
int strokeColorSaved;
|
1344
|
+
float strokeWeightSaved;
|
1345
|
+
int strokeCapSaved;
|
1346
|
+
int strokeJoinSaved;
|
1347
|
+
|
1348
|
+
boolean fillSaved;
|
1349
|
+
int fillColorSaved;
|
1350
|
+
|
1351
|
+
int rectModeSaved;
|
1352
|
+
int ellipseModeSaved;
|
1353
|
+
int shapeModeSaved;
|
1354
|
+
*/
|
1355
|
+
|
1356
|
+
|
1357
|
+
protected void pre(PGraphics g) {
|
1358
|
+
if (matrix != null) {
|
1359
|
+
g.pushMatrix();
|
1360
|
+
g.applyMatrix(matrix);
|
1361
|
+
}
|
1362
|
+
|
1363
|
+
/*
|
1364
|
+
strokeSaved = g.stroke;
|
1365
|
+
strokeColorSaved = g.strokeColor;
|
1366
|
+
strokeWeightSaved = g.strokeWeight;
|
1367
|
+
strokeCapSaved = g.strokeCap;
|
1368
|
+
strokeJoinSaved = g.strokeJoin;
|
1369
|
+
|
1370
|
+
fillSaved = g.fill;
|
1371
|
+
fillColorSaved = g.fillColor;
|
1372
|
+
|
1373
|
+
rectModeSaved = g.rectMode;
|
1374
|
+
ellipseModeSaved = g.ellipseMode;
|
1375
|
+
shapeModeSaved = g.shapeMode;
|
1376
|
+
*/
|
1377
|
+
if (style) {
|
1378
|
+
g.pushStyle();
|
1379
|
+
styles(g);
|
1380
|
+
}
|
1381
|
+
}
|
1382
|
+
|
1383
|
+
|
1384
|
+
protected void styles(PGraphics g) {
|
1385
|
+
// should not be necessary because using only the int version of color
|
1386
|
+
//parent.colorMode(PConstants.RGB, 255);
|
1387
|
+
|
1388
|
+
if (stroke) {
|
1389
|
+
g.stroke(strokeColor);
|
1390
|
+
g.strokeWeight(strokeWeight);
|
1391
|
+
g.strokeCap(strokeCap);
|
1392
|
+
g.strokeJoin(strokeJoin);
|
1393
|
+
} else {
|
1394
|
+
g.noStroke();
|
1395
|
+
}
|
1396
|
+
|
1397
|
+
if (fill) {
|
1398
|
+
//System.out.println("filling " + PApplet.hex(fillColor));
|
1399
|
+
g.fill(fillColor);
|
1400
|
+
} else {
|
1401
|
+
g.noFill();
|
1402
|
+
}
|
1403
|
+
}
|
1404
|
+
|
1405
|
+
|
1406
|
+
protected void post(PGraphics g) {
|
1407
|
+
// for (int i = 0; i < childCount; i++) {
|
1408
|
+
// children[i].draw(g);
|
1409
|
+
// }
|
1410
|
+
|
1411
|
+
/*
|
1412
|
+
// TODO this is not sufficient, since not saving fillR et al.
|
1413
|
+
g.stroke = strokeSaved;
|
1414
|
+
g.strokeColor = strokeColorSaved;
|
1415
|
+
g.strokeWeight = strokeWeightSaved;
|
1416
|
+
g.strokeCap = strokeCapSaved;
|
1417
|
+
g.strokeJoin = strokeJoinSaved;
|
1418
|
+
|
1419
|
+
g.fill = fillSaved;
|
1420
|
+
g.fillColor = fillColorSaved;
|
1421
|
+
|
1422
|
+
g.ellipseMode = ellipseModeSaved;
|
1423
|
+
*/
|
1424
|
+
|
1425
|
+
if (matrix != null) {
|
1426
|
+
g.popMatrix();
|
1427
|
+
}
|
1428
|
+
|
1429
|
+
if (style) {
|
1430
|
+
g.popStyle();
|
1431
|
+
}
|
1432
|
+
}
|
1433
|
+
|
1434
|
+
|
1435
|
+
////////////////////////////////////////////////////////////////////////
|
1436
|
+
//
|
1437
|
+
// Shape copy
|
1438
|
+
|
1439
|
+
|
1440
|
+
// TODO unapproved
|
1441
|
+
static protected PShape createShape(PApplet parent, PShape src) {
|
1442
|
+
PShape dest = null;
|
1443
|
+
if (src.family == GROUP) {
|
1444
|
+
dest = parent.createShape(GROUP);
|
1445
|
+
PShape.copyGroup(parent, src, dest);
|
1446
|
+
} else if (src.family == PRIMITIVE) {
|
1447
|
+
dest = parent.createShape(src.kind, src.params);
|
1448
|
+
PShape.copyPrimitive(src, dest);
|
1449
|
+
} else if (src.family == GEOMETRY) {
|
1450
|
+
dest = parent.createShape(src.kind);
|
1451
|
+
PShape.copyGeometry(src, dest);
|
1452
|
+
} else if (src.family == PATH) {
|
1453
|
+
dest = parent.createShape(PATH);
|
1454
|
+
PShape.copyPath(src, dest);
|
1455
|
+
}
|
1456
|
+
dest.setName(src.name);
|
1457
|
+
return dest;
|
1458
|
+
}
|
1459
|
+
|
1460
|
+
|
1461
|
+
// TODO unapproved
|
1462
|
+
static protected void copyGroup(PApplet parent, PShape src, PShape dest) {
|
1463
|
+
copyMatrix(src, dest);
|
1464
|
+
copyStyles(src, dest);
|
1465
|
+
copyImage(src, dest);
|
1466
|
+
for (int i = 0; i < src.childCount; i++) {
|
1467
|
+
PShape c = PShape.createShape(parent, src.children[i]);
|
1468
|
+
dest.addChild(c);
|
1469
|
+
}
|
1470
|
+
}
|
1471
|
+
|
1472
|
+
|
1473
|
+
// TODO unapproved
|
1474
|
+
static protected void copyPrimitive(PShape src, PShape dest) {
|
1475
|
+
copyMatrix(src, dest);
|
1476
|
+
copyStyles(src, dest);
|
1477
|
+
copyImage(src, dest);
|
1478
|
+
}
|
1479
|
+
|
1480
|
+
|
1481
|
+
// TODO unapproved
|
1482
|
+
static protected void copyGeometry(PShape src, PShape dest) {
|
1483
|
+
dest.beginShape(src.getKind());
|
1484
|
+
|
1485
|
+
copyMatrix(src, dest);
|
1486
|
+
copyStyles(src, dest);
|
1487
|
+
copyImage(src, dest);
|
1488
|
+
|
1489
|
+
if (src.style) {
|
1490
|
+
for (int i = 0; i < src.vertexCount; i++) {
|
1491
|
+
float[] vert = src.vertices[i];
|
1492
|
+
|
1493
|
+
dest.fill((int)(vert[PGraphics.A] * 255) << 24 |
|
1494
|
+
(int)(vert[PGraphics.R] * 255) << 16 |
|
1495
|
+
(int)(vert[PGraphics.G] * 255) << 8 |
|
1496
|
+
(int)(vert[PGraphics.B] * 255));
|
1497
|
+
|
1498
|
+
// Do we need to copy these as well?
|
1499
|
+
// dest.ambient(vert[PGraphics.AR] * 255, vert[PGraphics.AG] * 255, vert[PGraphics.AB] * 255);
|
1500
|
+
// dest.specular(vert[PGraphics.SPR] * 255, vert[PGraphics.SPG] * 255, vert[PGraphics.SPB] * 255);
|
1501
|
+
// dest.emissive(vert[PGraphics.ER] * 255, vert[PGraphics.EG] * 255, vert[PGraphics.EB] * 255);
|
1502
|
+
// dest.shininess(vert[PGraphics.SHINE]);
|
1503
|
+
|
1504
|
+
if (0 < PApplet.dist(vert[PGraphics.NX],
|
1505
|
+
vert[PGraphics.NY],
|
1506
|
+
vert[PGraphics.NZ], 0, 0, 0)) {
|
1507
|
+
dest.normal(vert[PGraphics.NX],
|
1508
|
+
vert[PGraphics.NY],
|
1509
|
+
vert[PGraphics.NZ]);
|
1510
|
+
}
|
1511
|
+
dest.vertex(vert[X], vert[Y], vert[Z],
|
1512
|
+
vert[PGraphics.U],
|
1513
|
+
vert[PGraphics.V]);
|
1514
|
+
}
|
1515
|
+
} else {
|
1516
|
+
for (int i = 0; i < src.vertexCount; i++) {
|
1517
|
+
float[] vert = src.vertices[i];
|
1518
|
+
if (vert[Z] == 0) {
|
1519
|
+
dest.vertex(vert[X], vert[Y]);
|
1520
|
+
} else {
|
1521
|
+
dest.vertex(vert[X], vert[Y], vert[Z]);
|
1522
|
+
}
|
1523
|
+
}
|
1524
|
+
}
|
1525
|
+
|
1526
|
+
dest.endShape();
|
1527
|
+
}
|
1528
|
+
|
1529
|
+
|
1530
|
+
// TODO unapproved
|
1531
|
+
static protected void copyPath(PShape src, PShape dest) {
|
1532
|
+
copyMatrix(src, dest);
|
1533
|
+
copyStyles(src, dest);
|
1534
|
+
copyImage(src, dest);
|
1535
|
+
dest.close = src.close;
|
1536
|
+
dest.setPath(src.vertexCount, src.vertices, src.vertexCodeCount, src.vertexCodes);
|
1537
|
+
}
|
1538
|
+
|
1539
|
+
|
1540
|
+
// TODO unapproved
|
1541
|
+
static protected void copyMatrix(PShape src, PShape dest) {
|
1542
|
+
if (src.matrix != null) {
|
1543
|
+
dest.applyMatrix(src.matrix);
|
1544
|
+
}
|
1545
|
+
}
|
1546
|
+
|
1547
|
+
|
1548
|
+
// TODO unapproved
|
1549
|
+
static protected void copyStyles(PShape src, PShape dest) {
|
1550
|
+
dest.ellipseMode = src.ellipseMode;
|
1551
|
+
dest.rectMode = src.rectMode;
|
1552
|
+
|
1553
|
+
if (src.stroke) {
|
1554
|
+
dest.stroke = true;
|
1555
|
+
dest.strokeColor = src.strokeColor;
|
1556
|
+
dest.strokeWeight = src.strokeWeight;
|
1557
|
+
dest.strokeCap = src.strokeCap;
|
1558
|
+
dest.strokeJoin = src.strokeJoin;
|
1559
|
+
} else {
|
1560
|
+
dest.stroke = false;
|
1561
|
+
}
|
1562
|
+
|
1563
|
+
if (src.fill) {
|
1564
|
+
dest.fill = true;
|
1565
|
+
dest.fillColor = src.fillColor;
|
1566
|
+
} else {
|
1567
|
+
dest.fill = false;
|
1568
|
+
}
|
1569
|
+
}
|
1570
|
+
|
1571
|
+
|
1572
|
+
// TODO unapproved
|
1573
|
+
static protected void copyImage(PShape src, PShape dest) {
|
1574
|
+
if (src.image != null) {
|
1575
|
+
dest.texture(src.image);
|
1576
|
+
}
|
1577
|
+
}
|
1578
|
+
|
1579
|
+
|
1580
|
+
|
1581
|
+
////////////////////////////////////////////////////////////////////////
|
1582
|
+
|
1583
|
+
|
1584
|
+
/**
|
1585
|
+
* Called by the following (the shape() command adds the g)
|
1586
|
+
* PShape s = loadShape("blah.svg");
|
1587
|
+
* shape(s);
|
1588
|
+
*/
|
1589
|
+
public void draw(PGraphics g) {
|
1590
|
+
if (visible) {
|
1591
|
+
pre(g);
|
1592
|
+
drawImpl(g);
|
1593
|
+
post(g);
|
1594
|
+
}
|
1595
|
+
}
|
1596
|
+
|
1597
|
+
|
1598
|
+
/**
|
1599
|
+
* Draws the SVG document.
|
1600
|
+
*/
|
1601
|
+
protected void drawImpl(PGraphics g) {
|
1602
|
+
if (family == GROUP) {
|
1603
|
+
drawGroup(g);
|
1604
|
+
} else if (family == PRIMITIVE) {
|
1605
|
+
drawPrimitive(g);
|
1606
|
+
} else if (family == GEOMETRY) {
|
1607
|
+
// Not same as path: `kind` matters.
|
1608
|
+
// drawPath(g);
|
1609
|
+
drawGeometry(g);
|
1610
|
+
} else if (family == PATH) {
|
1611
|
+
drawPath(g);
|
1612
|
+
}
|
1613
|
+
}
|
1614
|
+
|
1615
|
+
|
1616
|
+
protected void drawGroup(PGraphics g) {
|
1617
|
+
for (int i = 0; i < childCount; i++) {
|
1618
|
+
children[i].draw(g);
|
1619
|
+
}
|
1620
|
+
}
|
1621
|
+
|
1622
|
+
|
1623
|
+
protected void drawPrimitive(PGraphics g) {
|
1624
|
+
if (kind == POINT) {
|
1625
|
+
g.point(params[0], params[1]);
|
1626
|
+
|
1627
|
+
} else if (kind == LINE) {
|
1628
|
+
if (params.length == 4) { // 2D
|
1629
|
+
g.line(params[0], params[1],
|
1630
|
+
params[2], params[3]);
|
1631
|
+
} else { // 3D
|
1632
|
+
g.line(params[0], params[1], params[2],
|
1633
|
+
params[3], params[4], params[5]);
|
1634
|
+
}
|
1635
|
+
|
1636
|
+
} else if (kind == TRIANGLE) {
|
1637
|
+
g.triangle(params[0], params[1],
|
1638
|
+
params[2], params[3],
|
1639
|
+
params[4], params[5]);
|
1640
|
+
|
1641
|
+
} else if (kind == QUAD) {
|
1642
|
+
g.quad(params[0], params[1],
|
1643
|
+
params[2], params[3],
|
1644
|
+
params[4], params[5],
|
1645
|
+
params[6], params[7]);
|
1646
|
+
|
1647
|
+
} else if (kind == RECT) {
|
1648
|
+
if (image != null) {
|
1649
|
+
int oldMode = g.imageMode;
|
1650
|
+
g.imageMode(CORNER);
|
1651
|
+
g.image(image, params[0], params[1], params[2], params[3]);
|
1652
|
+
g.imageMode(oldMode);
|
1653
|
+
} else {
|
1654
|
+
int oldMode = g.rectMode;
|
1655
|
+
g.rectMode(rectMode);
|
1656
|
+
if (params.length == 4) {
|
1657
|
+
g.rect(params[0], params[1],
|
1658
|
+
params[2], params[3]);
|
1659
|
+
} else if (params.length == 5) {
|
1660
|
+
g.rect(params[0], params[1],
|
1661
|
+
params[2], params[3],
|
1662
|
+
params[4]);
|
1663
|
+
} else if (params.length == 8) {
|
1664
|
+
g.rect(params[0], params[1],
|
1665
|
+
params[2], params[3],
|
1666
|
+
params[4], params[5],
|
1667
|
+
params[6], params[7]);
|
1668
|
+
}
|
1669
|
+
g.rectMode(oldMode);
|
1670
|
+
}
|
1671
|
+
} else if (kind == ELLIPSE) {
|
1672
|
+
int oldMode = g.ellipseMode;
|
1673
|
+
g.ellipseMode(ellipseMode);
|
1674
|
+
g.ellipse(params[0], params[1],
|
1675
|
+
params[2], params[3]);
|
1676
|
+
g.ellipseMode(oldMode);
|
1677
|
+
|
1678
|
+
} else if (kind == ARC) {
|
1679
|
+
int oldMode = g.ellipseMode;
|
1680
|
+
g.ellipseMode(ellipseMode);
|
1681
|
+
if (params.length == 6) {
|
1682
|
+
g.arc(params[0], params[1],
|
1683
|
+
params[2], params[3],
|
1684
|
+
params[4], params[5]);
|
1685
|
+
} else if (params.length == 7) {
|
1686
|
+
g.arc(params[0], params[1],
|
1687
|
+
params[2], params[3],
|
1688
|
+
params[4], params[5],
|
1689
|
+
(int) params[6]);
|
1690
|
+
}
|
1691
|
+
g.ellipseMode(oldMode);
|
1692
|
+
|
1693
|
+
} else if (kind == BOX) {
|
1694
|
+
if (params.length == 1) {
|
1695
|
+
g.box(params[0]);
|
1696
|
+
} else {
|
1697
|
+
g.box(params[0], params[1], params[2]);
|
1698
|
+
}
|
1699
|
+
|
1700
|
+
} else if (kind == SPHERE) {
|
1701
|
+
g.sphere(params[0]);
|
1702
|
+
}
|
1703
|
+
}
|
1704
|
+
|
1705
|
+
|
1706
|
+
protected void drawGeometry(PGraphics g) {
|
1707
|
+
// get cache object using g.
|
1708
|
+
g.beginShape(kind);
|
1709
|
+
if (style) {
|
1710
|
+
for (int i = 0; i < vertexCount; i++) {
|
1711
|
+
g.vertex(vertices[i]);
|
1712
|
+
}
|
1713
|
+
} else {
|
1714
|
+
for (int i = 0; i < vertexCount; i++) {
|
1715
|
+
float[] vert = vertices[i];
|
1716
|
+
if (vert[Z] == 0) {
|
1717
|
+
g.vertex(vert[X], vert[Y]);
|
1718
|
+
} else {
|
1719
|
+
g.vertex(vert[X], vert[Y], vert[Z]);
|
1720
|
+
}
|
1721
|
+
}
|
1722
|
+
}
|
1723
|
+
g.endShape(close ? CLOSE : OPEN);
|
1724
|
+
}
|
1725
|
+
|
1726
|
+
|
1727
|
+
/*
|
1728
|
+
protected void drawPath(PGraphics g) {
|
1729
|
+
g.beginShape();
|
1730
|
+
for (int j = 0; j < childCount; j++) {
|
1731
|
+
if (j > 0) g.breakShape();
|
1732
|
+
int count = children[j].vertexCount;
|
1733
|
+
float[][] vert = children[j].vertices;
|
1734
|
+
int[] code = children[j].vertexCodes;
|
1735
|
+
|
1736
|
+
for (int i = 0; i < count; i++) {
|
1737
|
+
if (style) {
|
1738
|
+
if (children[j].fill) {
|
1739
|
+
g.fill(vert[i][R], vert[i][G], vert[i][B]);
|
1740
|
+
} else {
|
1741
|
+
g.noFill();
|
1742
|
+
}
|
1743
|
+
if (children[j].stroke) {
|
1744
|
+
g.stroke(vert[i][R], vert[i][G], vert[i][B]);
|
1745
|
+
} else {
|
1746
|
+
g.noStroke();
|
1747
|
+
}
|
1748
|
+
}
|
1749
|
+
g.edge(vert[i][EDGE] == 1);
|
1750
|
+
|
1751
|
+
if (code[i] == VERTEX) {
|
1752
|
+
g.vertex(vert[i]);
|
1753
|
+
|
1754
|
+
} else if (code[i] == BEZIER_VERTEX) {
|
1755
|
+
float z0 = vert[i+0][Z];
|
1756
|
+
float z1 = vert[i+1][Z];
|
1757
|
+
float z2 = vert[i+2][Z];
|
1758
|
+
if (z0 == 0 && z1 == 0 && z2 == 0) {
|
1759
|
+
g.bezierVertex(vert[i+0][X], vert[i+0][Y], z0,
|
1760
|
+
vert[i+1][X], vert[i+1][Y], z1,
|
1761
|
+
vert[i+2][X], vert[i+2][Y], z2);
|
1762
|
+
} else {
|
1763
|
+
g.bezierVertex(vert[i+0][X], vert[i+0][Y],
|
1764
|
+
vert[i+1][X], vert[i+1][Y],
|
1765
|
+
vert[i+2][X], vert[i+2][Y]);
|
1766
|
+
}
|
1767
|
+
} else if (code[i] == CURVE_VERTEX) {
|
1768
|
+
float z = vert[i][Z];
|
1769
|
+
if (z == 0) {
|
1770
|
+
g.curveVertex(vert[i][X], vert[i][Y]);
|
1771
|
+
} else {
|
1772
|
+
g.curveVertex(vert[i][X], vert[i][Y], z);
|
1773
|
+
}
|
1774
|
+
}
|
1775
|
+
}
|
1776
|
+
}
|
1777
|
+
g.endShape();
|
1778
|
+
}
|
1779
|
+
*/
|
1780
|
+
|
1781
|
+
protected void drawPath(PGraphics g) {
|
1782
|
+
// Paths might be empty (go figure)
|
1783
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=982
|
1784
|
+
if (vertices == null) return;
|
1785
|
+
|
1786
|
+
boolean insideContour = false;
|
1787
|
+
g.beginShape();
|
1788
|
+
|
1789
|
+
if (vertexCodeCount == 0) { // each point is a simple vertex
|
1790
|
+
if (vertices[0].length == 2) { // drawing 2D vertices
|
1791
|
+
for (int i = 0; i < vertexCount; i++) {
|
1792
|
+
g.vertex(vertices[i][X], vertices[i][Y]);
|
1793
|
+
}
|
1794
|
+
} else { // drawing 3D vertices
|
1795
|
+
for (int i = 0; i < vertexCount; i++) {
|
1796
|
+
g.vertex(vertices[i][X], vertices[i][Y], vertices[i][Z]);
|
1797
|
+
}
|
1798
|
+
}
|
1799
|
+
|
1800
|
+
} else { // coded set of vertices
|
1801
|
+
int index = 0;
|
1802
|
+
|
1803
|
+
if (vertices[0].length == 2) { // drawing a 2D path
|
1804
|
+
for (int j = 0; j < vertexCodeCount; j++) {
|
1805
|
+
switch (vertexCodes[j]) {
|
1806
|
+
|
1807
|
+
case VERTEX:
|
1808
|
+
g.vertex(vertices[index][X], vertices[index][Y]);
|
1809
|
+
index++;
|
1810
|
+
break;
|
1811
|
+
|
1812
|
+
case QUADRATIC_VERTEX:
|
1813
|
+
g.quadraticVertex(vertices[index+0][X], vertices[index+0][Y],
|
1814
|
+
vertices[index+1][X], vertices[index+1][Y]);
|
1815
|
+
index += 2;
|
1816
|
+
break;
|
1817
|
+
|
1818
|
+
case BEZIER_VERTEX:
|
1819
|
+
g.bezierVertex(vertices[index+0][X], vertices[index+0][Y],
|
1820
|
+
vertices[index+1][X], vertices[index+1][Y],
|
1821
|
+
vertices[index+2][X], vertices[index+2][Y]);
|
1822
|
+
index += 3;
|
1823
|
+
break;
|
1824
|
+
|
1825
|
+
case CURVE_VERTEX:
|
1826
|
+
g.curveVertex(vertices[index][X], vertices[index][Y]);
|
1827
|
+
index++;
|
1828
|
+
break;
|
1829
|
+
|
1830
|
+
case BREAK:
|
1831
|
+
if (insideContour) {
|
1832
|
+
g.endContour();
|
1833
|
+
}
|
1834
|
+
g.beginContour();
|
1835
|
+
insideContour = true;
|
1836
|
+
}
|
1837
|
+
}
|
1838
|
+
} else { // drawing a 3D path
|
1839
|
+
for (int j = 0; j < vertexCodeCount; j++) {
|
1840
|
+
switch (vertexCodes[j]) {
|
1841
|
+
|
1842
|
+
case VERTEX:
|
1843
|
+
g.vertex(vertices[index][X], vertices[index][Y], vertices[index][Z]);
|
1844
|
+
index++;
|
1845
|
+
break;
|
1846
|
+
|
1847
|
+
case QUADRATIC_VERTEX:
|
1848
|
+
g.quadraticVertex(vertices[index+0][X], vertices[index+0][Y], vertices[index+0][Z],
|
1849
|
+
vertices[index+1][X], vertices[index+1][Y], vertices[index+0][Z]);
|
1850
|
+
index += 2;
|
1851
|
+
break;
|
1852
|
+
|
1853
|
+
|
1854
|
+
case BEZIER_VERTEX:
|
1855
|
+
g.bezierVertex(vertices[index+0][X], vertices[index+0][Y], vertices[index+0][Z],
|
1856
|
+
vertices[index+1][X], vertices[index+1][Y], vertices[index+1][Z],
|
1857
|
+
vertices[index+2][X], vertices[index+2][Y], vertices[index+2][Z]);
|
1858
|
+
index += 3;
|
1859
|
+
break;
|
1860
|
+
|
1861
|
+
case CURVE_VERTEX:
|
1862
|
+
g.curveVertex(vertices[index][X], vertices[index][Y], vertices[index][Z]);
|
1863
|
+
index++;
|
1864
|
+
break;
|
1865
|
+
|
1866
|
+
case BREAK:
|
1867
|
+
if (insideContour) {
|
1868
|
+
g.endContour();
|
1869
|
+
}
|
1870
|
+
g.beginContour();
|
1871
|
+
insideContour = true;
|
1872
|
+
}
|
1873
|
+
}
|
1874
|
+
}
|
1875
|
+
}
|
1876
|
+
if (insideContour) {
|
1877
|
+
g.endContour();
|
1878
|
+
}
|
1879
|
+
g.endShape(close ? CLOSE : OPEN);
|
1880
|
+
}
|
1881
|
+
|
1882
|
+
|
1883
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
1884
|
+
|
1885
|
+
|
1886
|
+
public PShape getParent() {
|
1887
|
+
return parent;
|
1888
|
+
}
|
1889
|
+
|
1890
|
+
/**
|
1891
|
+
* @webref
|
1892
|
+
* @brief Returns the number of children
|
1893
|
+
*/
|
1894
|
+
public int getChildCount() {
|
1895
|
+
return childCount;
|
1896
|
+
}
|
1897
|
+
|
1898
|
+
|
1899
|
+
/** Resize the children[] array to be in line with childCount */
|
1900
|
+
protected void crop() {
|
1901
|
+
// https://github.com/processing/processing/issues/3347
|
1902
|
+
if (children.length != childCount) {
|
1903
|
+
children = (PShape[]) PApplet.subset(children, 0, childCount);
|
1904
|
+
}
|
1905
|
+
}
|
1906
|
+
|
1907
|
+
|
1908
|
+
public PShape[] getChildren() {
|
1909
|
+
crop();
|
1910
|
+
return children;
|
1911
|
+
}
|
1912
|
+
|
1913
|
+
/**
|
1914
|
+
* ( begin auto-generated from PShape_getChild.xml )
|
1915
|
+
*
|
1916
|
+
* Extracts a child shape from a parent shape. Specify the name of the
|
1917
|
+
* shape with the <b>target</b> parameter. The shape is returned as a
|
1918
|
+
* <b>PShape</b> object, or <b>null</b> is returned if there is an error.
|
1919
|
+
*
|
1920
|
+
* ( end auto-generated )
|
1921
|
+
* @webref pshape:method
|
1922
|
+
* @usage web_application
|
1923
|
+
* @brief Returns a child element of a shape as a PShape object
|
1924
|
+
* @param index the layer position of the shape to get
|
1925
|
+
* @see PShape#addChild(PShape)
|
1926
|
+
*/
|
1927
|
+
public PShape getChild(int index) {
|
1928
|
+
crop();
|
1929
|
+
return children[index];
|
1930
|
+
}
|
1931
|
+
|
1932
|
+
/**
|
1933
|
+
* @param target the name of the shape to get
|
1934
|
+
*/
|
1935
|
+
public PShape getChild(String target) {
|
1936
|
+
if (name != null && name.equals(target)) {
|
1937
|
+
return this;
|
1938
|
+
}
|
1939
|
+
if (nameTable != null) {
|
1940
|
+
PShape found = nameTable.get(target);
|
1941
|
+
if (found != null) return found;
|
1942
|
+
}
|
1943
|
+
for (int i = 0; i < childCount; i++) {
|
1944
|
+
PShape found = children[i].getChild(target);
|
1945
|
+
if (found != null) return found;
|
1946
|
+
}
|
1947
|
+
return null;
|
1948
|
+
}
|
1949
|
+
|
1950
|
+
|
1951
|
+
/**
|
1952
|
+
* Same as getChild(name), except that it first walks all the way up the
|
1953
|
+
* hierarchy to the eldest grandparent, so that children can be found anywhere.
|
1954
|
+
*/
|
1955
|
+
public PShape findChild(String target) {
|
1956
|
+
if (parent == null) {
|
1957
|
+
return getChild(target);
|
1958
|
+
|
1959
|
+
} else {
|
1960
|
+
return parent.findChild(target);
|
1961
|
+
}
|
1962
|
+
}
|
1963
|
+
|
1964
|
+
|
1965
|
+
// can't be just 'add' because that suggests additive geometry
|
1966
|
+
/**
|
1967
|
+
* @webref pshape:method
|
1968
|
+
* @brief Adds a new child
|
1969
|
+
* @param who any variable of type PShape
|
1970
|
+
* @see PShape#getChild(int)
|
1971
|
+
*/
|
1972
|
+
public void addChild(PShape who) {
|
1973
|
+
if (children == null) {
|
1974
|
+
children = new PShape[1];
|
1975
|
+
}
|
1976
|
+
if (childCount == children.length) {
|
1977
|
+
children = (PShape[]) PApplet.expand(children);
|
1978
|
+
}
|
1979
|
+
children[childCount++] = who;
|
1980
|
+
who.parent = this;
|
1981
|
+
|
1982
|
+
if (who.getName() != null) {
|
1983
|
+
addName(who.getName(), who);
|
1984
|
+
}
|
1985
|
+
}
|
1986
|
+
|
1987
|
+
|
1988
|
+
// adds child who exactly at position idx in the array of children.
|
1989
|
+
/**
|
1990
|
+
* @param idx the layer position in which to insert the new child
|
1991
|
+
*/
|
1992
|
+
public void addChild(PShape who, int idx) {
|
1993
|
+
if (idx < childCount) {
|
1994
|
+
if (childCount == children.length) {
|
1995
|
+
children = (PShape[]) PApplet.expand(children);
|
1996
|
+
}
|
1997
|
+
|
1998
|
+
// Copy [idx, childCount - 1] to [idx + 1, childCount]
|
1999
|
+
for (int i = childCount - 1; i >= idx; i--) {
|
2000
|
+
children[i + 1] = children[i];
|
2001
|
+
}
|
2002
|
+
childCount++;
|
2003
|
+
|
2004
|
+
children[idx] = who;
|
2005
|
+
|
2006
|
+
who.parent = this;
|
2007
|
+
|
2008
|
+
if (who.getName() != null) {
|
2009
|
+
addName(who.getName(), who);
|
2010
|
+
}
|
2011
|
+
}
|
2012
|
+
}
|
2013
|
+
|
2014
|
+
|
2015
|
+
/**
|
2016
|
+
* Remove the child shape with index idx.
|
2017
|
+
*/
|
2018
|
+
public void removeChild(int idx) {
|
2019
|
+
if (idx < childCount) {
|
2020
|
+
PShape child = children[idx];
|
2021
|
+
|
2022
|
+
// Copy [idx + 1, childCount - 1] to [idx, childCount - 2]
|
2023
|
+
for (int i = idx; i < childCount - 1; i++) {
|
2024
|
+
children[i] = children[i + 1];
|
2025
|
+
}
|
2026
|
+
childCount--;
|
2027
|
+
|
2028
|
+
if (child.getName() != null && nameTable != null) {
|
2029
|
+
nameTable.remove(child.getName());
|
2030
|
+
}
|
2031
|
+
}
|
2032
|
+
}
|
2033
|
+
|
2034
|
+
|
2035
|
+
/**
|
2036
|
+
* Add a shape to the name lookup table.
|
2037
|
+
*/
|
2038
|
+
public void addName(String nom, PShape shape) {
|
2039
|
+
if (parent != null) {
|
2040
|
+
parent.addName(nom, shape);
|
2041
|
+
} else {
|
2042
|
+
if (nameTable == null) {
|
2043
|
+
nameTable = new HashMap<String,PShape>();
|
2044
|
+
}
|
2045
|
+
nameTable.put(nom, shape);
|
2046
|
+
}
|
2047
|
+
}
|
2048
|
+
|
2049
|
+
|
2050
|
+
/**
|
2051
|
+
* Returns the index of child who.
|
2052
|
+
*/
|
2053
|
+
public int getChildIndex(PShape who) {
|
2054
|
+
for (int i = 0; i < childCount; i++) {
|
2055
|
+
if (children[i] == who) {
|
2056
|
+
return i;
|
2057
|
+
}
|
2058
|
+
}
|
2059
|
+
return -1;
|
2060
|
+
}
|
2061
|
+
|
2062
|
+
|
2063
|
+
public PShape getTessellation() {
|
2064
|
+
return null;
|
2065
|
+
}
|
2066
|
+
|
2067
|
+
|
2068
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
2069
|
+
|
2070
|
+
|
2071
|
+
/** The shape type, one of GROUP, PRIMITIVE, PATH, or GEOMETRY. */
|
2072
|
+
public int getFamily() {
|
2073
|
+
return family;
|
2074
|
+
}
|
2075
|
+
|
2076
|
+
|
2077
|
+
public int getKind() {
|
2078
|
+
return kind;
|
2079
|
+
}
|
2080
|
+
|
2081
|
+
|
2082
|
+
public float[] getParams() {
|
2083
|
+
return getParams(null);
|
2084
|
+
}
|
2085
|
+
|
2086
|
+
|
2087
|
+
public float[] getParams(float[] target) {
|
2088
|
+
if (target == null || target.length != params.length) {
|
2089
|
+
target = new float[params.length];
|
2090
|
+
}
|
2091
|
+
PApplet.arrayCopy(params, target);
|
2092
|
+
return target;
|
2093
|
+
}
|
2094
|
+
|
2095
|
+
|
2096
|
+
public float getParam(int index) {
|
2097
|
+
return params[index];
|
2098
|
+
}
|
2099
|
+
|
2100
|
+
|
2101
|
+
protected void setParams(float[] source) {
|
2102
|
+
if (params == null) {
|
2103
|
+
params = new float[source.length];
|
2104
|
+
}
|
2105
|
+
if (source.length != params.length) {
|
2106
|
+
PGraphics.showWarning("Wrong number of parameters");
|
2107
|
+
return;
|
2108
|
+
}
|
2109
|
+
PApplet.arrayCopy(source, params);
|
2110
|
+
}
|
2111
|
+
|
2112
|
+
|
2113
|
+
public void setPath(int vcount, float[][] verts) {
|
2114
|
+
setPath(vcount, verts, 0, null);
|
2115
|
+
}
|
2116
|
+
|
2117
|
+
|
2118
|
+
protected void setPath(int vcount, float[][] verts, int ccount, int[] codes) {
|
2119
|
+
if (verts == null || verts.length < vcount) return;
|
2120
|
+
if (0 < ccount && (codes == null || codes.length < ccount)) return;
|
2121
|
+
|
2122
|
+
int ndim = verts[0].length;
|
2123
|
+
vertexCount = vcount;
|
2124
|
+
vertices = new float[vertexCount][ndim];
|
2125
|
+
for (int i = 0; i < vertexCount; i++) {
|
2126
|
+
PApplet.arrayCopy(verts[i], vertices[i]);
|
2127
|
+
}
|
2128
|
+
|
2129
|
+
vertexCodeCount = ccount;
|
2130
|
+
if (0 < vertexCodeCount) {
|
2131
|
+
vertexCodes = new int[vertexCodeCount];
|
2132
|
+
PApplet.arrayCopy(codes, vertexCodes, vertexCodeCount);
|
2133
|
+
}
|
2134
|
+
}
|
2135
|
+
|
2136
|
+
/**
|
2137
|
+
* @webref pshape:method
|
2138
|
+
* @brief Returns the total number of vertices as an int
|
2139
|
+
* @see PShape#getVertex(int)
|
2140
|
+
* @see PShape#setVertex(int, float, float)
|
2141
|
+
*/
|
2142
|
+
public int getVertexCount() {
|
2143
|
+
if (family == GROUP || family == PRIMITIVE) {
|
2144
|
+
PGraphics.showWarning(NO_VERTICES_ERROR);
|
2145
|
+
}
|
2146
|
+
return vertexCount;
|
2147
|
+
}
|
2148
|
+
|
2149
|
+
|
2150
|
+
/**
|
2151
|
+
* @webref pshape:method
|
2152
|
+
* @brief Returns the vertex at the index position
|
2153
|
+
* @param index the location of the vertex
|
2154
|
+
* @see PShape#setVertex(int, float, float)
|
2155
|
+
* @see PShape#getVertexCount()
|
2156
|
+
*/
|
2157
|
+
public PVector getVertex(int index) {
|
2158
|
+
return getVertex(index, null);
|
2159
|
+
}
|
2160
|
+
|
2161
|
+
|
2162
|
+
/**
|
2163
|
+
* @param vec PVector to assign the data to
|
2164
|
+
*/
|
2165
|
+
public PVector getVertex(int index, PVector vec) {
|
2166
|
+
if (vec == null) {
|
2167
|
+
vec = new PVector();
|
2168
|
+
}
|
2169
|
+
float[] vert = vertices[index];
|
2170
|
+
vec.x = vert[X];
|
2171
|
+
vec.y = vert[Y];
|
2172
|
+
if (vert.length > 2) {
|
2173
|
+
vec.z = vert[Z];
|
2174
|
+
} else {
|
2175
|
+
vec.z = 0; // in case this isn't a new vector
|
2176
|
+
}
|
2177
|
+
return vec;
|
2178
|
+
}
|
2179
|
+
|
2180
|
+
|
2181
|
+
public float getVertexX(int index) {
|
2182
|
+
return vertices[index][X];
|
2183
|
+
}
|
2184
|
+
|
2185
|
+
|
2186
|
+
public float getVertexY(int index) {
|
2187
|
+
return vertices[index][Y];
|
2188
|
+
}
|
2189
|
+
|
2190
|
+
|
2191
|
+
public float getVertexZ(int index) {
|
2192
|
+
return vertices[index][Z];
|
2193
|
+
}
|
2194
|
+
|
2195
|
+
|
2196
|
+
/**
|
2197
|
+
* @webref pshape:method
|
2198
|
+
* @brief Sets the vertex at the index position
|
2199
|
+
* @param index the location of the vertex
|
2200
|
+
* @param x the x value for the vertex
|
2201
|
+
* @param y the y value for the vertex
|
2202
|
+
* @see PShape#getVertex(int)
|
2203
|
+
* @see PShape#getVertexCount()
|
2204
|
+
*/
|
2205
|
+
public void setVertex(int index, float x, float y) {
|
2206
|
+
if (openShape) {
|
2207
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setVertex()");
|
2208
|
+
return;
|
2209
|
+
}
|
2210
|
+
|
2211
|
+
vertices[index][X] = x;
|
2212
|
+
vertices[index][Y] = y;
|
2213
|
+
}
|
2214
|
+
|
2215
|
+
|
2216
|
+
/**
|
2217
|
+
* @param z the z value for the vertex
|
2218
|
+
*/
|
2219
|
+
public void setVertex(int index, float x, float y, float z) {
|
2220
|
+
if (openShape) {
|
2221
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setVertex()");
|
2222
|
+
return;
|
2223
|
+
}
|
2224
|
+
|
2225
|
+
vertices[index][X] = x;
|
2226
|
+
vertices[index][Y] = y;
|
2227
|
+
vertices[index][Z] = z;
|
2228
|
+
}
|
2229
|
+
|
2230
|
+
|
2231
|
+
/**
|
2232
|
+
* @param vec the PVector to define the x, y, z coordinates
|
2233
|
+
*/
|
2234
|
+
public void setVertex(int index, PVector vec) {
|
2235
|
+
if (openShape) {
|
2236
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setVertex()");
|
2237
|
+
return;
|
2238
|
+
}
|
2239
|
+
|
2240
|
+
vertices[index][X] = vec.x;
|
2241
|
+
vertices[index][Y] = vec.y;
|
2242
|
+
|
2243
|
+
if (vertices[index].length > 2) {
|
2244
|
+
vertices[index][Z] = vec.z;
|
2245
|
+
} else if (vec.z != 0 && vec.z == vec.z) {
|
2246
|
+
throw new IllegalArgumentException("Cannot set a z-coordinate on a 2D shape");
|
2247
|
+
}
|
2248
|
+
}
|
2249
|
+
|
2250
|
+
|
2251
|
+
public PVector getNormal(int index) {
|
2252
|
+
return getNormal(index, null);
|
2253
|
+
}
|
2254
|
+
|
2255
|
+
|
2256
|
+
public PVector getNormal(int index, PVector vec) {
|
2257
|
+
if (vec == null) {
|
2258
|
+
vec = new PVector();
|
2259
|
+
}
|
2260
|
+
vec.x = vertices[index][PGraphics.NX];
|
2261
|
+
vec.y = vertices[index][PGraphics.NY];
|
2262
|
+
vec.z = vertices[index][PGraphics.NZ];
|
2263
|
+
return vec;
|
2264
|
+
}
|
2265
|
+
|
2266
|
+
|
2267
|
+
public float getNormalX(int index) {
|
2268
|
+
return vertices[index][PGraphics.NX];
|
2269
|
+
}
|
2270
|
+
|
2271
|
+
|
2272
|
+
public float getNormalY(int index) {
|
2273
|
+
return vertices[index][PGraphics.NY];
|
2274
|
+
}
|
2275
|
+
|
2276
|
+
|
2277
|
+
public float getNormalZ(int index) {
|
2278
|
+
return vertices[index][PGraphics.NZ];
|
2279
|
+
}
|
2280
|
+
|
2281
|
+
|
2282
|
+
public void setNormal(int index, float nx, float ny, float nz) {
|
2283
|
+
if (openShape) {
|
2284
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setNormal()");
|
2285
|
+
return;
|
2286
|
+
}
|
2287
|
+
|
2288
|
+
vertices[index][PGraphics.NX] = nx;
|
2289
|
+
vertices[index][PGraphics.NY] = ny;
|
2290
|
+
vertices[index][PGraphics.NZ] = nz;
|
2291
|
+
}
|
2292
|
+
|
2293
|
+
|
2294
|
+
|
2295
|
+
public void setAttrib(String name, int index, float... values) {
|
2296
|
+
}
|
2297
|
+
|
2298
|
+
|
2299
|
+
public void setAttrib(String name, int index, int... values) {
|
2300
|
+
}
|
2301
|
+
|
2302
|
+
|
2303
|
+
public void setAttrib(String name, int index, boolean... values) {
|
2304
|
+
}
|
2305
|
+
|
2306
|
+
|
2307
|
+
public float getTextureU(int index) {
|
2308
|
+
return vertices[index][PGraphics.U];
|
2309
|
+
}
|
2310
|
+
|
2311
|
+
|
2312
|
+
public float getTextureV(int index) {
|
2313
|
+
return vertices[index][PGraphics.V];
|
2314
|
+
}
|
2315
|
+
|
2316
|
+
|
2317
|
+
public void setTextureUV(int index, float u, float v) {
|
2318
|
+
if (openShape) {
|
2319
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTextureUV()");
|
2320
|
+
return;
|
2321
|
+
}
|
2322
|
+
|
2323
|
+
// make sure we allocated the vertices array and that vertex exists
|
2324
|
+
if (vertices == null ||
|
2325
|
+
index >= vertices.length) {
|
2326
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setTextureUV()");
|
2327
|
+
return;
|
2328
|
+
}
|
2329
|
+
|
2330
|
+
|
2331
|
+
vertices[index][PGraphics.U] = u;
|
2332
|
+
vertices[index][PGraphics.V] = v;
|
2333
|
+
}
|
2334
|
+
|
2335
|
+
|
2336
|
+
public void setTextureMode(int mode) {
|
2337
|
+
if (openShape) {
|
2338
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTextureMode()");
|
2339
|
+
return;
|
2340
|
+
}
|
2341
|
+
|
2342
|
+
textureMode = mode;
|
2343
|
+
}
|
2344
|
+
|
2345
|
+
|
2346
|
+
public void setTexture(PImage tex) {
|
2347
|
+
if (openShape) {
|
2348
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTexture()");
|
2349
|
+
return;
|
2350
|
+
}
|
2351
|
+
|
2352
|
+
image = tex;
|
2353
|
+
}
|
2354
|
+
|
2355
|
+
|
2356
|
+
public int getFill(int index) {
|
2357
|
+
// make sure we allocated the vertices array and that vertex exists
|
2358
|
+
if (vertices == null ||
|
2359
|
+
index >= vertices.length) {
|
2360
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getFill()");
|
2361
|
+
return fillColor;
|
2362
|
+
}
|
2363
|
+
|
2364
|
+
if (image == null) {
|
2365
|
+
int a = (int) (vertices[index][PGraphics.A] * 255);
|
2366
|
+
int r = (int) (vertices[index][PGraphics.R] * 255);
|
2367
|
+
int g = (int) (vertices[index][PGraphics.G] * 255);
|
2368
|
+
int b = (int) (vertices[index][PGraphics.B] * 255);
|
2369
|
+
return (a << 24) | (r << 16) | (g << 8) | b;
|
2370
|
+
} else {
|
2371
|
+
return 0;
|
2372
|
+
}
|
2373
|
+
}
|
2374
|
+
|
2375
|
+
/**
|
2376
|
+
* @nowebref
|
2377
|
+
*/
|
2378
|
+
public void setFill(boolean fill) {
|
2379
|
+
if (openShape) {
|
2380
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setFill()");
|
2381
|
+
return;
|
2382
|
+
}
|
2383
|
+
|
2384
|
+
this.fill = fill;
|
2385
|
+
}
|
2386
|
+
|
2387
|
+
/**
|
2388
|
+
* ( begin auto-generated from PShape_setFill.xml )
|
2389
|
+
*
|
2390
|
+
* The <b>setFill()</b> method defines the fill color of a <b>PShape</b>.
|
2391
|
+
* This method is used after shapes are created or when a shape is defined explicitly
|
2392
|
+
* (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in the above example.
|
2393
|
+
* When a shape is created with <b>beginShape()</b> and <b>endShape()</b>, its
|
2394
|
+
* attributes may be changed with <b>fill()</b> and <b>stroke()</b> within
|
2395
|
+
* <b>beginShape()</b> and <b>endShape()</b>. However, after the shape is
|
2396
|
+
* created, only the <b>setFill()</b> method can define a new fill value for
|
2397
|
+
* the <b>PShape</b>.
|
2398
|
+
*
|
2399
|
+
* ( end auto-generated )
|
2400
|
+
*
|
2401
|
+
* @webref
|
2402
|
+
* @param fill
|
2403
|
+
* @brief Set the fill value
|
2404
|
+
*/
|
2405
|
+
public void setFill(int fill) {
|
2406
|
+
if (openShape) {
|
2407
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setFill()");
|
2408
|
+
return;
|
2409
|
+
}
|
2410
|
+
|
2411
|
+
this.fillColor = fill;
|
2412
|
+
|
2413
|
+
if (vertices != null && perVertexStyles) {
|
2414
|
+
for (int i = 0; i < vertexCount; i++) {
|
2415
|
+
setFill(i, fill);
|
2416
|
+
}
|
2417
|
+
}
|
2418
|
+
}
|
2419
|
+
|
2420
|
+
/**
|
2421
|
+
* @nowebref
|
2422
|
+
*/
|
2423
|
+
public void setFill(int index, int fill) {
|
2424
|
+
if (openShape) {
|
2425
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setFill()");
|
2426
|
+
return;
|
2427
|
+
}
|
2428
|
+
|
2429
|
+
if (!perVertexStyles) {
|
2430
|
+
PGraphics.showWarning(PER_VERTEX_UNSUPPORTED, "setFill()");
|
2431
|
+
return;
|
2432
|
+
}
|
2433
|
+
|
2434
|
+
// make sure we allocated the vertices array and that vertex exists
|
2435
|
+
if (vertices == null || index >= vertices.length) {
|
2436
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getFill()");
|
2437
|
+
return;
|
2438
|
+
}
|
2439
|
+
|
2440
|
+
if (image == null) {
|
2441
|
+
vertices[index][PGraphics.A] = ((fill >> 24) & 0xFF) / 255.0f;
|
2442
|
+
vertices[index][PGraphics.R] = ((fill >> 16) & 0xFF) / 255.0f;
|
2443
|
+
vertices[index][PGraphics.G] = ((fill >> 8) & 0xFF) / 255.0f;
|
2444
|
+
vertices[index][PGraphics.B] = ((fill >> 0) & 0xFF) / 255.0f;
|
2445
|
+
}
|
2446
|
+
}
|
2447
|
+
|
2448
|
+
|
2449
|
+
public int getTint(int index) {
|
2450
|
+
// make sure we allocated the vertices array and that vertex exists
|
2451
|
+
if (vertices == null || index >= vertices.length) {
|
2452
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getTint()");
|
2453
|
+
return this.tintColor;
|
2454
|
+
}
|
2455
|
+
|
2456
|
+
if (image != null) {
|
2457
|
+
int a = (int) (vertices[index][PGraphics.A] * 255);
|
2458
|
+
int r = (int) (vertices[index][PGraphics.R] * 255);
|
2459
|
+
int g = (int) (vertices[index][PGraphics.G] * 255);
|
2460
|
+
int b = (int) (vertices[index][PGraphics.B] * 255);
|
2461
|
+
return (a << 24) | (r << 16) | (g << 8) | b;
|
2462
|
+
} else {
|
2463
|
+
return 0;
|
2464
|
+
}
|
2465
|
+
}
|
2466
|
+
|
2467
|
+
|
2468
|
+
public void setTint(boolean tint) {
|
2469
|
+
if (openShape) {
|
2470
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTint()");
|
2471
|
+
return;
|
2472
|
+
}
|
2473
|
+
|
2474
|
+
this.tint = tint;
|
2475
|
+
}
|
2476
|
+
|
2477
|
+
|
2478
|
+
public void setTint(int fill) {
|
2479
|
+
if (openShape) {
|
2480
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTint()");
|
2481
|
+
return;
|
2482
|
+
}
|
2483
|
+
|
2484
|
+
tintColor = fill;
|
2485
|
+
|
2486
|
+
if (vertices != null) {
|
2487
|
+
for (int i = 0; i < vertices.length; i++) {
|
2488
|
+
setFill(i, fill);
|
2489
|
+
}
|
2490
|
+
}
|
2491
|
+
}
|
2492
|
+
|
2493
|
+
|
2494
|
+
public void setTint(int index, int tint) {
|
2495
|
+
if (openShape) {
|
2496
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setTint()");
|
2497
|
+
return;
|
2498
|
+
}
|
2499
|
+
|
2500
|
+
// make sure we allocated the vertices array and that vertex exists
|
2501
|
+
if (vertices == null ||
|
2502
|
+
index >= vertices.length) {
|
2503
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setTint()");
|
2504
|
+
return;
|
2505
|
+
}
|
2506
|
+
|
2507
|
+
if (image != null) {
|
2508
|
+
vertices[index][PGraphics.A] = ((tint >> 24) & 0xFF) / 255.0f;
|
2509
|
+
vertices[index][PGraphics.R] = ((tint >> 16) & 0xFF) / 255.0f;
|
2510
|
+
vertices[index][PGraphics.G] = ((tint >> 8) & 0xFF) / 255.0f;
|
2511
|
+
vertices[index][PGraphics.B] = ((tint >> 0) & 0xFF) / 255.0f;
|
2512
|
+
}
|
2513
|
+
}
|
2514
|
+
|
2515
|
+
|
2516
|
+
public int getStroke(int index) {
|
2517
|
+
// make sure we allocated the vertices array and that vertex exists
|
2518
|
+
if (vertices == null ||
|
2519
|
+
index >= vertices.length) {
|
2520
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getStroke()");
|
2521
|
+
return strokeColor;
|
2522
|
+
}
|
2523
|
+
|
2524
|
+
int a = (int) (vertices[index][PGraphics.SA] * 255);
|
2525
|
+
int r = (int) (vertices[index][PGraphics.SR] * 255);
|
2526
|
+
int g = (int) (vertices[index][PGraphics.SG] * 255);
|
2527
|
+
int b = (int) (vertices[index][PGraphics.SB] * 255);
|
2528
|
+
return (a << 24) | (r << 16) | (g << 8) | b;
|
2529
|
+
}
|
2530
|
+
|
2531
|
+
/**
|
2532
|
+
* @nowebref
|
2533
|
+
*/
|
2534
|
+
public void setStroke(boolean stroke) {
|
2535
|
+
if (openShape) {
|
2536
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStroke()");
|
2537
|
+
return;
|
2538
|
+
}
|
2539
|
+
|
2540
|
+
this.stroke = stroke;
|
2541
|
+
}
|
2542
|
+
|
2543
|
+
/**
|
2544
|
+
* ( begin auto-generated from PShape_setStroke.xml )
|
2545
|
+
*
|
2546
|
+
* The <b>setStroke()</b> method defines the outline color of a <b>PShape</b>.
|
2547
|
+
* This method is used after shapes are created or when a shape is defined
|
2548
|
+
* explicitly (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in
|
2549
|
+
* the above example. When a shape is created with <b>beginShape()</b> and
|
2550
|
+
* <b>endShape()</b>, its attributes may be changed with <b>fill()</b> and
|
2551
|
+
* <b>stroke()</b> within <b>beginShape()</b> and <b>endShape()</b>.
|
2552
|
+
* However, after the shape is created, only the <b>setStroke()</b> method
|
2553
|
+
* can define a new stroke value for the <b>PShape</b>.
|
2554
|
+
*
|
2555
|
+
* ( end auto-generated )
|
2556
|
+
*
|
2557
|
+
* @webref
|
2558
|
+
* @param stroke
|
2559
|
+
* @brief Set the stroke value
|
2560
|
+
*/
|
2561
|
+
public void setStroke(int stroke) {
|
2562
|
+
if (openShape) {
|
2563
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStroke()");
|
2564
|
+
return;
|
2565
|
+
}
|
2566
|
+
|
2567
|
+
strokeColor = stroke;
|
2568
|
+
|
2569
|
+
if (vertices != null && perVertexStyles) {
|
2570
|
+
for (int i = 0; i < vertices.length; i++) {
|
2571
|
+
setStroke(i, stroke);
|
2572
|
+
}
|
2573
|
+
}
|
2574
|
+
}
|
2575
|
+
|
2576
|
+
/**
|
2577
|
+
* @nowebref
|
2578
|
+
*/
|
2579
|
+
public void setStroke(int index, int stroke) {
|
2580
|
+
if (openShape) {
|
2581
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStroke()");
|
2582
|
+
return;
|
2583
|
+
}
|
2584
|
+
|
2585
|
+
if (!perVertexStyles) {
|
2586
|
+
PGraphics.showWarning(PER_VERTEX_UNSUPPORTED, "setStroke()");
|
2587
|
+
return;
|
2588
|
+
}
|
2589
|
+
|
2590
|
+
// make sure we allocated the vertices array and that vertex exists
|
2591
|
+
if (vertices == null || index >= vertices.length) {
|
2592
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setStroke()");
|
2593
|
+
return;
|
2594
|
+
}
|
2595
|
+
|
2596
|
+
vertices[index][PGraphics.SA] = ((stroke >> 24) & 0xFF) / 255.0f;
|
2597
|
+
vertices[index][PGraphics.SR] = ((stroke >> 16) & 0xFF) / 255.0f;
|
2598
|
+
vertices[index][PGraphics.SG] = ((stroke >> 8) & 0xFF) / 255.0f;
|
2599
|
+
vertices[index][PGraphics.SB] = ((stroke >> 0) & 0xFF) / 255.0f;
|
2600
|
+
}
|
2601
|
+
|
2602
|
+
|
2603
|
+
public float getStrokeWeight(int index) {
|
2604
|
+
// make sure we allocated the vertices array and that vertex exists
|
2605
|
+
if (vertices == null || index >= vertices.length) {
|
2606
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getStrokeWeight()");
|
2607
|
+
return strokeWeight;
|
2608
|
+
}
|
2609
|
+
|
2610
|
+
return vertices[index][PGraphics.SW];
|
2611
|
+
}
|
2612
|
+
|
2613
|
+
|
2614
|
+
public void setStrokeWeight(float weight) {
|
2615
|
+
if (openShape) {
|
2616
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeWeight()");
|
2617
|
+
return;
|
2618
|
+
}
|
2619
|
+
|
2620
|
+
strokeWeight = weight;
|
2621
|
+
|
2622
|
+
if (vertices != null && perVertexStyles) {
|
2623
|
+
for (int i = 0; i < vertexCount; i++) {
|
2624
|
+
setStrokeWeight(i, weight);
|
2625
|
+
}
|
2626
|
+
}
|
2627
|
+
}
|
2628
|
+
|
2629
|
+
|
2630
|
+
public void setStrokeWeight(int index, float weight) {
|
2631
|
+
if (openShape) {
|
2632
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeWeight()");
|
2633
|
+
return;
|
2634
|
+
}
|
2635
|
+
|
2636
|
+
if (!perVertexStyles) {
|
2637
|
+
PGraphics.showWarning(PER_VERTEX_UNSUPPORTED, "setStrokeWeight()");
|
2638
|
+
return;
|
2639
|
+
}
|
2640
|
+
|
2641
|
+
// make sure we allocated the vertices array and that vertex exists
|
2642
|
+
if (vertices == null || index >= vertices.length) {
|
2643
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setStrokeWeight()");
|
2644
|
+
return;
|
2645
|
+
}
|
2646
|
+
|
2647
|
+
vertices[index][PGraphics.SW] = weight;
|
2648
|
+
}
|
2649
|
+
|
2650
|
+
|
2651
|
+
public void setStrokeJoin(int join) {
|
2652
|
+
if (openShape) {
|
2653
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeJoin()");
|
2654
|
+
return;
|
2655
|
+
}
|
2656
|
+
|
2657
|
+
strokeJoin = join;
|
2658
|
+
}
|
2659
|
+
|
2660
|
+
|
2661
|
+
public void setStrokeCap(int cap) {
|
2662
|
+
if (openShape) {
|
2663
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setStrokeCap()");
|
2664
|
+
return;
|
2665
|
+
}
|
2666
|
+
|
2667
|
+
strokeCap = cap;
|
2668
|
+
}
|
2669
|
+
|
2670
|
+
|
2671
|
+
public int getAmbient(int index) {
|
2672
|
+
// make sure we allocated the vertices array and that vertex exists
|
2673
|
+
if (vertices == null || index >= vertices.length) {
|
2674
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getAmbient()");
|
2675
|
+
return ambientColor;
|
2676
|
+
}
|
2677
|
+
|
2678
|
+
int r = (int) (vertices[index][PGraphics.AR] * 255);
|
2679
|
+
int g = (int) (vertices[index][PGraphics.AG] * 255);
|
2680
|
+
int b = (int) (vertices[index][PGraphics.AB] * 255);
|
2681
|
+
return 0xff000000 | (r << 16) | (g << 8) | b;
|
2682
|
+
}
|
2683
|
+
|
2684
|
+
|
2685
|
+
public void setAmbient(int ambient) {
|
2686
|
+
if (openShape) {
|
2687
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setAmbient()");
|
2688
|
+
return;
|
2689
|
+
}
|
2690
|
+
|
2691
|
+
ambientColor = ambient;
|
2692
|
+
|
2693
|
+
if (vertices != null) {
|
2694
|
+
for (int i = 0; i < vertices.length; i++) {
|
2695
|
+
setAmbient(i, ambient);
|
2696
|
+
}
|
2697
|
+
}
|
2698
|
+
}
|
2699
|
+
|
2700
|
+
|
2701
|
+
public void setAmbient(int index, int ambient) {
|
2702
|
+
if (openShape) {
|
2703
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setAmbient()");
|
2704
|
+
return;
|
2705
|
+
}
|
2706
|
+
|
2707
|
+
// make sure we allocated the vertices array and that vertex exists
|
2708
|
+
if (vertices == null || index >= vertices.length) {
|
2709
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setAmbient()");
|
2710
|
+
return;
|
2711
|
+
}
|
2712
|
+
|
2713
|
+
vertices[index][PGraphics.AR] = ((ambient >> 16) & 0xFF) / 255.0f;
|
2714
|
+
vertices[index][PGraphics.AG] = ((ambient >> 8) & 0xFF) / 255.0f;
|
2715
|
+
vertices[index][PGraphics.AB] = ((ambient >> 0) & 0xFF) / 255.0f;
|
2716
|
+
}
|
2717
|
+
|
2718
|
+
|
2719
|
+
public int getSpecular(int index) {
|
2720
|
+
// make sure we allocated the vertices array and that vertex exists
|
2721
|
+
if (vertices == null || index >= vertices.length) {
|
2722
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getSpecular()");
|
2723
|
+
return specularColor;
|
2724
|
+
}
|
2725
|
+
|
2726
|
+
int r = (int) (vertices[index][PGraphics.SPR] * 255);
|
2727
|
+
int g = (int) (vertices[index][PGraphics.SPG] * 255);
|
2728
|
+
int b = (int) (vertices[index][PGraphics.SPB] * 255);
|
2729
|
+
return 0xff000000 | (r << 16) | (g << 8) | b;
|
2730
|
+
}
|
2731
|
+
|
2732
|
+
|
2733
|
+
public void setSpecular(int specular) {
|
2734
|
+
if (openShape) {
|
2735
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setSpecular()");
|
2736
|
+
return;
|
2737
|
+
}
|
2738
|
+
|
2739
|
+
specularColor = specular;
|
2740
|
+
|
2741
|
+
if (vertices != null) {
|
2742
|
+
for (int i = 0; i < vertices.length; i++) {
|
2743
|
+
setSpecular(i, specular);
|
2744
|
+
}
|
2745
|
+
}
|
2746
|
+
}
|
2747
|
+
|
2748
|
+
|
2749
|
+
public void setSpecular(int index, int specular) {
|
2750
|
+
if (openShape) {
|
2751
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setSpecular()");
|
2752
|
+
return;
|
2753
|
+
}
|
2754
|
+
|
2755
|
+
// make sure we allocated the vertices array and that vertex exists
|
2756
|
+
if (vertices == null || index >= vertices.length) {
|
2757
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setSpecular()");
|
2758
|
+
return;
|
2759
|
+
}
|
2760
|
+
|
2761
|
+
vertices[index][PGraphics.SPR] = ((specular >> 16) & 0xFF) / 255.0f;
|
2762
|
+
vertices[index][PGraphics.SPG] = ((specular >> 8) & 0xFF) / 255.0f;
|
2763
|
+
vertices[index][PGraphics.SPB] = ((specular >> 0) & 0xFF) / 255.0f;
|
2764
|
+
}
|
2765
|
+
|
2766
|
+
|
2767
|
+
public int getEmissive(int index) {
|
2768
|
+
// make sure we allocated the vertices array and that vertex exists
|
2769
|
+
if (vertices == null || index >= vertices.length) {
|
2770
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getEmissive()");
|
2771
|
+
return emissiveColor;
|
2772
|
+
}
|
2773
|
+
|
2774
|
+
int r = (int) (vertices[index][PGraphics.ER] * 255);
|
2775
|
+
int g = (int) (vertices[index][PGraphics.EG] * 255);
|
2776
|
+
int b = (int) (vertices[index][PGraphics.EB] * 255);
|
2777
|
+
return 0xff000000 | (r << 16) | (g << 8) | b;
|
2778
|
+
}
|
2779
|
+
|
2780
|
+
|
2781
|
+
public void setEmissive(int emissive) {
|
2782
|
+
if (openShape) {
|
2783
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setEmissive()");
|
2784
|
+
return;
|
2785
|
+
}
|
2786
|
+
|
2787
|
+
emissiveColor = emissive;
|
2788
|
+
|
2789
|
+
if (vertices != null) {
|
2790
|
+
for (int i = 0; i < vertices.length; i++) {
|
2791
|
+
setEmissive(i, emissive);
|
2792
|
+
}
|
2793
|
+
}
|
2794
|
+
}
|
2795
|
+
|
2796
|
+
|
2797
|
+
public void setEmissive(int index, int emissive) {
|
2798
|
+
if (openShape) {
|
2799
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setEmissive()");
|
2800
|
+
return;
|
2801
|
+
}
|
2802
|
+
|
2803
|
+
// make sure we allocated the vertices array and that vertex exists
|
2804
|
+
if (vertices == null ||
|
2805
|
+
index >= vertices.length) {
|
2806
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setEmissive()");
|
2807
|
+
return;
|
2808
|
+
}
|
2809
|
+
|
2810
|
+
vertices[index][PGraphics.ER] = ((emissive >> 16) & 0xFF) / 255.0f;
|
2811
|
+
vertices[index][PGraphics.EG] = ((emissive >> 8) & 0xFF) / 255.0f;
|
2812
|
+
vertices[index][PGraphics.EB] = ((emissive >> 0) & 0xFF) / 255.0f;
|
2813
|
+
}
|
2814
|
+
|
2815
|
+
|
2816
|
+
public float getShininess(int index) {
|
2817
|
+
// make sure we allocated the vertices array and that vertex exists
|
2818
|
+
if (vertices == null ||
|
2819
|
+
index >= vertices.length) {
|
2820
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "getShininess()");
|
2821
|
+
return shininess;
|
2822
|
+
}
|
2823
|
+
|
2824
|
+
return vertices[index][PGraphics.SHINE];
|
2825
|
+
}
|
2826
|
+
|
2827
|
+
|
2828
|
+
public void setShininess(float shine) {
|
2829
|
+
if (openShape) {
|
2830
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setShininess()");
|
2831
|
+
return;
|
2832
|
+
}
|
2833
|
+
|
2834
|
+
shininess = shine;
|
2835
|
+
|
2836
|
+
if (vertices != null) {
|
2837
|
+
for (int i = 0; i < vertices.length; i++) {
|
2838
|
+
setShininess(i, shine);
|
2839
|
+
}
|
2840
|
+
}
|
2841
|
+
}
|
2842
|
+
|
2843
|
+
|
2844
|
+
public void setShininess(int index, float shine) {
|
2845
|
+
if (openShape) {
|
2846
|
+
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setShininess()");
|
2847
|
+
return;
|
2848
|
+
}
|
2849
|
+
|
2850
|
+
// make sure we allocated the vertices array and that vertex exists
|
2851
|
+
if (vertices == null ||
|
2852
|
+
index >= vertices.length) {
|
2853
|
+
PGraphics.showWarning(NO_SUCH_VERTEX_ERROR + " (" + index + ")", "setShininess()");
|
2854
|
+
return;
|
2855
|
+
}
|
2856
|
+
|
2857
|
+
|
2858
|
+
vertices[index][PGraphics.SHINE] = shine;
|
2859
|
+
}
|
2860
|
+
|
2861
|
+
|
2862
|
+
public int[] getVertexCodes() {
|
2863
|
+
if (vertexCodes == null) {
|
2864
|
+
return null;
|
2865
|
+
}
|
2866
|
+
if (vertexCodes.length != vertexCodeCount) {
|
2867
|
+
vertexCodes = PApplet.subset(vertexCodes, 0, vertexCodeCount);
|
2868
|
+
}
|
2869
|
+
return vertexCodes;
|
2870
|
+
}
|
2871
|
+
|
2872
|
+
|
2873
|
+
public int getVertexCodeCount() {
|
2874
|
+
return vertexCodeCount;
|
2875
|
+
}
|
2876
|
+
|
2877
|
+
|
2878
|
+
/**
|
2879
|
+
* One of VERTEX, BEZIER_VERTEX, CURVE_VERTEX, or BREAK.
|
2880
|
+
*/
|
2881
|
+
public int getVertexCode(int index) {
|
2882
|
+
return vertexCodes[index];
|
2883
|
+
}
|
2884
|
+
|
2885
|
+
|
2886
|
+
public boolean isClosed() {
|
2887
|
+
return close;
|
2888
|
+
}
|
2889
|
+
|
2890
|
+
|
2891
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
2892
|
+
|
2893
|
+
|
2894
|
+
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
2895
|
+
public boolean contains(float x, float y) {
|
2896
|
+
if (family == PATH) {
|
2897
|
+
boolean c = false;
|
2898
|
+
for (int i = 0, j = vertexCount-1; i < vertexCount; j = i++) {
|
2899
|
+
if (((vertices[i][Y] > y) != (vertices[j][Y] > y)) &&
|
2900
|
+
(x <
|
2901
|
+
(vertices[j][X]-vertices[i][X]) *
|
2902
|
+
(y-vertices[i][Y]) /
|
2903
|
+
(vertices[j][1]-vertices[i][Y]) +
|
2904
|
+
vertices[i][X])) {
|
2905
|
+
c = !c;
|
2906
|
+
}
|
2907
|
+
}
|
2908
|
+
return c;
|
2909
|
+
} else {
|
2910
|
+
throw new IllegalArgumentException("The contains() method is only implemented for paths.");
|
2911
|
+
}
|
2912
|
+
}
|
2913
|
+
|
2914
|
+
|
2915
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
2916
|
+
|
2917
|
+
|
2918
|
+
// translate, rotate, scale, apply (no push/pop)
|
2919
|
+
// these each call matrix.translate, etc
|
2920
|
+
// if matrix is null when one is called,
|
2921
|
+
// it is created and set to identity
|
2922
|
+
|
2923
|
+
|
2924
|
+
/**
|
2925
|
+
* ( begin auto-generated from PShape_translate.xml )
|
2926
|
+
*
|
2927
|
+
* Specifies an amount to displace the shape. The <b>x</b> parameter
|
2928
|
+
* specifies left/right translation, the <b>y</b> parameter specifies
|
2929
|
+
* up/down translation, and the <b>z</b> parameter specifies translations
|
2930
|
+
* toward/away from the screen. Subsequent calls to the method accumulates
|
2931
|
+
* the effect. For example, calling <b>translate(50, 0)</b> and then
|
2932
|
+
* <b>translate(20, 0)</b> is the same as <b>translate(70, 0)</b>. This
|
2933
|
+
* transformation is applied directly to the shape, it's not refreshed each
|
2934
|
+
* time <b>draw()</b> is run.
|
2935
|
+
* <br /><br />
|
2936
|
+
* Using this method with the <b>z</b> parameter requires using the P3D
|
2937
|
+
* parameter in combination with size.
|
2938
|
+
*
|
2939
|
+
* ( end auto-generated )
|
2940
|
+
* @webref pshape:method
|
2941
|
+
* @usage web_application
|
2942
|
+
* @brief Displaces the shape
|
2943
|
+
* @param x left/right translation
|
2944
|
+
* @param y up/down translation
|
2945
|
+
* @see PShape#rotate(float)
|
2946
|
+
* @see PShape#scale(float)
|
2947
|
+
* @see PShape#resetMatrix()
|
2948
|
+
*/
|
2949
|
+
public void translate(float x, float y) {
|
2950
|
+
checkMatrix(2);
|
2951
|
+
matrix.translate(x, y);
|
2952
|
+
}
|
2953
|
+
|
2954
|
+
/**
|
2955
|
+
* @param z forward/back translation
|
2956
|
+
*/
|
2957
|
+
public void translate(float x, float y, float z) {
|
2958
|
+
checkMatrix(3);
|
2959
|
+
matrix.translate(x, y, z);
|
2960
|
+
}
|
2961
|
+
|
2962
|
+
/**
|
2963
|
+
* ( begin auto-generated from PShape_rotateX.xml )
|
2964
|
+
*
|
2965
|
+
* Rotates a shape around the x-axis the amount specified by the
|
2966
|
+
* <b>angle</b> parameter. Angles should be specified in radians (values
|
2967
|
+
* from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
|
2968
|
+
* <br /><br />
|
2969
|
+
* Shapes are always rotated around the upper-left corner of their bounding
|
2970
|
+
* box. Positive numbers rotate objects in a clockwise direction.
|
2971
|
+
* Subsequent calls to the method accumulates the effect. For example,
|
2972
|
+
* calling <b>rotateX(HALF_PI)</b> and then <b>rotateX(HALF_PI)</b> is the
|
2973
|
+
* same as <b>rotateX(PI)</b>. This transformation is applied directly to
|
2974
|
+
* the shape, it's not refreshed each time <b>draw()</b> is run.
|
2975
|
+
* <br /><br />
|
2976
|
+
* This method requires a 3D renderer. You need to use P3D as a third
|
2977
|
+
* parameter for the <b>size()</b> function as shown in the example above.
|
2978
|
+
*
|
2979
|
+
* ( end auto-generated )
|
2980
|
+
* @webref pshape:method
|
2981
|
+
* @usage web_application
|
2982
|
+
* @brief Rotates the shape around the x-axis
|
2983
|
+
* @param angle angle of rotation specified in radians
|
2984
|
+
* @see PShape#rotate(float)
|
2985
|
+
* @see PShape#rotateY(float)
|
2986
|
+
* @see PShape#rotateZ(float)
|
2987
|
+
* @see PShape#scale(float)
|
2988
|
+
* @see PShape#translate(float, float)
|
2989
|
+
* @see PShape#resetMatrix()
|
2990
|
+
*/
|
2991
|
+
public void rotateX(float angle) {
|
2992
|
+
rotate(angle, 1, 0, 0);
|
2993
|
+
}
|
2994
|
+
|
2995
|
+
/**
|
2996
|
+
* ( begin auto-generated from PShape_rotateY.xml )
|
2997
|
+
*
|
2998
|
+
* Rotates a shape around the y-axis the amount specified by the
|
2999
|
+
* <b>angle</b> parameter. Angles should be specified in radians (values
|
3000
|
+
* from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
|
3001
|
+
* <br /><br />
|
3002
|
+
* Shapes are always rotated around the upper-left corner of their bounding
|
3003
|
+
* box. Positive numbers rotate objects in a clockwise direction.
|
3004
|
+
* Subsequent calls to the method accumulates the effect. For example,
|
3005
|
+
* calling <b>rotateY(HALF_PI)</b> and then <b>rotateY(HALF_PI)</b> is the
|
3006
|
+
* same as <b>rotateY(PI)</b>. This transformation is applied directly to
|
3007
|
+
* the shape, it's not refreshed each time <b>draw()</b> is run.
|
3008
|
+
* <br /><br />
|
3009
|
+
* This method requires a 3D renderer. You need to use P3D as a third
|
3010
|
+
* parameter for the <b>size()</b> function as shown in the example above.
|
3011
|
+
*
|
3012
|
+
* ( end auto-generated )
|
3013
|
+
*
|
3014
|
+
* @webref pshape:method
|
3015
|
+
* @usage web_application
|
3016
|
+
* @brief Rotates the shape around the y-axis
|
3017
|
+
* @param angle angle of rotation specified in radians
|
3018
|
+
* @see PShape#rotate(float)
|
3019
|
+
* @see PShape#rotateX(float)
|
3020
|
+
* @see PShape#rotateZ(float)
|
3021
|
+
* @see PShape#scale(float)
|
3022
|
+
* @see PShape#translate(float, float)
|
3023
|
+
* @see PShape#resetMatrix()
|
3024
|
+
*/
|
3025
|
+
public void rotateY(float angle) {
|
3026
|
+
rotate(angle, 0, 1, 0);
|
3027
|
+
}
|
3028
|
+
|
3029
|
+
|
3030
|
+
/**
|
3031
|
+
* ( begin auto-generated from PShape_rotateZ.xml )
|
3032
|
+
*
|
3033
|
+
* Rotates a shape around the z-axis the amount specified by the
|
3034
|
+
* <b>angle</b> parameter. Angles should be specified in radians (values
|
3035
|
+
* from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
|
3036
|
+
* <br /><br />
|
3037
|
+
* Shapes are always rotated around the upper-left corner of their bounding
|
3038
|
+
* box. Positive numbers rotate objects in a clockwise direction.
|
3039
|
+
* Subsequent calls to the method accumulates the effect. For example,
|
3040
|
+
* calling <b>rotateZ(HALF_PI)</b> and then <b>rotateZ(HALF_PI)</b> is the
|
3041
|
+
* same as <b>rotateZ(PI)</b>. This transformation is applied directly to
|
3042
|
+
* the shape, it's not refreshed each time <b>draw()</b> is run.
|
3043
|
+
* <br /><br />
|
3044
|
+
* This method requires a 3D renderer. You need to use P3D as a third
|
3045
|
+
* parameter for the <b>size()</b> function as shown in the example above.
|
3046
|
+
*
|
3047
|
+
* ( end auto-generated )
|
3048
|
+
* @webref pshape:method
|
3049
|
+
* @usage web_application
|
3050
|
+
* @brief Rotates the shape around the z-axis
|
3051
|
+
* @param angle angle of rotation specified in radians
|
3052
|
+
* @see PShape#rotate(float)
|
3053
|
+
* @see PShape#rotateX(float)
|
3054
|
+
* @see PShape#rotateY(float)
|
3055
|
+
* @see PShape#scale(float)
|
3056
|
+
* @see PShape#translate(float, float)
|
3057
|
+
* @see PShape#resetMatrix()
|
3058
|
+
*/
|
3059
|
+
public void rotateZ(float angle) {
|
3060
|
+
rotate(angle, 0, 0, 1);
|
3061
|
+
}
|
3062
|
+
|
3063
|
+
/**
|
3064
|
+
* ( begin auto-generated from PShape_rotate.xml )
|
3065
|
+
*
|
3066
|
+
* Rotates a shape the amount specified by the <b>angle</b> parameter.
|
3067
|
+
* Angles should be specified in radians (values from 0 to TWO_PI) or
|
3068
|
+
* converted to radians with the <b>radians()</b> method.
|
3069
|
+
* <br /><br />
|
3070
|
+
* Shapes are always rotated around the upper-left corner of their bounding
|
3071
|
+
* box. Positive numbers rotate objects in a clockwise direction.
|
3072
|
+
* Transformations apply to everything that happens after and subsequent
|
3073
|
+
* calls to the method accumulates the effect. For example, calling
|
3074
|
+
* <b>rotate(HALF_PI)</b> and then <b>rotate(HALF_PI)</b> is the same as
|
3075
|
+
* <b>rotate(PI)</b>. This transformation is applied directly to the shape,
|
3076
|
+
* it's not refreshed each time <b>draw()</b> is run.
|
3077
|
+
*
|
3078
|
+
* ( end auto-generated )
|
3079
|
+
* @webref pshape:method
|
3080
|
+
* @usage web_application
|
3081
|
+
* @brief Rotates the shape
|
3082
|
+
* @param angle angle of rotation specified in radians
|
3083
|
+
* @see PShape#rotateX(float)
|
3084
|
+
* @see PShape#rotateY(float)
|
3085
|
+
* @see PShape#rotateZ(float)
|
3086
|
+
* @see PShape#scale(float)
|
3087
|
+
* @see PShape#translate(float, float)
|
3088
|
+
* @see PShape#resetMatrix()
|
3089
|
+
*/
|
3090
|
+
public void rotate(float angle) {
|
3091
|
+
checkMatrix(2); // at least 2...
|
3092
|
+
matrix.rotate(angle);
|
3093
|
+
}
|
3094
|
+
|
3095
|
+
/**
|
3096
|
+
* @nowebref
|
3097
|
+
*/
|
3098
|
+
public void rotate(float angle, float v0, float v1, float v2) {
|
3099
|
+
checkMatrix(3);
|
3100
|
+
float norm2 = v0 * v0 + v1 * v1 + v2 * v2;
|
3101
|
+
if (Math.abs(norm2 - 1) > EPSILON) {
|
3102
|
+
// The rotation vector is not normalized.
|
3103
|
+
float norm = PApplet.sqrt(norm2);
|
3104
|
+
v0 /= norm;
|
3105
|
+
v1 /= norm;
|
3106
|
+
v2 /= norm;
|
3107
|
+
}
|
3108
|
+
matrix.rotate(angle, v0, v1, v2);
|
3109
|
+
}
|
3110
|
+
|
3111
|
+
|
3112
|
+
//
|
3113
|
+
|
3114
|
+
/**
|
3115
|
+
* ( begin auto-generated from PShape_scale.xml )
|
3116
|
+
*
|
3117
|
+
* Increases or decreases the size of a shape by expanding and contracting
|
3118
|
+
* vertices. Shapes always scale from the relative origin of their bounding
|
3119
|
+
* box. Scale values are specified as decimal percentages. For example, the
|
3120
|
+
* method call <b>scale(2.0)</b> increases the dimension of a shape by
|
3121
|
+
* 200%. Subsequent calls to the method multiply the effect. For example,
|
3122
|
+
* calling <b>scale(2.0)</b> and then <b>scale(1.5)</b> is the same as
|
3123
|
+
* <b>scale(3.0)</b>. This transformation is applied directly to the shape,
|
3124
|
+
* it's not refreshed each time <b>draw()</b> is run.
|
3125
|
+
* <br /><br />
|
3126
|
+
* Using this method with the <b>z</b> parameter requires using the P3D
|
3127
|
+
* parameter in combination with size.
|
3128
|
+
*
|
3129
|
+
* ( end auto-generated )
|
3130
|
+
* @webref pshape:method
|
3131
|
+
* @usage web_application
|
3132
|
+
* @brief Increases and decreases the size of a shape
|
3133
|
+
* @param s percentate to scale the object
|
3134
|
+
* @see PShape#rotate(float)
|
3135
|
+
* @see PShape#translate(float, float)
|
3136
|
+
* @see PShape#resetMatrix()
|
3137
|
+
*/
|
3138
|
+
public void scale(float s) {
|
3139
|
+
checkMatrix(2); // at least 2...
|
3140
|
+
matrix.scale(s);
|
3141
|
+
}
|
3142
|
+
|
3143
|
+
|
3144
|
+
public void scale(float x, float y) {
|
3145
|
+
checkMatrix(2);
|
3146
|
+
matrix.scale(x, y);
|
3147
|
+
}
|
3148
|
+
|
3149
|
+
/**
|
3150
|
+
* @param x percentage to scale the object in the x-axis
|
3151
|
+
* @param y percentage to scale the object in the y-axis
|
3152
|
+
* @param z percentage to scale the object in the z-axis
|
3153
|
+
*/
|
3154
|
+
public void scale(float x, float y, float z) {
|
3155
|
+
checkMatrix(3);
|
3156
|
+
matrix.scale(x, y, z);
|
3157
|
+
}
|
3158
|
+
|
3159
|
+
|
3160
|
+
//
|
3161
|
+
|
3162
|
+
/**
|
3163
|
+
* ( begin auto-generated from PShape_resetMatrix.xml )
|
3164
|
+
*
|
3165
|
+
* Replaces the current matrix of a shape with the identity matrix. The
|
3166
|
+
* equivalent function in OpenGL is glLoadIdentity().
|
3167
|
+
*
|
3168
|
+
* ( end auto-generated )
|
3169
|
+
* @webref pshape:method
|
3170
|
+
* @brief Replaces the current matrix of a shape with the identity matrix
|
3171
|
+
* @usage web_application
|
3172
|
+
* @see PShape#rotate(float)
|
3173
|
+
* @see PShape#scale(float)
|
3174
|
+
* @see PShape#translate(float, float)
|
3175
|
+
*/
|
3176
|
+
public void resetMatrix() {
|
3177
|
+
checkMatrix(2);
|
3178
|
+
matrix.reset();
|
3179
|
+
}
|
3180
|
+
|
3181
|
+
|
3182
|
+
public void applyMatrix(PMatrix source) {
|
3183
|
+
if (source instanceof PMatrix2D) {
|
3184
|
+
applyMatrix((PMatrix2D) source);
|
3185
|
+
} else if (source instanceof PMatrix3D) {
|
3186
|
+
applyMatrix((PMatrix3D) source);
|
3187
|
+
}
|
3188
|
+
}
|
3189
|
+
|
3190
|
+
|
3191
|
+
public void applyMatrix(PMatrix2D source) {
|
3192
|
+
applyMatrix(source.m00, source.m01, 0, source.m02,
|
3193
|
+
source.m10, source.m11, 0, source.m12,
|
3194
|
+
0, 0, 1, 0,
|
3195
|
+
0, 0, 0, 1);
|
3196
|
+
}
|
3197
|
+
|
3198
|
+
|
3199
|
+
public void applyMatrix(float n00, float n01, float n02,
|
3200
|
+
float n10, float n11, float n12) {
|
3201
|
+
checkMatrix(2);
|
3202
|
+
matrix.apply(n00, n01, n02,
|
3203
|
+
n10, n11, n12);
|
3204
|
+
}
|
3205
|
+
|
3206
|
+
|
3207
|
+
public void applyMatrix(PMatrix3D source) {
|
3208
|
+
applyMatrix(source.m00, source.m01, source.m02, source.m03,
|
3209
|
+
source.m10, source.m11, source.m12, source.m13,
|
3210
|
+
source.m20, source.m21, source.m22, source.m23,
|
3211
|
+
source.m30, source.m31, source.m32, source.m33);
|
3212
|
+
}
|
3213
|
+
|
3214
|
+
|
3215
|
+
public void applyMatrix(float n00, float n01, float n02, float n03,
|
3216
|
+
float n10, float n11, float n12, float n13,
|
3217
|
+
float n20, float n21, float n22, float n23,
|
3218
|
+
float n30, float n31, float n32, float n33) {
|
3219
|
+
checkMatrix(3);
|
3220
|
+
matrix.apply(n00, n01, n02, n03,
|
3221
|
+
n10, n11, n12, n13,
|
3222
|
+
n20, n21, n22, n23,
|
3223
|
+
n30, n31, n32, n33);
|
3224
|
+
}
|
3225
|
+
|
3226
|
+
|
3227
|
+
//
|
3228
|
+
|
3229
|
+
|
3230
|
+
/**
|
3231
|
+
* Make sure that the shape's matrix is 1) not null, and 2) has a matrix
|
3232
|
+
* that can handle <em>at least</em> the specified number of dimensions.
|
3233
|
+
*/
|
3234
|
+
protected void checkMatrix(int dimensions) {
|
3235
|
+
if (matrix == null) {
|
3236
|
+
if (dimensions == 2) {
|
3237
|
+
matrix = new PMatrix2D();
|
3238
|
+
} else {
|
3239
|
+
matrix = new PMatrix3D();
|
3240
|
+
}
|
3241
|
+
} else if (dimensions == 3 && (matrix instanceof PMatrix2D)) {
|
3242
|
+
// time for an upgrayedd for a double dose of my pimpin'
|
3243
|
+
matrix = new PMatrix3D(matrix);
|
3244
|
+
}
|
3245
|
+
}
|
3246
|
+
|
3247
|
+
|
3248
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
3249
|
+
|
3250
|
+
|
3251
|
+
/**
|
3252
|
+
* Center the shape based on its bounding box. Can't assume
|
3253
|
+
* that the bounding box is 0, 0, width, height. Common case will be
|
3254
|
+
* opening a letter size document in Illustrator, and drawing something
|
3255
|
+
* in the middle, then reading it in as an svg file.
|
3256
|
+
* This will also need to flip the y axis (scale(1, -1)) in cases
|
3257
|
+
* like Adobe Illustrator where the coordinates start at the bottom.
|
3258
|
+
*/
|
3259
|
+
// public void center() {
|
3260
|
+
// }
|
3261
|
+
|
3262
|
+
|
3263
|
+
/**
|
3264
|
+
* Set the pivot point for all transformations.
|
3265
|
+
*/
|
3266
|
+
// public void pivot(float x, float y) {
|
3267
|
+
// px = x;
|
3268
|
+
// py = y;
|
3269
|
+
// }
|
3270
|
+
|
3271
|
+
|
3272
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
3273
|
+
|
3274
|
+
|
3275
|
+
public void colorMode(int mode) {
|
3276
|
+
colorMode(mode, colorModeX, colorModeY, colorModeZ, colorModeA);
|
3277
|
+
}
|
3278
|
+
|
3279
|
+
/**
|
3280
|
+
* @param max range for all color elements
|
3281
|
+
*/
|
3282
|
+
public void colorMode(int mode, float max) {
|
3283
|
+
colorMode(mode, max, max, max, max);
|
3284
|
+
}
|
3285
|
+
|
3286
|
+
|
3287
|
+
/**
|
3288
|
+
* @param maxX range for the red or hue depending on the current color mode
|
3289
|
+
* @param maxY range for the green or saturation depending on the current color mode
|
3290
|
+
* @param maxZ range for the blue or brightness depending on the current color mode
|
3291
|
+
*/
|
3292
|
+
public void colorMode(int mode, float maxX, float maxY, float maxZ) {
|
3293
|
+
colorMode(mode, maxX, maxY, maxZ, colorModeA);
|
3294
|
+
}
|
3295
|
+
|
3296
|
+
/**
|
3297
|
+
* @param maxA range for the alpha
|
3298
|
+
*/
|
3299
|
+
public void colorMode(int mode,
|
3300
|
+
float maxX, float maxY, float maxZ, float maxA) {
|
3301
|
+
colorMode = mode;
|
3302
|
+
|
3303
|
+
colorModeX = maxX; // still needs to be set for hsb
|
3304
|
+
colorModeY = maxY;
|
3305
|
+
colorModeZ = maxZ;
|
3306
|
+
colorModeA = maxA;
|
3307
|
+
|
3308
|
+
// if color max values are all 1, then no need to scale
|
3309
|
+
colorModeScale =
|
3310
|
+
((maxA != 1) || (maxX != maxY) || (maxY != maxZ) || (maxZ != maxA));
|
3311
|
+
|
3312
|
+
// if color is rgb/0..255 this will make it easier for the
|
3313
|
+
// red() green() etc functions
|
3314
|
+
colorModeDefault = (colorMode == RGB) &&
|
3315
|
+
(colorModeA == 255) && (colorModeX == 255) &&
|
3316
|
+
(colorModeY == 255) && (colorModeZ == 255);
|
3317
|
+
}
|
3318
|
+
|
3319
|
+
|
3320
|
+
protected void colorCalc(int rgb) {
|
3321
|
+
if (((rgb & 0xff000000) == 0) && (rgb <= colorModeX)) {
|
3322
|
+
colorCalc((float) rgb);
|
3323
|
+
|
3324
|
+
} else {
|
3325
|
+
colorCalcARGB(rgb, colorModeA);
|
3326
|
+
}
|
3327
|
+
}
|
3328
|
+
|
3329
|
+
|
3330
|
+
protected void colorCalc(int rgb, float alpha) {
|
3331
|
+
if (((rgb & 0xff000000) == 0) && (rgb <= colorModeX)) { // see above
|
3332
|
+
colorCalc((float) rgb, alpha);
|
3333
|
+
|
3334
|
+
} else {
|
3335
|
+
colorCalcARGB(rgb, alpha);
|
3336
|
+
}
|
3337
|
+
}
|
3338
|
+
|
3339
|
+
|
3340
|
+
protected void colorCalc(float gray) {
|
3341
|
+
colorCalc(gray, colorModeA);
|
3342
|
+
}
|
3343
|
+
|
3344
|
+
|
3345
|
+
protected void colorCalc(float gray, float alpha) {
|
3346
|
+
if (gray > colorModeX) gray = colorModeX;
|
3347
|
+
if (alpha > colorModeA) alpha = colorModeA;
|
3348
|
+
|
3349
|
+
if (gray < 0) gray = 0;
|
3350
|
+
if (alpha < 0) alpha = 0;
|
3351
|
+
|
3352
|
+
calcR = colorModeScale ? (gray / colorModeX) : gray;
|
3353
|
+
calcG = calcR;
|
3354
|
+
calcB = calcR;
|
3355
|
+
calcA = colorModeScale ? (alpha / colorModeA) : alpha;
|
3356
|
+
|
3357
|
+
calcRi = (int)(calcR*255); calcGi = (int)(calcG*255);
|
3358
|
+
calcBi = (int)(calcB*255); calcAi = (int)(calcA*255);
|
3359
|
+
calcColor = (calcAi << 24) | (calcRi << 16) | (calcGi << 8) | calcBi;
|
3360
|
+
calcAlpha = (calcAi != 255);
|
3361
|
+
}
|
3362
|
+
|
3363
|
+
|
3364
|
+
protected void colorCalc(float x, float y, float z) {
|
3365
|
+
colorCalc(x, y, z, colorModeA);
|
3366
|
+
}
|
3367
|
+
|
3368
|
+
|
3369
|
+
protected void colorCalc(float x, float y, float z, float a) {
|
3370
|
+
if (x > colorModeX) x = colorModeX;
|
3371
|
+
if (y > colorModeY) y = colorModeY;
|
3372
|
+
if (z > colorModeZ) z = colorModeZ;
|
3373
|
+
if (a > colorModeA) a = colorModeA;
|
3374
|
+
|
3375
|
+
if (x < 0) x = 0;
|
3376
|
+
if (y < 0) y = 0;
|
3377
|
+
if (z < 0) z = 0;
|
3378
|
+
if (a < 0) a = 0;
|
3379
|
+
|
3380
|
+
switch (colorMode) {
|
3381
|
+
case RGB:
|
3382
|
+
if (colorModeScale) {
|
3383
|
+
calcR = x / colorModeX;
|
3384
|
+
calcG = y / colorModeY;
|
3385
|
+
calcB = z / colorModeZ;
|
3386
|
+
calcA = a / colorModeA;
|
3387
|
+
} else {
|
3388
|
+
calcR = x; calcG = y; calcB = z; calcA = a;
|
3389
|
+
}
|
3390
|
+
break;
|
3391
|
+
|
3392
|
+
case HSB:
|
3393
|
+
x /= colorModeX; // h
|
3394
|
+
y /= colorModeY; // s
|
3395
|
+
z /= colorModeZ; // b
|
3396
|
+
|
3397
|
+
calcA = colorModeScale ? (a/colorModeA) : a;
|
3398
|
+
|
3399
|
+
if (y == 0) { // saturation == 0
|
3400
|
+
calcR = calcG = calcB = z;
|
3401
|
+
|
3402
|
+
} else {
|
3403
|
+
float which = (x - (int)x) * 6.0f;
|
3404
|
+
float f = which - (int)which;
|
3405
|
+
float p = z * (1.0f - y);
|
3406
|
+
float q = z * (1.0f - y * f);
|
3407
|
+
float t = z * (1.0f - (y * (1.0f - f)));
|
3408
|
+
|
3409
|
+
switch ((int)which) {
|
3410
|
+
case 0: calcR = z; calcG = t; calcB = p; break;
|
3411
|
+
case 1: calcR = q; calcG = z; calcB = p; break;
|
3412
|
+
case 2: calcR = p; calcG = z; calcB = t; break;
|
3413
|
+
case 3: calcR = p; calcG = q; calcB = z; break;
|
3414
|
+
case 4: calcR = t; calcG = p; calcB = z; break;
|
3415
|
+
case 5: calcR = z; calcG = p; calcB = q; break;
|
3416
|
+
}
|
3417
|
+
}
|
3418
|
+
break;
|
3419
|
+
}
|
3420
|
+
calcRi = (int)(255*calcR); calcGi = (int)(255*calcG);
|
3421
|
+
calcBi = (int)(255*calcB); calcAi = (int)(255*calcA);
|
3422
|
+
calcColor = (calcAi << 24) | (calcRi << 16) | (calcGi << 8) | calcBi;
|
3423
|
+
calcAlpha = (calcAi != 255);
|
3424
|
+
}
|
3425
|
+
|
3426
|
+
|
3427
|
+
protected void colorCalcARGB(int argb, float alpha) {
|
3428
|
+
if (alpha == colorModeA) {
|
3429
|
+
calcAi = (argb >> 24) & 0xff;
|
3430
|
+
calcColor = argb;
|
3431
|
+
} else {
|
3432
|
+
calcAi = (int) (((argb >> 24) & 0xff) * (alpha / colorModeA));
|
3433
|
+
calcColor = (calcAi << 24) | (argb & 0xFFFFFF);
|
3434
|
+
}
|
3435
|
+
calcRi = (argb >> 16) & 0xff;
|
3436
|
+
calcGi = (argb >> 8) & 0xff;
|
3437
|
+
calcBi = argb & 0xff;
|
3438
|
+
calcA = calcAi / 255.0f;
|
3439
|
+
calcR = calcRi / 255.0f;
|
3440
|
+
calcG = calcGi / 255.0f;
|
3441
|
+
calcB = calcBi / 255.0f;
|
3442
|
+
calcAlpha = (calcAi != 255);
|
3443
|
+
}
|
3444
|
+
|
3445
|
+
}
|