propane 3.3.1-java → 3.4.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,42 +41,42 @@ import processing.data.*;
41
41
  */
42
42
  public class PShapeJava2D extends PShapeSVG {
43
43
 
44
- Paint strokeGradientPaint;
45
- Paint fillGradientPaint;
44
+ Paint strokeGradientPaint;
45
+ Paint fillGradientPaint;
46
46
 
47
- public PShapeJava2D(XML svg) {
48
- super(svg);
49
- }
47
+ public PShapeJava2D(XML svg) {
48
+ super(svg);
49
+ }
50
50
 
51
- public PShapeJava2D(PShapeSVG parent, XML properties, boolean parseKids) {
52
- super(parent, properties, parseKids);
53
- }
51
+ public PShapeJava2D(PShapeSVG parent, XML properties, boolean parseKids) {
52
+ super(parent, properties, parseKids);
53
+ }
54
54
 
55
- @Override
56
- protected void setParent(PShapeSVG parent) {
57
- super.setParent(parent);
55
+ @Override
56
+ protected void setParent(PShapeSVG parent) {
57
+ super.setParent(parent);
58
58
 
59
- if (parent instanceof PShapeJava2D) {
60
- PShapeJava2D pj = (PShapeJava2D) parent;
61
- fillGradientPaint = pj.fillGradientPaint;
62
- strokeGradientPaint = pj.strokeGradientPaint;
59
+ if (parent instanceof PShapeJava2D) {
60
+ PShapeJava2D pj = (PShapeJava2D) parent;
61
+ fillGradientPaint = pj.fillGradientPaint;
62
+ strokeGradientPaint = pj.strokeGradientPaint;
63
63
 
64
- } else { // parent is null or not Java2D
65
- fillGradientPaint = null;
66
- strokeGradientPaint = null;
67
- }
64
+ } else { // parent is null or not Java2D
65
+ fillGradientPaint = null;
66
+ strokeGradientPaint = null;
68
67
  }
68
+ }
69
69
 
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
- }
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
+ }
77
77
 
78
78
 
