propane 3.4.2-java → 3.5.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +5 -1
  5. data/Gemfile +2 -0
  6. data/README.md +15 -3
  7. data/Rakefile +9 -10
  8. data/bin/propane +3 -1
  9. data/lib/propane.rb +2 -1
  10. data/lib/propane/app.rb +2 -1
  11. data/lib/propane/creators/sketch_class.rb +7 -1
  12. data/lib/propane/creators/sketch_factory.rb +4 -2
  13. data/lib/propane/creators/sketch_writer.rb +1 -0
  14. data/lib/propane/helper_methods.rb +22 -22
  15. data/lib/propane/helpers/numeric.rb +2 -0
  16. data/lib/propane/helpers/version_error.rb +1 -0
  17. data/lib/propane/library.rb +5 -1
  18. data/lib/propane/library_loader.rb +2 -0
  19. data/lib/propane/native_folder.rb +10 -9
  20. data/lib/propane/native_loader.rb +3 -0
  21. data/lib/propane/runner.rb +11 -5
  22. data/lib/propane/version.rb +2 -1
  23. data/library/boids/boids.rb +21 -11
  24. data/library/color_group/color_group.rb +2 -0
  25. data/library/control_panel/control_panel.rb +8 -5
  26. data/library/dxf/dxf.rb +2 -0
  27. data/library/file_chooser/chooser.rb +10 -9
  28. data/library/file_chooser/file_chooser.rb +10 -9
  29. data/library/library_proxy/library_proxy.rb +2 -0
  30. data/library/net/net.rb +2 -0
  31. data/library/simplex_noise/simplex_noise.rb +2 -0
  32. data/library/slider/slider.rb +23 -22
  33. data/library/vector_utils/vector_utils.rb +4 -0
  34. data/library/video_event/video_event.rb +2 -0
  35. data/pom.rb +46 -45
  36. data/pom.xml +4 -4
  37. data/propane.gemspec +8 -7
  38. data/src/main/java/monkstone/ColorUtil.java +1 -3
  39. data/src/main/java/monkstone/MathToolModule.java +1 -1
  40. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  41. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  42. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  43. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  44. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  45. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  46. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  47. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  49. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  50. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  51. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  52. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  53. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  54. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  55. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  56. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  57. data/src/main/java/processing/awt/PGraphicsJava2D.java +788 -283
  58. data/src/main/java/processing/awt/PImageAWT.java +260 -0
  59. data/src/main/java/processing/awt/PShapeJava2D.java +56 -53
  60. data/src/main/java/processing/awt/PSurfaceAWT.java +309 -211
  61. data/src/main/java/processing/awt/ShimAWT.java +580 -0
  62. data/src/main/java/processing/core/PApplet.java +2877 -2098
  63. data/src/main/java/processing/core/PConstants.java +477 -447
  64. data/src/main/java/processing/core/PFont.java +930 -884
  65. data/src/main/java/processing/core/PGraphics.java +337 -309
  66. data/src/main/java/processing/core/PImage.java +1689 -1689
  67. data/src/main/java/processing/core/PMatrix.java +172 -159
  68. data/src/main/java/processing/core/PMatrix2D.java +456 -410
  69. data/src/main/java/processing/core/PMatrix3D.java +755 -735
  70. data/src/main/java/processing/core/PShape.java +2910 -2656
  71. data/src/main/java/processing/core/PShapeOBJ.java +97 -94
  72. data/src/main/java/processing/core/PShapeSVG.java +1656 -1462
  73. data/src/main/java/processing/core/PStyle.java +40 -37
  74. data/src/main/java/processing/core/PSurface.java +134 -97
  75. data/src/main/java/processing/core/PSurfaceNone.java +292 -218
  76. data/src/main/java/processing/core/PVector.java +991 -966
  77. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  78. data/src/main/java/processing/data/DoubleDict.java +756 -710
  79. data/src/main/java/processing/data/DoubleList.java +749 -696
  80. data/src/main/java/processing/data/FloatDict.java +748 -702
  81. data/src/main/java/processing/data/FloatList.java +751 -697
  82. data/src/main/java/processing/data/IntDict.java +720 -673
  83. data/src/main/java/processing/data/IntList.java +699 -633
  84. data/src/main/java/processing/data/JSONArray.java +931 -873
  85. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  86. data/src/main/java/processing/data/JSONTokener.java +351 -341
  87. data/src/main/java/processing/data/LongDict.java +710 -663
  88. data/src/main/java/processing/data/LongList.java +701 -635
  89. data/src/main/java/processing/data/Sort.java +37 -41
  90. data/src/main/java/processing/data/StringDict.java +525 -486
  91. data/src/main/java/processing/data/StringList.java +626 -580
  92. data/src/main/java/processing/data/Table.java +3693 -3513
  93. data/src/main/java/processing/data/TableRow.java +182 -183
  94. data/src/main/java/processing/data/XML.java +954 -880
  95. data/src/main/java/processing/event/Event.java +87 -67
  96. data/src/main/java/processing/event/KeyEvent.java +48 -41
  97. data/src/main/java/processing/event/MouseEvent.java +87 -113
  98. data/src/main/java/processing/event/TouchEvent.java +10 -6
  99. data/src/main/java/processing/javafx/PSurfaceFX.java +26 -0
  100. data/src/main/java/processing/net/Client.java +20 -20
  101. data/src/main/java/processing/net/Server.java +9 -9
  102. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  103. data/src/main/java/processing/opengl/FrameBuffer.java +390 -376
  104. data/src/main/java/processing/opengl/LinePath.java +130 -91
  105. data/src/main/java/processing/opengl/LineStroker.java +593 -582
  106. data/src/main/java/processing/opengl/PGL.java +645 -579
  107. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  108. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  109. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12287 -12030
  110. data/src/main/java/processing/opengl/PJOGL.java +1743 -1672
  111. data/src/main/java/processing/opengl/PShader.java +345 -416
  112. data/src/main/java/processing/opengl/PShapeOpenGL.java +4601 -4543
  113. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1113 -1029
  114. data/src/main/java/processing/opengl/Texture.java +1489 -1401
  115. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  116. data/test/create_test.rb +21 -20
  117. data/test/deglut_spec_test.rb +4 -2
  118. data/test/helper_methods_test.rb +49 -20
  119. data/test/math_tool_test.rb +39 -32
  120. data/test/native_folder.rb +47 -0
  121. data/test/respond_to_test.rb +3 -2
  122. data/test/sketches/key_event.rb +2 -2
  123. data/test/sketches/library/my_library/my_library.rb +3 -0
  124. data/test/test_helper.rb +2 -0
  125. data/test/vecmath_spec_test.rb +35 -22
  126. data/vendors/Rakefile +28 -22
  127. metadata +13 -13
  128. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  129. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  130. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  131. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -0,0 +1,260 @@
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) 2015 The Processing Foundation
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.awt;
24
+
25
+ import java.awt.Graphics2D;
26
+ import java.awt.Image;
27
+ import java.awt.RenderingHints;
28
+ import java.awt.Transparency;
29
+ import java.awt.image.BufferedImage;
30
+ import java.awt.image.DataBuffer;
31
+ import java.awt.image.DataBufferInt;
32
+ import java.awt.image.PixelGrabber;
33
+ import java.awt.image.WritableRaster;
34
+ import java.io.IOException;
35
+
36
+ import processing.core.PImage;
37
+
38
+
39
+ public class PImageAWT extends PImage {
40
+
41
+ /**
42
+ * Construct a new PImage from a java.awt.Image. This constructor assumes
43
+ * that you've done the work of making sure a MediaTracker has been used
44
+ * to fully download the data and that the img is valid.
45
+ *
46
+ * @nowebref
47
+ * @param img assumes a MediaTracker has been used to fully download
48
+ * the data and the img is valid
49
+ */
50
+ public PImageAWT(Image img) {
51
+ format = RGB;
52
+ if (img instanceof BufferedImage) {
53
+ BufferedImage bi = (BufferedImage) img;
54
+ width = bi.getWidth();
55
+ height = bi.getHeight();
56
+ int type = bi.getType();
57
+ if (type == BufferedImage.TYPE_3BYTE_BGR ||
58
+ type == BufferedImage.TYPE_4BYTE_ABGR) {
59
+ pixels = new int[width * height];
60
+ bi.getRGB(0, 0, width, height, pixels, 0, width);
61
+ if (type == BufferedImage.TYPE_4BYTE_ABGR) {
62
+ format = ARGB;
63
+ } else {
64
+ opaque();
65
+ }
66
+ } else {
67
+ DataBuffer db = bi.getRaster().getDataBuffer();
68
+ if (db instanceof DataBufferInt) {
69
+ pixels = ((DataBufferInt) db).getData();
70
+ if (type == BufferedImage.TYPE_INT_ARGB) {
71
+ format = ARGB;
72
+ } else if (type == BufferedImage.TYPE_INT_RGB) {
73
+ opaque();
74
+ }
75
+ }
76
+ }
77
+ }
78
+ // Implements fall-through if not DataBufferInt above, or not a
79
+ // known type, or not DataBufferInt for the data itself.
80
+ if (pixels == null) { // go the old school Java 1.0 route
81
+ width = img.getWidth(null);
82
+ height = img.getHeight(null);
83
+ pixels = new int[width * height];
84
+ PixelGrabber pg =
85
+ new PixelGrabber(img, 0, 0, width, height, pixels, 0, width);
86
+ try {
87
+ pg.grabPixels();
88
+ } catch (InterruptedException e) { }
89
+ }
90
+ pixelDensity = 1;
91
+ pixelWidth = width;
92
+ pixelHeight = height;
93
+ }
94
+
95
+
96
+ /**
97
+ * Use the getNative() method instead, which allows library interfaces to be
98
+ * written in a cross-platform fashion for desktop, Android, and others.
99
+ * This is still included for PGraphics objects, which may need the image.
100
+ */
101
+ public Image getImage() { // ignore
102
+ return (Image) getNative();
103
+ }
104
+
105
+
106
+ /**
107
+ * Returns a native BufferedImage from this PImage.
108
+ */
109
+ @Override
110
+ public Object getNative() { // ignore
111
+ loadPixels();
112
+ int type = (format == RGB) ?
113
+ BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
114
+ BufferedImage image = new BufferedImage(pixelWidth, pixelHeight, type);
115
+ WritableRaster wr = image.getRaster();
116
+ wr.setDataElements(0, 0, pixelWidth, pixelHeight, pixels);
117
+ return image;
118
+ }
119
+
120
+
121
+ @Override
122
+ public void resize(int w, int h) { // ignore
123
+ if (w <= 0 && h <= 0) {
124
+ throw new IllegalArgumentException("width or height must be > 0 for resize");
125
+ }
126
+
127
+ if (w == 0) { // Use height to determine relative size
128
+ float diff = (float) h / (float) height;
129
+ w = (int) (width * diff);
130
+ } else if (h == 0) { // Use the width to determine relative size
131
+ float diff = (float) w / (float) width;
132
+ h = (int) (height * diff);
133
+ }
134
+
135
+ BufferedImage img =
136
+ shrinkImage((BufferedImage) getNative(), w*pixelDensity, h*pixelDensity);
137
+
138
+ PImage temp = new PImageAWT(img);
139
+ this.pixelWidth = temp.width;
140
+ this.pixelHeight = temp.height;
141
+
142
+ // Get the resized pixel array
143
+ this.pixels = temp.pixels;
144
+
145
+ this.width = pixelWidth / pixelDensity;
146
+ this.height = pixelHeight / pixelDensity;
147
+
148
+ // Mark the pixels array as altered
149
+ updatePixels();
150
+ }
151
+
152
+
153
+ // Adapted from getFasterScaledInstance() method from page 111 of
154
+ // "Filthy Rich Clients" by Chet Haase and Romain Guy
155
+ // Additional modifications and simplifications have been added,
156
+ // plus a fix to deal with an infinite loop if images are expanded.
157
+ // http://code.google.com/p/processing/issues/detail?id=1463
158
+ static private BufferedImage shrinkImage(BufferedImage img,
159
+ int targetWidth, int targetHeight) {
160
+ int type = (img.getTransparency() == Transparency.OPAQUE) ?
161
+ BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
162
+ BufferedImage outgoing = img;
163
+ BufferedImage scratchImage = null;
164
+ Graphics2D g2 = null;
165
+ int prevW = outgoing.getWidth();
166
+ int prevH = outgoing.getHeight();
167
+ boolean isTranslucent = img.getTransparency() != Transparency.OPAQUE;
168
+
169
+ // Use multi-step technique: start with original size, then scale down in
170
+ // multiple passes with drawImage() until the target size is reached
171
+ int w = img.getWidth();
172
+ int h = img.getHeight();
173
+
174
+ do {
175
+ if (w > targetWidth) {
176
+ w /= 2;
177
+ // if this is the last step, do the exact size
178
+ if (w < targetWidth) {
179
+ w = targetWidth;
180
+ }
181
+ } else if (targetWidth >= w) {
182
+ w = targetWidth;
183
+ }
184
+ if (h > targetHeight) {
185
+ h /= 2;
186
+ if (h < targetHeight) {
187
+ h = targetHeight;
188
+ }
189
+ } else if (targetHeight >= h) {
190
+ h = targetHeight;
191
+ }
192
+ if (scratchImage == null || isTranslucent) {
193
+ // Use a single scratch buffer for all iterations and then copy
194
+ // to the final, correctly-sized image before returning
195
+ scratchImage = new BufferedImage(w, h, type);
196
+ g2 = scratchImage.createGraphics();
197
+ }
198
+ g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
199
+ RenderingHints.VALUE_INTERPOLATION_BILINEAR);
200
+ g2.drawImage(outgoing, 0, 0, w, h, 0, 0, prevW, prevH, null);
201
+ prevW = w;
202
+ prevH = h;
203
+ outgoing = scratchImage;
204
+ } while (w != targetWidth || h != targetHeight);
205
+
206
+ if (g2 != null) {
207
+ g2.dispose();
208
+ }
209
+
210
+ // If we used a scratch buffer that is larger than our target size,
211
+ // create an image of the right size and copy the results into it
212
+ if (targetWidth != outgoing.getWidth() ||
213
+ targetHeight != outgoing.getHeight()) {
214
+ scratchImage = new BufferedImage(targetWidth, targetHeight, type);
215
+ g2 = scratchImage.createGraphics();
216
+ g2.drawImage(outgoing, 0, 0, null);
217
+ g2.dispose();
218
+ outgoing = scratchImage;
219
+ }
220
+ return outgoing;
221
+ }
222
+
223
+
224
+ @Override
225
+ protected boolean saveImpl(String filename) {
226
+ if (saveImageFormats == null) {
227
+ saveImageFormats = javax.imageio.ImageIO.getWriterFormatNames();
228
+ }
229
+ try {
230
+ if (saveImageFormats != null) {
231
+ for (String saveImageFormat : saveImageFormats) {
232
+ if (filename.endsWith("." + saveImageFormat)) {
233
+ if (!saveImageIO(filename)) {
234
+ System.err.println("Error while saving image.");
235
+ return false;
236
+ }
237
+ return true;
238
+ }
239
+ }
240
+ }
241
+ } catch (IOException e) {
242
+ }
243
+ return false;
244
+ }
245
+
246
+
247
+ protected String[] saveImageFormats;
248
+
249
+
250
+ /**
251
+ * Use ImageIO functions from Java 1.4 and later to handle image save.
252
+ * Various formats are supported, typically jpeg, png, bmp, and wbmp.
253
+ * To get a list of the supported formats for writing, use: <BR>
254
+ * <code>println(javax.imageio.ImageIO.getReaderFormatNames())</code>
255
+ */
256
+ protected boolean saveImageIO(String path) throws IOException {
257
+ return PImage.saveViaImageIO(this, path);
258
+ }
259
+
260
+ }
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -16,7 +18,8 @@
16
18
  Public License along with this library; if not, write to the
