picrate 0.0.2-java

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