propane 3.1.0.pre-java → 3.2.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/CHANGELOG.md +1 -5
- data/README.md +23 -12
- data/Rakefile +23 -12
- data/lib/propane/helpers/version_error.rb +6 -0
- data/lib/propane/runner.rb +12 -0
- data/lib/propane/version.rb +1 -1
- data/library/slider/slider.rb +1 -1
- data/mvnw +234 -0
- data/mvnw.cmd +145 -0
- data/pom.xml +28 -27
- data/propane.gemspec +2 -2
- data/src/main/java/japplemenubar/JAppleMenuBar.java +41 -47
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/MathToolModule.java +12 -11
- data/src/main/java/monkstone/PropaneLibrary.java +9 -10
- data/src/main/java/monkstone/core/LibraryProxy.java +124 -113
- data/src/main/java/monkstone/fastmath/Deglut.java +86 -89
- data/src/main/java/monkstone/filechooser/Chooser.java +7 -13
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -1
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +4 -4
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +9 -9
- data/src/main/java/monkstone/slider/SimpleSlider.java +0 -9
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +11 -13
- data/src/main/java/monkstone/slider/Slider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +8 -9
- data/src/main/java/monkstone/vecmath/AppRender.java +2 -2
- data/src/main/java/monkstone/vecmath/ShapeRender.java +2 -2
- data/src/main/java/monkstone/vecmath/package-info.java +2 -2
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/VideoInterface.java +11 -5
- data/src/main/java/monkstone/videoevent/package-info.java +2 -2
- data/src/main/java/processing/awt/PGraphicsJava2D.java +1742 -2243
- data/src/main/java/processing/awt/PShapeJava2D.java +268 -270
- data/src/main/java/processing/awt/PSurfaceAWT.java +821 -920
- data/src/main/java/processing/core/DesktopHandler.java +94 -0
- data/src/main/java/processing/core/PApplet.java +14170 -14082
- data/src/main/java/processing/core/PConstants.java +447 -473
- data/src/main/java/processing/core/PFont.java +867 -873
- data/src/main/java/processing/core/PGraphics.java +7193 -7428
- data/src/main/java/processing/core/PImage.java +3051 -3117
- data/src/main/java/processing/core/PMatrix.java +159 -172
- data/src/main/java/processing/core/PMatrix2D.java +403 -444
- data/src/main/java/processing/core/PMatrix3D.java +735 -749
- data/src/main/java/processing/core/PShape.java +2651 -2793
- data/src/main/java/processing/core/PShapeOBJ.java +415 -422
- data/src/main/java/processing/core/PShapeSVG.java +1466 -1475
- data/src/main/java/processing/core/PStyle.java +37 -40
- data/src/main/java/processing/core/PSurface.java +98 -103
- data/src/main/java/processing/core/PSurfaceNone.java +208 -236
- data/src/main/java/processing/core/PVector.java +961 -990
- data/src/main/java/processing/data/DoubleDict.java +709 -753
- data/src/main/java/processing/data/DoubleList.java +695 -748
- data/src/main/java/processing/data/FloatDict.java +702 -746
- data/src/main/java/processing/data/FloatList.java +697 -751
- data/src/main/java/processing/data/IntDict.java +673 -718
- data/src/main/java/processing/data/IntList.java +633 -699
- data/src/main/java/processing/data/JSONArray.java +873 -931
- data/src/main/java/processing/data/JSONObject.java +1165 -1262
- data/src/main/java/processing/data/JSONTokener.java +341 -351
- data/src/main/java/processing/data/LongDict.java +662 -707
- data/src/main/java/processing/data/LongList.java +634 -700
- data/src/main/java/processing/data/Sort.java +41 -37
- data/src/main/java/processing/data/StringDict.java +486 -522
- data/src/main/java/processing/data/StringList.java +580 -624
- data/src/main/java/processing/data/Table.java +3508 -3686
- data/src/main/java/processing/data/TableRow.java +183 -182
- data/src/main/java/processing/data/XML.java +883 -957
- data/src/main/java/processing/event/Event.java +66 -87
- data/src/main/java/processing/event/KeyEvent.java +41 -48
- data/src/main/java/processing/event/MouseEvent.java +93 -103
- data/src/main/java/processing/event/TouchEvent.java +6 -10
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +5 -69
- data/src/main/java/processing/javafx/PSurfaceFX.java +2 -7
- data/src/main/java/processing/opengl/FontTexture.java +270 -290
- data/src/main/java/processing/opengl/FrameBuffer.java +363 -375
- data/src/main/java/processing/opengl/LinePath.java +500 -543
- data/src/main/java/processing/opengl/LineStroker.java +582 -593
- data/src/main/java/processing/opengl/PGL.java +2881 -2904
- data/src/main/java/processing/opengl/PGraphics2D.java +315 -408
- data/src/main/java/processing/opengl/PGraphics3D.java +72 -107
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12043 -12230
- data/src/main/java/processing/opengl/PJOGL.java +1681 -1745
- data/src/main/java/processing/opengl/PShader.java +1257 -1260
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4599 -4662
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1030 -1047
- data/src/main/java/processing/opengl/Texture.java +1397 -1462
- data/src/main/java/processing/opengl/VertexBuffer.java +55 -57
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/vendors/Rakefile +1 -1
- metadata +12 -8
- data/src/main/java/processing/core/ThinkDifferent.java +0 -70
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
|
2
|
-
|
|
3
1
|
/*
|
|
4
2
|
Part of the Processing project - http://processing.org
|
|
5
3
|
|
|
@@ -18,8 +16,7 @@
|
|
|
18
16
|
Public License along with this library; if not, write to the
|
|
19
17
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
20
18
|
Boston, MA 02111-1307 USA
|
|
21
|
-
*/
|
|
22
|
-
|
|
19
|
+
*/
|
|
23
20
|
package processing.awt;
|
|
24
21
|
|
|
25
22
|
import java.awt.Paint;
|
|
@@ -38,50 +35,48 @@ import processing.core.PGraphics;
|
|
|
38
35
|
import processing.core.PShapeSVG;
|
|
39
36
|
import processing.data.*;
|
|
40
37
|
|
|
41
|
-
|
|
42
38
|
/**
|
|
43
|
-
* Implements features for PShape that are specific to AWT and Java2D.
|
|
44
|
-
*
|
|
39
|
+
* Implements features for PShape that are specific to AWT and Java2D. At the
|
|
40
|
+
* moment, this is gradients and java.awt.Paint handling.
|
|
45
41
|
*/
|
|
46
42
|
public class PShapeJava2D extends PShapeSVG {
|
|
47
|
-
Paint strokeGradientPaint;
|
|
48
|
-
Paint fillGradientPaint;
|
|
49
43
|
|
|
44
|
+
Paint strokeGradientPaint;
|
|
45
|
+
Paint fillGradientPaint;
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
public PShapeJava2D(PShapeSVG parent, XML properties, boolean parseKids) {
|
|
57
|
-
super(parent, properties, parseKids);
|
|
58
|
-
}
|
|
47
|
+
public PShapeJava2D(XML svg) {
|
|
48
|
+
super(svg);
|
|
49
|
+
}
|
|
59
50
|
|
|
51
|
+
public PShapeJava2D(PShapeSVG parent, XML properties, boolean parseKids) {
|
|
52
|
+
super(parent, properties, parseKids);
|
|
53
|
+
}
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
@Override
|
|
56
|
+
protected void setParent(PShapeSVG parent) {
|
|
57
|
+
super.setParent(parent);
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
if (parent instanceof PShapeJava2D) {
|
|
60
|
+
PShapeJava2D pj = (PShapeJava2D) parent;
|
|
61
|
+
fillGradientPaint = pj.fillGradientPaint;
|
|
62
|
+
strokeGradientPaint = pj.strokeGradientPaint;
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
} else { // parent is null or not Java2D
|
|
65
|
+
fillGradientPaint = null;
|
|
66
|
+
strokeGradientPaint = null;
|
|
67
|
+
}
|
|
73
68
|
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Factory method for subclasses.
|
|
72
|
+
*/
|
|
73
|
+
@Override
|
|
74
|
+
protected PShapeSVG createShape(PShapeSVG parent, XML properties, boolean parseKids) {
|
|
75
|
+
return new PShapeJava2D(parent, properties, parseKids);
|
|
76
|
+
}
|
|
82
77
|
|
|
83
78
|
|
|
84
|
-
|
|
79
|
+
/*
|
|
85
80
|
@Override
|
|
86
81
|
public void setColor(String colorText, boolean isFill) {
|
|
87
82
|
super.setColor(colorText, isFill);
|
|
@@ -93,230 +88,239 @@ public class PShapeJava2D extends PShapeSVG {
|
|
|
93
88
|
strokeGradientPaint = calcGradientPaint(strokeGradient);
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public PaintContext createContext(ColorModel cm,
|
|
120
|
-
Rectangle deviceBounds, Rectangle2D userBounds,
|
|
121
|
-
AffineTransform xform, RenderingHints hints) {
|
|
122
|
-
Point2D t1 = xform.transform(new Point2D.Float(x1, y1), null);
|
|
123
|
-
Point2D t2 = xform.transform(new Point2D.Float(x2, y2), null);
|
|
124
|
-
return new LinearGradientContext((float) t1.getX(), (float) t1.getY(),
|
|
125
|
-
(float) t2.getX(), (float) t2.getY());
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public int getTransparency() {
|
|
129
|
-
return TRANSLUCENT; // why not.. rather than checking each color
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public class LinearGradientContext implements PaintContext {
|
|
133
|
-
int ACCURACY = 2;
|
|
134
|
-
float tx1, ty1, tx2, ty2;
|
|
135
|
-
|
|
136
|
-
public LinearGradientContext(float tx1, float ty1, float tx2, float ty2) {
|
|
137
|
-
this.tx1 = tx1;
|
|
138
|
-
this.ty1 = ty1;
|
|
139
|
-
this.tx2 = tx2;
|
|
140
|
-
this.ty2 = ty2;
|
|
141
|
-
}
|
|
91
|
+
*/
|
|
92
|
+
static class LinearGradientPaint implements Paint {
|
|
93
|
+
|
|
94
|
+
float x1, y1, x2, y2;
|
|
95
|
+
float[] offset;
|
|
96
|
+
int[] color;
|
|
97
|
+
int count;
|
|
98
|
+
float opacity;
|
|
99
|
+
|
|
100
|
+
public LinearGradientPaint(float x1, float y1, float x2, float y2,
|
|
101
|
+
float[] offset, int[] color, int count,
|
|
102
|
+
float opacity) {
|
|
103
|
+
this.x1 = x1;
|
|
104
|
+
this.y1 = y1;
|
|
105
|
+
this.x2 = x2;
|
|
106
|
+
this.y2 = y2;
|
|
107
|
+
this.offset = offset;
|
|
108
|
+
this.color = color;
|
|
109
|
+
this.count = count;
|
|
110
|
+
this.opacity = opacity;
|
|
111
|
+
}
|
|
142
112
|
|
|
143
|
-
|
|
113
|
+
public PaintContext createContext(ColorModel cm,
|
|
114
|
+
Rectangle deviceBounds, Rectangle2D userBounds,
|
|
115
|
+
AffineTransform xform, RenderingHints hints) {
|
|
116
|
+
Point2D t1 = xform.transform(new Point2D.Float(x1, y1), null);
|
|
117
|
+
Point2D t2 = xform.transform(new Point2D.Float(x2, y2), null);
|
|
118
|
+
return new LinearGradientContext((float) t1.getX(), (float) t1.getY(),
|
|
119
|
+
(float) t2.getX(), (float) t2.getY());
|
|
120
|
+
}
|
|
144
121
|
|
|
145
|
-
|
|
122
|
+
public int getTransparency() {
|
|
123
|
+
return TRANSLUCENT; // why not.. rather than checking each color
|
|
124
|
+
}
|
|
146
125
|
|
|
147
|
-
|
|
148
|
-
WritableRaster raster =
|
|
149
|
-
getColorModel().createCompatibleWritableRaster(w, h);
|
|
126
|
+
public class LinearGradientContext implements PaintContext {
|
|
150
127
|
|
|
151
|
-
|
|
128
|
+
int ACCURACY = 2;
|
|
129
|
+
float tx1, ty1, tx2, ty2;
|
|
152
130
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
ny /= len;
|
|
160
|
-
}
|
|
131
|
+
public LinearGradientContext(float tx1, float ty1, float tx2, float ty2) {
|
|
132
|
+
this.tx1 = tx1;
|
|
133
|
+
this.ty1 = ty1;
|
|
134
|
+
this.tx2 = tx2;
|
|
135
|
+
this.ty2 = ty2;
|
|
136
|
+
}
|
|
161
137
|
|
|
162
|
-
|
|
163
|
-
if (span <= 0) {
|
|
164
|
-
//System.err.println("span is too small");
|
|
165
|
-
// annoying edge case where the gradient isn't legit
|
|
166
|
-
int index = 0;
|
|
167
|
-
for (int j = 0; j < h; j++) {
|
|
168
|
-
for (int i = 0; i < w; i++) {
|
|
169
|
-
data[index++] = 0;
|
|
170
|
-
data[index++] = 0;
|
|
171
|
-
data[index++] = 0;
|
|
172
|
-
data[index++] = 255;
|
|
138
|
+
public void dispose() {
|
|
173
139
|
}
|
|
174
|
-
}
|
|
175
140
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
int prev = 0;
|
|
179
|
-
for (int i = 1; i < count; i++) {
|
|
180
|
-
int c0 = color[i-1];
|
|
181
|
-
int c1 = color[i];
|
|
182
|
-
int last = (int) (offset[i] * (span-1));
|
|
183
|
-
//System.out.println("last is " + last);
|
|
184
|
-
for (int j = prev; j <= last; j++) {
|
|
185
|
-
float btwn = PApplet.norm(j, prev, last);
|
|
186
|
-
interp[j][0] = (int) PApplet.lerp((c0 >> 16) & 0xff, (c1 >> 16) & 0xff, btwn);
|
|
187
|
-
interp[j][1] = (int) PApplet.lerp((c0 >> 8) & 0xff, (c1 >> 8) & 0xff, btwn);
|
|
188
|
-
interp[j][2] = (int) PApplet.lerp(c0 & 0xff, c1 & 0xff, btwn);
|
|
189
|
-
interp[j][3] = (int) (PApplet.lerp((c0 >> 24) & 0xff, (c1 >> 24) & 0xff, btwn) * opacity);
|
|
190
|
-
//System.out.println(j + " " + interp[j][0] + " " + interp[j][1] + " " + interp[j][2]);
|
|
141
|
+
public ColorModel getColorModel() {
|
|
142
|
+
return ColorModel.getRGBdefault();
|
|
191
143
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
144
|
+
|
|
145
|
+
public Raster getRaster(int x, int y, int w, int h) {
|
|
146
|
+
WritableRaster raster
|
|
147
|
+
= getColorModel().createCompatibleWritableRaster(w, h);
|
|
148
|
+
|
|
149
|
+
int[] data = new int[w * h * 4];
|
|
150
|
+
|
|
151
|
+
// make normalized version of base vector
|
|
152
|
+
float nx = tx2 - tx1;
|
|
153
|
+
float ny = ty2 - ty1;
|
|
154
|
+
float len = (float) Math.sqrt(nx * nx + ny * ny);
|
|
155
|
+
if (len != 0) {
|
|
156
|
+
nx /= len;
|
|
157
|
+
ny /= len;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
int span = (int) PApplet.dist(tx1, ty1, tx2, ty2) * ACCURACY;
|
|
161
|
+
if (span <= 0) {
|
|
162
|
+
//System.err.println("span is too small");
|
|
163
|
+
// annoying edge case where the gradient isn't legit
|
|
164
|
+
int index = 0;
|
|
165
|
+
for (int j = 0; j < h; j++) {
|
|
166
|
+
for (int i = 0; i < w; i++) {
|
|
167
|
+
data[index++] = 0;
|
|
168
|
+
data[index++] = 0;
|
|
169
|
+
data[index++] = 0;
|
|
170
|
+
data[index++] = 255;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
} else {
|
|
175
|
+
int[][] interp = new int[span][4];
|
|
176
|
+
int prev = 0;
|
|
177
|
+
for (int i = 1; i < count; i++) {
|
|
178
|
+
int c0 = color[i - 1];
|
|
179
|
+
int c1 = color[i];
|
|
180
|
+
int last = (int) (offset[i] * (span - 1));
|
|
181
|
+
//System.out.println("last is " + last);
|
|
182
|
+
for (int j = prev; j <= last; j++) {
|
|
183
|
+
float btwn = PApplet.norm(j, prev, last);
|
|
184
|
+
interp[j][0] = (int) PApplet.lerp((c0 >> 16) & 0xff, (c1 >> 16) & 0xff, btwn);
|
|
185
|
+
interp[j][1] = (int) PApplet.lerp((c0 >> 8) & 0xff, (c1 >> 8) & 0xff, btwn);
|
|
186
|
+
interp[j][2] = (int) PApplet.lerp(c0 & 0xff, c1 & 0xff, btwn);
|
|
187
|
+
interp[j][3] = (int) (PApplet.lerp((c0 >> 24) & 0xff, (c1 >> 24) & 0xff, btwn) * opacity);
|
|
188
|
+
//System.out.println(j + " " + interp[j][0] + " " + interp[j][1] + " " + interp[j][2]);
|
|
189
|
+
}
|
|
190
|
+
prev = last;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
int index = 0;
|
|
194
|
+
for (int j = 0; j < h; j++) {
|
|
195
|
+
for (int i = 0; i < w; i++) {
|
|
196
|
+
//float distance = 0; //PApplet.dist(cx, cy, x + i, y + j);
|
|
197
|
+
//int which = PApplet.min((int) (distance * ACCURACY), interp.length-1);
|
|
198
|
+
float px = (x + i) - tx1;
|
|
199
|
+
float py = (y + j) - ty1;
|
|
200
|
+
// distance up the line is the dot product of the normalized
|
|
201
|
+
// vector of the gradient start/stop by the point being tested
|
|
202
|
+
int which = (int) ((px * nx + py * ny) * ACCURACY);
|
|
203
|
+
if (which < 0) {
|
|
204
|
+
which = 0;
|
|
205
|
+
}
|
|
206
|
+
if (which > interp.length - 1) {
|
|
207
|
+
which = interp.length - 1;
|
|
208
|
+
}
|
|
209
|
+
//if (which > 138) System.out.println("grabbing " + which);
|
|
210
|
+
|
|
211
|
+
data[index++] = interp[which][0];
|
|
212
|
+
data[index++] = interp[which][1];
|
|
213
|
+
data[index++] = interp[which][2];
|
|
214
|
+
data[index++] = interp[which][3];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
raster.setPixels(0, 0, w, h, data);
|
|
219
|
+
|
|
220
|
+
return raster;
|
|
213
221
|
}
|
|
214
|
-
}
|
|
215
222
|
}
|
|
216
|
-
raster.setPixels(0, 0, w, h, data);
|
|
217
|
-
|
|
218
|
-
return raster;
|
|
219
|
-
}
|
|
220
223
|
}
|
|
221
|
-
}
|
|
222
224
|
|
|
225
|
+
static class RadialGradientPaint implements Paint {
|
|
226
|
+
|
|
227
|
+
float cx, cy, radius;
|
|
228
|
+
float[] offset;
|
|
229
|
+
int[] color;
|
|
230
|
+
int count;
|
|
231
|
+
float opacity;
|
|
232
|
+
|
|
233
|
+
public RadialGradientPaint(float cx, float cy, float radius,
|
|
234
|
+
float[] offset, int[] color, int count,
|
|
235
|
+
float opacity) {
|
|
236
|
+
this.cx = cx;
|
|
237
|
+
this.cy = cy;
|
|
238
|
+
this.radius = radius;
|
|
239
|
+
this.offset = offset;
|
|
240
|
+
this.color = color;
|
|
241
|
+
this.count = count;
|
|
242
|
+
this.opacity = opacity;
|
|
243
|
+
}
|
|
223
244
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
float opacity;
|
|
230
|
-
|
|
231
|
-
public RadialGradientPaint(float cx, float cy, float radius,
|
|
232
|
-
float[] offset, int[] color, int count,
|
|
233
|
-
float opacity) {
|
|
234
|
-
this.cx = cx;
|
|
235
|
-
this.cy = cy;
|
|
236
|
-
this.radius = radius;
|
|
237
|
-
this.offset = offset;
|
|
238
|
-
this.color = color;
|
|
239
|
-
this.count = count;
|
|
240
|
-
this.opacity = opacity;
|
|
241
|
-
}
|
|
245
|
+
public PaintContext createContext(ColorModel cm,
|
|
246
|
+
Rectangle deviceBounds, Rectangle2D userBounds,
|
|
247
|
+
AffineTransform xform, RenderingHints hints) {
|
|
248
|
+
return new RadialGradientContext();
|
|
249
|
+
}
|
|
242
250
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return new RadialGradientContext();
|
|
247
|
-
}
|
|
251
|
+
public int getTransparency() {
|
|
252
|
+
return TRANSLUCENT;
|
|
253
|
+
}
|
|
248
254
|
|
|
249
|
-
|
|
250
|
-
return TRANSLUCENT;
|
|
251
|
-
}
|
|
255
|
+
public class RadialGradientContext implements PaintContext {
|
|
252
256
|
|
|
253
|
-
|
|
254
|
-
int ACCURACY = 5;
|
|
255
|
-
|
|
256
|
-
public void dispose() {}
|
|
257
|
-
|
|
258
|
-
public ColorModel getColorModel() { return ColorModel.getRGBdefault(); }
|
|
259
|
-
|
|
260
|
-
public Raster getRaster(int x, int y, int w, int h) {
|
|
261
|
-
WritableRaster raster =
|
|
262
|
-
getColorModel().createCompatibleWritableRaster(w, h);
|
|
263
|
-
|
|
264
|
-
int span = (int) radius * ACCURACY;
|
|
265
|
-
int[][] interp = new int[span][4];
|
|
266
|
-
int prev = 0;
|
|
267
|
-
for (int i = 1; i < count; i++) {
|
|
268
|
-
int c0 = color[i-1];
|
|
269
|
-
int c1 = color[i];
|
|
270
|
-
int last = (int) (offset[i] * (span - 1));
|
|
271
|
-
for (int j = prev; j <= last; j++) {
|
|
272
|
-
float btwn = PApplet.norm(j, prev, last);
|
|
273
|
-
interp[j][0] = (int) PApplet.lerp((c0 >> 16) & 0xff, (c1 >> 16) & 0xff, btwn);
|
|
274
|
-
interp[j][1] = (int) PApplet.lerp((c0 >> 8) & 0xff, (c1 >> 8) & 0xff, btwn);
|
|
275
|
-
interp[j][2] = (int) PApplet.lerp(c0 & 0xff, c1 & 0xff, btwn);
|
|
276
|
-
interp[j][3] = (int) (PApplet.lerp((c0 >> 24) & 0xff, (c1 >> 24) & 0xff, btwn) * opacity);
|
|
277
|
-
}
|
|
278
|
-
prev = last;
|
|
279
|
-
}
|
|
257
|
+
int ACCURACY = 5;
|
|
280
258
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
for (int j = 0; j < h; j++) {
|
|
284
|
-
for (int i = 0; i < w; i++) {
|
|
285
|
-
float distance = PApplet.dist(cx, cy, x + i, y + j);
|
|
286
|
-
int which = PApplet.min((int) (distance * ACCURACY), interp.length-1);
|
|
287
|
-
|
|
288
|
-
data[index++] = interp[which][0];
|
|
289
|
-
data[index++] = interp[which][1];
|
|
290
|
-
data[index++] = interp[which][2];
|
|
291
|
-
data[index++] = interp[which][3];
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
raster.setPixels(0, 0, w, h, data);
|
|
259
|
+
public void dispose() {
|
|
260
|
+
}
|
|
295
261
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
262
|
+
public ColorModel getColorModel() {
|
|
263
|
+
return ColorModel.getRGBdefault();
|
|
264
|
+
}
|
|
300
265
|
|
|
266
|
+
public Raster getRaster(int x, int y, int w, int h) {
|
|
267
|
+
WritableRaster raster
|
|
268
|
+
= getColorModel().createCompatibleWritableRaster(w, h);
|
|
269
|
+
|
|
270
|
+
int span = (int) radius * ACCURACY;
|
|
271
|
+
int[][] interp = new int[span][4];
|
|
272
|
+
int prev = 0;
|
|
273
|
+
for (int i = 1; i < count; i++) {
|
|
274
|
+
int c0 = color[i - 1];
|
|
275
|
+
int c1 = color[i];
|
|
276
|
+
int last = (int) (offset[i] * (span - 1));
|
|
277
|
+
for (int j = prev; j <= last; j++) {
|
|
278
|
+
float btwn = PApplet.norm(j, prev, last);
|
|
279
|
+
interp[j][0] = (int) PApplet.lerp((c0 >> 16) & 0xff, (c1 >> 16) & 0xff, btwn);
|
|
280
|
+
interp[j][1] = (int) PApplet.lerp((c0 >> 8) & 0xff, (c1 >> 8) & 0xff, btwn);
|
|
281
|
+
interp[j][2] = (int) PApplet.lerp(c0 & 0xff, c1 & 0xff, btwn);
|
|
282
|
+
interp[j][3] = (int) (PApplet.lerp((c0 >> 24) & 0xff, (c1 >> 24) & 0xff, btwn) * opacity);
|
|
283
|
+
}
|
|
284
|
+
prev = last;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
int[] data = new int[w * h * 4];
|
|
288
|
+
int index = 0;
|
|
289
|
+
for (int j = 0; j < h; j++) {
|
|
290
|
+
for (int i = 0; i < w; i++) {
|
|
291
|
+
float distance = PApplet.dist(cx, cy, x + i, y + j);
|
|
292
|
+
int which = PApplet.min((int) (distance * ACCURACY), interp.length - 1);
|
|
293
|
+
|
|
294
|
+
data[index++] = interp[which][0];
|
|
295
|
+
data[index++] = interp[which][1];
|
|
296
|
+
data[index++] = interp[which][2];
|
|
297
|
+
data[index++] = interp[which][3];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
raster.setPixels(0, 0, w, h, data);
|
|
301
|
+
|
|
302
|
+
return raster;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
301
306
|
|
|
302
|
-
|
|
303
|
-
|
|
307
|
+
protected Paint calcGradientPaint(Gradient gradient) {
|
|
308
|
+
if (gradient instanceof LinearGradient) {
|
|
304
309
|
// System.out.println("creating linear gradient");
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
310
|
+
LinearGradient grad = (LinearGradient) gradient;
|
|
311
|
+
return new LinearGradientPaint(grad.x1, grad.y1, grad.x2, grad.y2,
|
|
312
|
+
grad.offset, grad.color, grad.count,
|
|
313
|
+
opacity);
|
|
309
314
|
|
|
310
|
-
|
|
315
|
+
} else if (gradient instanceof RadialGradient) {
|
|
311
316
|
// System.out.println("creating radial gradient");
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
317
|
+
RadialGradient grad = (RadialGradient) gradient;
|
|
318
|
+
return new RadialGradientPaint(grad.cx, grad.cy, grad.r,
|
|
319
|
+
grad.offset, grad.color, grad.count,
|
|
320
|
+
opacity);
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
316
323
|
}
|
|
317
|
-
return null;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
324
|
|
|
321
325
|
// protected Paint calcGradientPaint(Gradient gradient,
|
|
322
326
|
// float x1, float y1, float x2, float y2) {
|
|
@@ -328,8 +332,6 @@ public class PShapeJava2D extends PShapeSVG {
|
|
|
328
332
|
// }
|
|
329
333
|
// throw new RuntimeException("Not a linear gradient.");
|
|
330
334
|
// }
|
|
331
|
-
|
|
332
|
-
|
|
333
335
|
// protected Paint calcGradientPaint(Gradient gradient,
|
|
334
336
|
// float cx, float cy, float r) {
|
|
335
337
|
// if (gradient instanceof RadialGradient) {
|
|
@@ -340,38 +342,34 @@ public class PShapeJava2D extends PShapeSVG {
|
|
|
340
342
|
// }
|
|
341
343
|
// throw new RuntimeException("Not a radial gradient.");
|
|
342
344
|
// }
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
// need to shut off, in case parent object has a gradient applied
|
|
373
|
-
//p2d.fillGradient = false;
|
|
345
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
|
346
|
+
@Override
|
|
347
|
+
protected void styles(PGraphics g) {
|
|
348
|
+
super.styles(g);
|
|
349
|
+
|
|
350
|
+
//if (g instanceof PGraphicsJava2D) {
|
|
351
|
+
PGraphicsJava2D p2d = (PGraphicsJava2D) g;
|
|
352
|
+
|
|
353
|
+
if (strokeGradient != null) {
|
|
354
|
+
p2d.strokeGradient = true;
|
|
355
|
+
if (strokeGradientPaint == null) {
|
|
356
|
+
strokeGradientPaint = calcGradientPaint(strokeGradient);
|
|
357
|
+
}
|
|
358
|
+
p2d.strokeGradientObject = strokeGradientPaint;
|
|
359
|
+
} else {
|
|
360
|
+
// need to shut off, in case parent object has a gradient applied
|
|
361
|
+
//p2d.strokeGradient = false;
|
|
362
|
+
}
|
|
363
|
+
if (fillGradient != null) {
|
|
364
|
+
p2d.fillGradient = true;
|
|
365
|
+
if (fillGradientPaint == null) {
|
|
366
|
+
fillGradientPaint = calcGradientPaint(fillGradient);
|
|
367
|
+
}
|
|
368
|
+
p2d.fillGradientObject = fillGradientPaint;
|
|
369
|
+
} else {
|
|
370
|
+
// need to shut off, in case parent object has a gradient applied
|
|
371
|
+
//p2d.fillGradient = false;
|
|
372
|
+
}
|
|
373
|
+
//}
|
|
374
374
|
}
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
}
|
|
375
|
+
}
|