17
19
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
20
  Boston, MA 02111-1307 USA
19
- */
21
+ */
22
+
20
23
  package processing.awt;
21
24
 
22
25
  import java.awt.Paint;
@@ -35,23 +38,26 @@ import processing.core.PGraphics;
35
38
  import processing.core.PShapeSVG;
36
39
  import processing.data.*;
37
40
 
41
+
38
42
  /**
39
- * Implements features for PShape that are specific to AWT and Java2D. At the
40
- * moment, this is gradients and java.awt.Paint handling.
43
+ * Implements features for PShape that are specific to AWT and Java2D.
44
+ * At the moment, this is gradients and java.awt.Paint handling.
41
45
  */
42
46
  public class PShapeJava2D extends PShapeSVG {
43
-
44
47
  Paint strokeGradientPaint;
45
48
  Paint fillGradientPaint;
46
49
 
50
+
47
51
  public PShapeJava2D(XML svg) {
48
52
  super(svg);
49
53
  }
50
54
 
55
+
51
56
  public PShapeJava2D(PShapeSVG parent, XML properties, boolean parseKids) {
52
57
  super(parent, properties, parseKids);
53
58
  }
54
59
 
60
+
55
61
  @Override
56
62
  protected void setParent(PShapeSVG parent) {
57
63
  super.setParent(parent);
@@ -67,9 +73,8 @@ public class PShapeJava2D extends PShapeSVG {
67
73
  }
68
74
  }
69
75
 
70
- /**
71
- * Factory method for subclasses.
72
- */
76
+
77
+ /** Factory method for subclasses. */
73
78
  @Override
74
79
  protected PShapeSVG createShape(PShapeSVG parent, XML properties, boolean parseKids) {
75
80
  return new PShapeJava2D(parent, properties, parseKids);
@@ -88,9 +93,10 @@ public class PShapeJava2D extends PShapeSVG {
88
93
  strokeGradientPaint = calcGradientPaint(strokeGradient);
89
94
  }
90
95
  }
91
- */
92
- static class LinearGradientPaint implements Paint {
96
+ */
93
97
 
98
+
99
+ static class LinearGradientPaint implements Paint {
94
100
  float x1, y1, x2, y2;
95
101
  float[] offset;
96
102
  int[] color;
@@ -98,8 +104,8 @@ public class PShapeJava2D extends PShapeSVG {
98
104
  float opacity;
99
105
 
100
106
  public LinearGradientPaint(float x1, float y1, float x2, float y2,
101
- float[] offset, int[] color, int count,
102
- float opacity) {
107
+ float[] offset, int[] color, int count,
108
+ float opacity) {
103
109
  this.x1 = x1;
104
110
  this.y1 = y1;
105
111
  this.x2 = x2;
@@ -110,21 +116,22 @@ public class PShapeJava2D extends PShapeSVG {
110
116
  this.opacity = opacity;
111
117
  }
112
118
 
119
+ @Override
113
120
  public PaintContext createContext(ColorModel cm,
114
- Rectangle deviceBounds, Rectangle2D userBounds,
115
- AffineTransform xform, RenderingHints hints) {
121
+ Rectangle deviceBounds, Rectangle2D userBounds,
122
+ AffineTransform xform, RenderingHints hints) {
116
123
  Point2D t1 = xform.transform(new Point2D.Float(x1, y1), null);
117
124
  Point2D t2 = xform.transform(new Point2D.Float(x2, y2), null);
118
125
  return new LinearGradientContext((float) t1.getX(), (float) t1.getY(),
119
- (float) t2.getX(), (float) t2.getY());
126
+ (float) t2.getX(), (float) t2.getY());
120
127
  }
121
128
 
129
+ @Override
122
130
  public int getTransparency() {
123
131
  return TRANSLUCENT; // why not.. rather than checking each color
124
132
  }
125
133
 
126
134
  public class LinearGradientContext implements PaintContext {
127
-
128
135
  int ACCURACY = 2;
129
136
  float tx1, ty1, tx2, ty2;
130
137
 
@@ -136,25 +143,22 @@ public class PShapeJava2D extends PShapeSVG {
136
143
  }
137
144
 
138
145
  @Override
139
- public void dispose() {
140
- }
146
+ public void dispose() { }
141
147
 
142
148
  @Override
143
- public ColorModel getColorModel() {
144
- return ColorModel.getRGBdefault();
145
- }
149
+ public ColorModel getColorModel() { return ColorModel.getRGBdefault(); }
146
150
 
147
151
  @Override
148
152
  public Raster getRaster(int x, int y, int w, int h) {
149
- WritableRaster raster
150
- = getColorModel().createCompatibleWritableRaster(w, h);
153
+ WritableRaster raster =
154
+ getColorModel().createCompatibleWritableRaster(w, h);
151
155
 
152
156
  int[] data = new int[w * h * 4];
153
157
 
154
158
  // make normalized version of base vector
155
159
  float nx = tx2 - tx1;
156
160
  float ny = ty2 - ty1;
157
- float len = (float) Math.sqrt(nx * nx + ny * ny);
161
+ float len = (float) Math.sqrt(nx*nx + ny*ny);
158
162
  if (len != 0) {
159
163
  nx /= len;
160
164
  ny /= len;
@@ -178,9 +182,9 @@ public class PShapeJava2D extends PShapeSVG {
178
182
  int[][] interp = new int[span][4];
179
183
  int prev = 0;
180
184
  for (int i = 1; i < count; i++) {
181
- int c0 = color[i - 1];
185
+ int c0 = color[i-1];
182
186
  int c1 = color[i];
183
- int last = (int) (offset[i] * (span - 1));
187
+ int last = (int) (offset[i] * (span-1));
184
188
  //System.out.println("last is " + last);
185
189
  for (int j = prev; j <= last; j++) {
186
190
  float btwn = PApplet.norm(j, prev, last);
@@ -202,13 +206,9 @@ public class PShapeJava2D extends PShapeSVG {
202
206
  float py = (y + j) - ty1;
203
207
  // distance up the line is the dot product of the normalized
204
208
  // vector of the gradient start/stop by the point being tested
205
- int which = (int) ((px * nx + py * ny) * ACCURACY);
206
- if (which < 0) {
207
- which = 0;
208
- }
209
- if (which > interp.length - 1) {
210
- which = interp.length - 1;
211
- }
209
+ int which = (int) ((px*nx + py*ny) * ACCURACY);
210
+ if (which < 0) which = 0;
211
+ if (which > interp.length-1) which = interp.length-1;
212
212
  //if (which > 138) System.out.println("grabbing " + which);
213
213
 
214
214
  data[index++] = interp[which][0];
@@ -225,8 +225,8 @@ public class PShapeJava2D extends PShapeSVG {
225
225
  }
226
226
  }
227
227
 
228
- static class RadialGradientPaint implements Paint {
229
228
 
229
+ static class RadialGradientPaint implements Paint {
230
230
  float cx, cy, radius;
231
231
  float[] offset;
232
232
  int[] color;
@@ -234,8 +234,8 @@ public class PShapeJava2D extends PShapeSVG {
234
234
  float opacity;
235
235
 
236
236
  public RadialGradientPaint(float cx, float cy, float radius,
237
- float[] offset, int[] color, int count,
238
- float opacity) {
237
+ float[] offset, int[] color, int count,
238
+ float opacity) {
239
239
  this.cx = cx;
240
240
  this.cy = cy;
241
241
  this.radius = radius;
@@ -245,10 +245,9 @@ public class PShapeJava2D extends PShapeSVG {
245
245
  this.opacity = opacity;
246
246
  }
247
247
 
248
- @Override
249
248
  public PaintContext createContext(ColorModel cm,
250
- Rectangle deviceBounds, Rectangle2D userBounds,
251
- AffineTransform xform, RenderingHints hints) {
249
+ Rectangle deviceBounds, Rectangle2D userBounds,
250
+ AffineTransform xform, RenderingHints hints) {
252
251
  return new RadialGradientContext();
253
252
  }
254
253
 
@@ -258,28 +257,24 @@ public class PShapeJava2D extends PShapeSVG {
258
257
  }
259
258
 
260
259
  public class RadialGradientContext implements PaintContext {
261
-
262
260
  int ACCURACY = 5;
263
261
 
264
262
  @Override
265
- public void dispose() {
266
- }
263
+ public void dispose() {}
267
264
 
268
265
  @Override
269
- public ColorModel getColorModel() {
270
- return ColorModel.getRGBdefault();
271
- }
266
+ public ColorModel getColorModel() { return ColorModel.getRGBdefault(); }
272
267
 
273
268
  @Override
274
269
  public Raster getRaster(int x, int y, int w, int h) {
275
- WritableRaster raster
276
- = getColorModel().createCompatibleWritableRaster(w, h);
270
+ WritableRaster raster =
271
+ getColorModel().createCompatibleWritableRaster(w, h);
277
272
 
278
273
  int span = (int) radius * ACCURACY;
279
274
  int[][] interp = new int[span][4];
280
275
  int prev = 0;
281
276
  for (int i = 1; i < count; i++) {
282
- int c0 = color[i - 1];
277
+ int c0 = color[i-1];
283
278
  int c1 = color[i];
284
279
  int last = (int) (offset[i] * (span - 1));
285
280
  for (int j = prev; j <= last; j++) {
@@ -297,7 +292,7 @@ public class PShapeJava2D extends PShapeSVG {
297
292
  for (int j = 0; j < h; j++) {
298
293
  for (int i = 0; i < w; i++) {
299
294
  float distance = PApplet.dist(cx, cy, x + i, y + j);
300
- int which = PApplet.min((int) (distance * ACCURACY), interp.length - 1);
295
+ int which = PApplet.min((int) (distance * ACCURACY), interp.length-1);
301
296
 
302
297
  data[index++] = interp[which][0];
303
298
  data[index++] = interp[which][1];
@@ -312,24 +307,26 @@ public class PShapeJava2D extends PShapeSVG {
312
307
  }
313
308
  }
314
309
 
310
+
315
311
  protected Paint calcGradientPaint(Gradient gradient) {
316
312
  if (gradient instanceof LinearGradient) {
317
313
  // System.out.println("creating linear gradient");
318
314
  LinearGradient grad = (LinearGradient) gradient;
319
315
  return new LinearGradientPaint(grad.x1, grad.y1, grad.x2, grad.y2,
320
- grad.offset, grad.color, grad.count,
321
- opacity);
316
+ grad.offset, grad.color, grad.count,
317
+ opacity);
322
318
 
323
319
  } else if (gradient instanceof RadialGradient) {
324
320
  // System.out.println("creating radial gradient");
325
321
  RadialGradient grad = (RadialGradient) gradient;
326
322
  return new RadialGradientPaint(grad.cx, grad.cy, grad.r,
327
- grad.offset, grad.color, grad.count,
328
- opacity);
323
+ grad.offset, grad.color, grad.count,
324
+ opacity);
329
325
  }
330
326
  return null;
331
327
  }
332
328
 
329
+
333
330
  // protected Paint calcGradientPaint(Gradient gradient,
334
331
  // float x1, float y1, float x2, float y2) {
335
332
  // if (gradient instanceof LinearGradient) {
@@ -340,6 +337,8 @@ public class PShapeJava2D extends PShapeSVG {
340
337
  // }
341
338
  // throw new RuntimeException("Not a linear gradient.");
342
339
  // }
340
+
341
+
343
342
  // protected Paint calcGradientPaint(Gradient gradient,
344
343
  // float cx, float cy, float r) {
345
344
  // if (gradient instanceof RadialGradient) {
@@ -350,7 +349,11 @@ public class PShapeJava2D extends PShapeSVG {
350
349
  // }
351
350
  // throw new RuntimeException("Not a radial gradient.");
352
351
  // }
352
+
353
+
353
354
  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
355
+
356
+
354
357
  @Override
355
358
  protected void styles(PGraphics g) {
356
359
  super.styles(g);
@@ -380,4 +383,4 @@ public class PShapeJava2D extends PShapeSVG {
380
383
  }
381
384
  //}
382
385
  }
383
- }
386
+ }