79
- /*
79
+ /*
80
80
  @Override
81
81
  public void setColor(String colorText, boolean isFill) {
82
82
  super.setColor(colorText, isFill);
@@ -88,239 +88,247 @@ public class PShapeJava2D extends PShapeSVG {
88
88
  strokeGradientPaint = calcGradientPaint(strokeGradient);
89
89
  }
90
90
  }
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
- }
112
-
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
- }
121
-
122
- public int getTransparency() {
123
- return TRANSLUCENT; // why not.. rather than checking each color
124
- }
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
+ }
125
112
 
126
- public class LinearGradientContext implements PaintContext {
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
+ }
127
121
 
128
- int ACCURACY = 2;
129
- float tx1, ty1, tx2, ty2;
122
+ public int getTransparency() {
123
+ return TRANSLUCENT; // why not.. rather than checking each color
124
+ }
130
125
 
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
- }
126
+ public class LinearGradientContext implements PaintContext {
127
+
128
+ int ACCURACY = 2;
129
+ float tx1, ty1, tx2, ty2;
130
+
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
+ }
137
+
138
+ @Override
139
+ public void dispose() {
140
+ }
141
+
142
+ @Override
143
+ public ColorModel getColorModel() {
144
+ return ColorModel.getRGBdefault();
145
+ }
146
+
147
+ @Override
148
+ public Raster getRaster(int x, int y, int w, int h) {
149
+ WritableRaster raster
150
+ = getColorModel().createCompatibleWritableRaster(w, h);
151
+
152
+ int[] data = new int[w * h * 4];
153
+
154
+ // make normalized version of base vector
155
+ float nx = tx2 - tx1;
156
+ float ny = ty2 - ty1;
157
+ float len = (float) Math.sqrt(nx * nx + ny * ny);
158
+ if (len != 0) {
159
+ nx /= len;
160
+ ny /= len;
161
+ }
137
162
 
138
- public void dispose() {
163
+ int span = (int) PApplet.dist(tx1, ty1, tx2, ty2) * ACCURACY;
164
+ if (span <= 0) {
165
+ //System.err.println("span is too small");
166
+ // annoying edge case where the gradient isn't legit
167
+ int index = 0;
168
+ for (int j = 0; j < h; j++) {
169
+ for (int i = 0; i < w; i++) {
170
+ data[index++] = 0;
171
+ data[index++] = 0;
172
+ data[index++] = 0;
173
+ data[index++] = 255;
139
174
  }
175
+ }
140
176
 
141
- public ColorModel getColorModel() {
142
- return ColorModel.getRGBdefault();
177
+ } else {
178
+ int[][] interp = new int[span][4];
179
+ int prev = 0;
180
+ for (int i = 1; i < count; i++) {
181
+ int c0 = color[i - 1];
182
+ int c1 = color[i];
183
+ int last = (int) (offset[i] * (span - 1));
184
+ //System.out.println("last is " + last);
185
+ for (int j = prev; j <= last; j++) {
186
+ float btwn = PApplet.norm(j, prev, last);
187
+ interp[j][0] = (int) PApplet.lerp((c0 >> 16) & 0xff, (c1 >> 16) & 0xff, btwn);
188
+ interp[j][1] = (int) PApplet.lerp((c0 >> 8) & 0xff, (c1 >> 8) & 0xff, btwn);
189
+ interp[j][2] = (int) PApplet.lerp(c0 & 0xff, c1 & 0xff, btwn);
190
+ interp[j][3] = (int) (PApplet.lerp((c0 >> 24) & 0xff, (c1 >> 24) & 0xff, btwn) * opacity);
191
+ //System.out.println(j + " " + interp[j][0] + " " + interp[j][1] + " " + interp[j][2]);
143
192
  }
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;
193
+ prev = last;
194
+ }
195
+
196
+ int index = 0;
197
+ for (int j = 0; j < h; j++) {
198
+ for (int i = 0; i < w; i++) {
199
+ //float distance = 0; //PApplet.dist(cx, cy, x + i, y + j);
200
+ //int which = PApplet.min((int) (distance * ACCURACY), interp.length-1);
201
+ float px = (x + i) - tx1;
202
+ float py = (y + j) - ty1;
203
+ // distance up the line is the dot product of the normalized
204
+ // 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
+ }
212
+ //if (which > 138) System.out.println("grabbing " + which);
213
+
214
+ data[index++] = interp[which][0];
215
+ data[index++] = interp[which][1];
216
+ data[index++] = interp[which][2];
217
+ data[index++] = interp[which][3];
221
218
  }
219
+ }
222
220
  }
223
- }
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
- }
244
-
245
- public PaintContext createContext(ColorModel cm,
246
- Rectangle deviceBounds, Rectangle2D userBounds,
247
- AffineTransform xform, RenderingHints hints) {
248
- return new RadialGradientContext();
249
- }
221
+ raster.setPixels(0, 0, w, h, data);
250
222
 
251
- public int getTransparency() {
252
- return TRANSLUCENT;
253
- }
223
+ return raster;
224
+ }
225
+ }
226
+ }
254
227
 
255
- public class RadialGradientContext implements PaintContext {
228
+ static class RadialGradientPaint implements Paint {
229
+
230
+ float cx, cy, radius;
231
+ float[] offset;
232
+ int[] color;
233
+ int count;
234
+ float opacity;
235
+
236
+ public RadialGradientPaint(float cx, float cy, float radius,
237
+ float[] offset, int[] color, int count,
238
+ float opacity) {
239
+ this.cx = cx;
240
+ this.cy = cy;
241
+ this.radius = radius;
242
+ this.offset = offset;
243
+ this.color = color;
244
+ this.count = count;
245
+ this.opacity = opacity;
246
+ }
256
247
 
257
- int ACCURACY = 5;
248
+ @Override
249
+ public PaintContext createContext(ColorModel cm,
250
+ Rectangle deviceBounds, Rectangle2D userBounds,
251
+ AffineTransform xform, RenderingHints hints) {
252
+ return new RadialGradientContext();
253
+ }
258
254
 
259
- public void dispose() {
260
- }
255
+ @Override
256
+ public int getTransparency() {
257
+ return TRANSLUCENT;
258
+ }
261
259
 
262
- public ColorModel getColorModel() {
263
- return ColorModel.getRGBdefault();
264
- }
260
+ public class RadialGradientContext implements PaintContext {
261
+
262
+ int ACCURACY = 5;
263
+
264
+ @Override
265
+ public void dispose() {
266
+ }
267
+
268
+ @Override
269
+ public ColorModel getColorModel() {
270
+ return ColorModel.getRGBdefault();
271
+ }
272
+
273
+ @Override
274
+ public Raster getRaster(int x, int y, int w, int h) {
275
+ WritableRaster raster
276
+ = getColorModel().createCompatibleWritableRaster(w, h);
277
+
278
+ int span = (int) radius * ACCURACY;
279
+ int[][] interp = new int[span][4];
280
+ int prev = 0;
281
+ for (int i = 1; i < count; i++) {
282
+ int c0 = color[i - 1];
283
+ int c1 = color[i];
284
+ int last = (int) (offset[i] * (span - 1));
285
+ for (int j = prev; j <= last; j++) {
286
+ float btwn = PApplet.norm(j, prev, last);
287
+ interp[j][0] = (int) PApplet.lerp((c0 >> 16) & 0xff, (c1 >> 16) & 0xff, btwn);
288
+ interp[j][1] = (int) PApplet.lerp((c0 >> 8) & 0xff, (c1 >> 8) & 0xff, btwn);
289
+ interp[j][2] = (int) PApplet.lerp(c0 & 0xff, c1 & 0xff, btwn);
290
+ interp[j][3] = (int) (PApplet.lerp((c0 >> 24) & 0xff, (c1 >> 24) & 0xff, btwn) * opacity);
291
+ }
292
+ prev = last;
293
+ }
265
294
 
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
- }
295
+ int[] data = new int[w * h * 4];
296
+ int index = 0;
297
+ for (int j = 0; j < h; j++) {
298
+ for (int i = 0; i < w; i++) {
299
+ float distance = PApplet.dist(cx, cy, x + i, y + j);
300
+ int which = PApplet.min((int) (distance * ACCURACY), interp.length - 1);
301
+
302
+ data[index++] = interp[which][0];
303
+ data[index++] = interp[which][1];
304
+ data[index++] = interp[which][2];
305
+ data[index++] = interp[which][3];
306
+ }
304
307
  }
308
+ raster.setPixels(0, 0, w, h, data);
309
+
310
+ return raster;
311
+ }
305
312
  }
313
+ }
306
314
 
307
- protected Paint calcGradientPaint(Gradient gradient) {
308
- if (gradient instanceof LinearGradient) {
315
+ protected Paint calcGradientPaint(Gradient gradient) {
316
+ if (gradient instanceof LinearGradient) {
309
317
  // System.out.println("creating linear gradient");
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);
318
+ LinearGradient grad = (LinearGradient) gradient;
319
+ return new LinearGradientPaint(grad.x1, grad.y1, grad.x2, grad.y2,
320
+ grad.offset, grad.color, grad.count,
321
+ opacity);
314
322
 
315
- } else if (gradient instanceof RadialGradient) {
323
+ } else if (gradient instanceof RadialGradient) {
316
324
  // System.out.println("creating radial gradient");
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;
325
+ RadialGradient grad = (RadialGradient) gradient;
326
+ return new RadialGradientPaint(grad.cx, grad.cy, grad.r,
327
+ grad.offset, grad.color, grad.count,
328
+ opacity);
323
329
  }
330
+ return null;
331
+ }
324
332
 
325
333
  // protected Paint calcGradientPaint(Gradient gradient,
326
334
  // float x1, float y1, float x2, float y2) {
@@ -342,34 +350,34 @@ public class PShapeJava2D extends PShapeSVG {
342
350
  // }
343
351
  // throw new RuntimeException("Not a radial gradient.");
344
352
  // }
345
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
346
- @Override
347
- protected void styles(PGraphics g) {
348
- super.styles(g);
353
+ // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
354
+ @Override
355
+ protected void styles(PGraphics g) {
356
+ super.styles(g);
349
357
 
350
- //if (g instanceof PGraphicsJava2D) {
351
- PGraphicsJava2D p2d = (PGraphicsJava2D) g;
358
+ //if (g instanceof PGraphicsJava2D) {
359
+ PGraphicsJava2D p2d = (PGraphicsJava2D) g;
352
360
 
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
- //}
361
+ if (strokeGradient != null) {
362
+ p2d.strokeGradient = true;
363
+ if (strokeGradientPaint == null) {
364
+ strokeGradientPaint = calcGradientPaint(strokeGradient);
365
+ }
366
+ p2d.strokeGradientObject = strokeGradientPaint;
367
+ } else {
368
+ // need to shut off, in case parent object has a gradient applied
369
+ //p2d.strokeGradient = false;
374
370
  }
371
+ if (fillGradient != null) {
372
+ p2d.fillGradient = true;
373
+ if (fillGradientPaint == null) {
374
+ fillGradientPaint = calcGradientPaint(fillGradient);
375
+ }
376
+ p2d.fillGradientObject = fillGradientPaint;
377
+ } else {
378
+ // need to shut off, in case parent object has a gradient applied
379
+ //p2d.fillGradient = false;
380
+ }
381
+ //}
382
+ }
375
383
  }