geomerative 0.1.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.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/LICENSE +662 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +2 -0
  6. data/Rakefile +37 -0
  7. data/examples/README.md +7 -0
  8. data/examples/data/FreeSans.ttf +0 -0
  9. data/examples/data/ReplicaBold.ttf +0 -0
  10. data/examples/data/bot1.svg +160 -0
  11. data/examples/hello_svg_to_pdf.rb +26 -0
  12. data/examples/hello_world.rb +23 -0
  13. data/examples/physics_type.rb +77 -0
  14. data/examples/rotate_first_letter.rb +28 -0
  15. data/geomerative.gemspec +32 -0
  16. data/lib/geomerative.rb +12 -0
  17. data/lib/geomerative/version.rb +3 -0
  18. data/pom.xml +110 -0
  19. data/src/geomerative/FastRClip.java +2715 -0
  20. data/src/geomerative/RClip.java +2892 -0
  21. data/src/geomerative/RClosest.java +64 -0
  22. data/src/geomerative/RCommand.java +1941 -0
  23. data/src/geomerative/RContour.java +348 -0
  24. data/src/geomerative/RFont.java +583 -0
  25. data/src/geomerative/RG.java +753 -0
  26. data/src/geomerative/RGeomElem.java +1075 -0
  27. data/src/geomerative/RGroup.java +888 -0
  28. data/src/geomerative/RMatrix.java +401 -0
  29. data/src/geomerative/RMesh.java +420 -0
  30. data/src/geomerative/RPath.java +1095 -0
  31. data/src/geomerative/RPoint.java +419 -0
  32. data/src/geomerative/RPolygon.java +1110 -0
  33. data/src/geomerative/RRectangle.java +91 -0
  34. data/src/geomerative/RSVG.java +976 -0
  35. data/src/geomerative/RShape.java +2045 -0
  36. data/src/geomerative/RStrip.java +221 -0
  37. data/src/geomerative/RStyle.java +469 -0
  38. data/src/org/apache/batik/svggen/font/.SVGFont.java.swp +0 -0
  39. data/src/org/apache/batik/svggen/font/Font.java +188 -0
  40. data/src/org/apache/batik/svggen/font/Glyph.java +113 -0
  41. data/src/org/apache/batik/svggen/font/Messages.java.bak +72 -0
  42. data/src/org/apache/batik/svggen/font/Point.java +38 -0
  43. data/src/org/apache/batik/svggen/font/RandomAccessFileEmulator.java +15 -0
  44. data/src/org/apache/batik/svggen/font/table/ClassDef.java +42 -0
  45. data/src/org/apache/batik/svggen/font/table/ClassDefFormat1.java +55 -0
  46. data/src/org/apache/batik/svggen/font/table/ClassDefFormat2.java +49 -0
  47. data/src/org/apache/batik/svggen/font/table/CmapFormat.java +81 -0
  48. data/src/org/apache/batik/svggen/font/table/CmapFormat0.java +60 -0
  49. data/src/org/apache/batik/svggen/font/table/CmapFormat2.java +48 -0
  50. data/src/org/apache/batik/svggen/font/table/CmapFormat4.java +147 -0
  51. data/src/org/apache/batik/svggen/font/table/CmapFormat6.java +60 -0
  52. data/src/org/apache/batik/svggen/font/table/CmapIndexEntry.java +84 -0
  53. data/src/org/apache/batik/svggen/font/table/CmapTable.java +87 -0
  54. data/src/org/apache/batik/svggen/font/table/Coverage.java +50 -0
  55. data/src/org/apache/batik/svggen/font/table/CoverageFormat1.java +59 -0
  56. data/src/org/apache/batik/svggen/font/table/CoverageFormat2.java +56 -0
  57. data/src/org/apache/batik/svggen/font/table/CvtTable.java +48 -0
  58. data/src/org/apache/batik/svggen/font/table/Device.java +63 -0
  59. data/src/org/apache/batik/svggen/font/table/DirectoryEntry.java +73 -0
  60. data/src/org/apache/batik/svggen/font/table/Feature.java +56 -0
  61. data/src/org/apache/batik/svggen/font/table/FeatureList.java +70 -0
  62. data/src/org/apache/batik/svggen/font/table/FeatureRecord.java +52 -0
  63. data/src/org/apache/batik/svggen/font/table/FeatureTags.java +30 -0
  64. data/src/org/apache/batik/svggen/font/table/FpgmTable.java +38 -0
  65. data/src/org/apache/batik/svggen/font/table/GlyfCompositeComp.java +165 -0
  66. data/src/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java +160 -0
  67. data/src/org/apache/batik/svggen/font/table/GlyfDescript.java +79 -0
  68. data/src/org/apache/batik/svggen/font/table/GlyfSimpleDescript.java +155 -0
  69. data/src/org/apache/batik/svggen/font/table/GlyfTable.java +111 -0
  70. data/src/org/apache/batik/svggen/font/table/GlyphDescription.java +39 -0
  71. data/src/org/apache/batik/svggen/font/table/GposTable.java +80 -0
  72. data/src/org/apache/batik/svggen/font/table/GsubTable.java +118 -0
  73. data/src/org/apache/batik/svggen/font/table/HeadTable.java +159 -0
  74. data/src/org/apache/batik/svggen/font/table/HheaTable.java +109 -0
  75. data/src/org/apache/batik/svggen/font/table/HmtxTable.java +99 -0
  76. data/src/org/apache/batik/svggen/font/table/KernSubtable.java +58 -0
  77. data/src/org/apache/batik/svggen/font/table/KernSubtableFormat0.java +65 -0
  78. data/src/org/apache/batik/svggen/font/table/KernSubtableFormat2.java +56 -0
  79. data/src/org/apache/batik/svggen/font/table/KernTable.java +64 -0
  80. data/src/org/apache/batik/svggen/font/table/KerningPair.java +53 -0
  81. data/src/org/apache/batik/svggen/font/table/LangSys.java +58 -0
  82. data/src/org/apache/batik/svggen/font/table/LangSysRecord.java +52 -0
  83. data/src/org/apache/batik/svggen/font/table/Ligature.java +57 -0
  84. data/src/org/apache/batik/svggen/font/table/LigatureSet.java +55 -0
  85. data/src/org/apache/batik/svggen/font/table/LigatureSubst.java +40 -0
  86. data/src/org/apache/batik/svggen/font/table/LigatureSubstFormat1.java +63 -0
  87. data/src/org/apache/batik/svggen/font/table/LocaTable.java +72 -0
  88. data/src/org/apache/batik/svggen/font/table/Lookup.java +77 -0
  89. data/src/org/apache/batik/svggen/font/table/LookupList.java +68 -0
  90. data/src/org/apache/batik/svggen/font/table/LookupSubtable.java +27 -0
  91. data/src/org/apache/batik/svggen/font/table/LookupSubtableFactory.java +31 -0
  92. data/src/org/apache/batik/svggen/font/table/MaxpTable.java +124 -0
  93. data/src/org/apache/batik/svggen/font/table/NameRecord.java +98 -0
  94. data/src/org/apache/batik/svggen/font/table/NameTable.java +67 -0
  95. data/src/org/apache/batik/svggen/font/table/Os2Table.java +232 -0
  96. data/src/org/apache/batik/svggen/font/table/Panose.java +108 -0
  97. data/src/org/apache/batik/svggen/font/table/PostTable.java +379 -0
  98. data/src/org/apache/batik/svggen/font/table/PrepTable.java +38 -0
  99. data/src/org/apache/batik/svggen/font/table/Program.java +49 -0
  100. data/src/org/apache/batik/svggen/font/table/RangeRecord.java +57 -0
  101. data/src/org/apache/batik/svggen/font/table/Script.java +72 -0
  102. data/src/org/apache/batik/svggen/font/table/ScriptList.java +78 -0
  103. data/src/org/apache/batik/svggen/font/table/ScriptRecord.java +52 -0
  104. data/src/org/apache/batik/svggen/font/table/ScriptTags.java +28 -0
  105. data/src/org/apache/batik/svggen/font/table/SingleSubst.java +47 -0
  106. data/src/org/apache/batik/svggen/font/table/SingleSubstFormat1.java +67 -0
  107. data/src/org/apache/batik/svggen/font/table/SingleSubstFormat2.java +67 -0
  108. data/src/org/apache/batik/svggen/font/table/Table.java +204 -0
  109. data/src/org/apache/batik/svggen/font/table/TableDirectory.java +94 -0
  110. data/src/org/apache/batik/svggen/font/table/TableFactory.java +121 -0
  111. metadata +206 -0
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
3
+ *
4
+ This file is part of Geomerative.
5
+ *
6
+ * Geomerative is free software: you can redistribute it and/or modify it under
7
+ * the terms of the GNU General Public License as published by the Free Software
8
+ * Foundation, either version 3 of the License, or (at your option) any later
9
+ * version.
10
+ *
11
+ * Geomerative is distributed in the hope that it will be useful, but WITHOUT
12
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
+ * details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License along with
17
+ * Geomerative. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ package geomerative;
20
+
21
+ import processing.core.*;
22
+
23
+ /**
24
+ * RStrip is a reduced interface for creating, holding and drawing triangle
25
+ * strips. Triangle strips are ordered lists of points (RPoint) which define the
26
+ * vertices of a mesh.
27
+ *
28
+ * @eexample RStrip
29
+ * @usage Geometry
30
+ * @related RPoint
31
+ * @related RMesh
32
+ * @extended
33
+ */
34
+ public class RStrip {
35
+
36
+ /**
37
+ * @invisible
38
+ */
39
+ public int type = RGeomElem.TRISTRIP;
40
+
41
+ /**
42
+ * Array of RPoint objects holding the vertices of the strip.
43
+ *
44
+ * @eexample vertices
45
+ * @related RPoint
46
+ * @related countVertices ( )
47
+ * @related addVertex ( )
48
+ */
49
+ public RPoint vertices[];
50
+
51
+ // ----------------------
52
+ // --- Public Methods ---
53
+ // ----------------------
54
+ /**
55
+ * Use this method to create a new strip.
56
+ *
57
+ * @eexample RStrip ( )
58
+ * @related addVertex ( )
59
+ * @param s the object of which to make a copy
60
+ */
61
+ public RStrip(RStrip s) {
62
+ for (int i = 0; i < s.countVertices(); i++) {
63
+ this.append(new RPoint(s.vertices[i]));
64
+ }
65
+ }
66
+
67
+ public RStrip() {
68
+ vertices = null;
69
+ }
70
+
71
+ /**
72
+ * Use this method to count the number of vertices in the strip.
73
+ *
74
+ * @eexample countVertices
75
+ * @return int, the number vertices in the strip
76
+ */
77
+ public int countVertices() {
78
+ if (this.vertices == null) {
79
+ return 0;
80
+ }
81
+
82
+ return this.vertices.length;
83
+ }
84
+
85
+ /**
86
+ * Use this method to draw the strip.
87
+ *
88
+ * @eexample drawStrip
89
+ * @param g PGraphics, the graphics object on which to draw the strip
90
+ */
91
+ public void draw(PGraphics g) {
92
+ int numVertices = countVertices();
93
+ g.beginShape(PConstants.TRIANGLE_STRIP);
94
+ for (int i = 0; i < numVertices; i++) {
95
+ g.vertex(vertices[i].x, vertices[i].y);
96
+ }
97
+ g.endShape();
98
+ }
99
+
100
+ /**
101
+ * Use this method to add new vertices to the strip.
102
+ *
103
+ * @param p
104
+ * @eexample addVertex ( )
105
+ */
106
+ public void addVertex(RPoint p) {
107
+ this.append(p);
108
+ }
109
+
110
+ public void addVertex(float x, float y) {
111
+ this.append(new RPoint(x, y));
112
+ }
113
+
114
+ /**
115
+ * Use this method to get the bounding box of the strip.
116
+ *
117
+ * @eexample getBounds
118
+ * @return RContour, the bounding box of the strip in the form of a
119
+ * four-point contour
120
+ * @related draw ( )
121
+ */
122
+ public RContour getBounds() {
123
+ float xmin = Float.MAX_VALUE;
124
+ float ymin = Float.MAX_VALUE;
125
+ float xmax = -Float.MAX_VALUE;
126
+ float ymax = -Float.MAX_VALUE;
127
+
128
+ for (int i = 0; i < this.countVertices(); i++) {
129
+ float x = this.vertices[i].x;
130
+ float y = this.vertices[i].y;
131
+ if (x < xmin) {
132
+ xmin = x;
133
+ }
134
+ if (x > xmax) {
135
+ xmax = x;
136
+ }
137
+ if (y < ymin) {
138
+ ymin = y;
139
+ }
140
+ if (y > ymax) {
141
+ ymax = y;
142
+ }
143
+ }
144
+
145
+ RContour c = new RContour();
146
+ c.addPoint(xmin, ymin);
147
+ c.addPoint(xmin, ymax);
148
+ c.addPoint(xmax, ymax);
149
+ c.addPoint(xmax, ymin);
150
+ return c;
151
+ }
152
+
153
+ /**
154
+ * Use this to get the vertices of the strip. It returns the points as an
155
+ * array of RPoint.
156
+ *
157
+ * @eexample RStrip_getHandles
158
+ * @return RPoint[], the vertices returned in an array.
159
+ *
160
+ */
161
+ public RPoint[] getHandles() {
162
+ return vertices;
163
+ }
164
+
165
+ /**
166
+ * Use this to get the vertices of the strip. It returns the points as an
167
+ * array of RPoint.
168
+ *
169
+ * @eexample RStrip_getPoints
170
+ * @return RPoint[], the vertices returned in an array.
171
+ *
172
+ */
173
+ public RPoint[] getPoints() {
174
+ return vertices;
175
+ }
176
+
177
+ /**
178
+ * Use this method to transform the strip.
179
+ *
180
+ * @eexample transformStrip
181
+ * @param m RMatrix, the matrix of the affine transformation to apply to the
182
+ * strip
183
+ */
184
+ public void transform(RMatrix m) {
185
+ int numVertices = countVertices();
186
+ if (numVertices != 0) {
187
+ for (int i = 0; i < numVertices; i++) {
188
+ vertices[i].transform(m);
189
+ }
190
+ }
191
+ }
192
+
193
+ void add(RPoint p) {
194
+ this.append(p);
195
+ }
196
+
197
+ void add(float x, float y) {
198
+ this.append(new RPoint(x, y));
199
+ }
200
+
201
+ /**
202
+ * Remove all of the points. Creates an empty polygon.
203
+ */
204
+ void clear() {
205
+ this.vertices = null;
206
+ }
207
+
208
+ final void append(RPoint nextvertex) {
209
+ RPoint[] newvertices;
210
+ if (vertices == null) {
211
+ newvertices = new RPoint[1];
212
+ newvertices[0] = nextvertex;
213
+ } else {
214
+ newvertices = new RPoint[this.vertices.length + 1];
215
+ System.arraycopy(this.vertices, 0, newvertices, 0, this.vertices.length);
216
+ newvertices[this.vertices.length] = nextvertex;
217
+ }
218
+ this.vertices = newvertices;
219
+ }
220
+
221
+ }
@@ -0,0 +1,469 @@
1
+ /**
2
+ Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
3
+
4
+ This file is part of Geomerative.
5
+
6
+ Geomerative is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ Geomerative is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with Geomerative. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ package geomerative ;
21
+ import processing.core.*;
22
+
23
+ /**
24
+ * @extended
25
+ */
26
+ public class RStyle{
27
+ public PImage texture = null;
28
+
29
+ public boolean fillDef = false;
30
+ public boolean fill = false;
31
+ public int fillColor = 0xff000000;
32
+
33
+ public boolean fillAlphaDef = false;
34
+ public int fillAlpha = 0xff000000;
35
+
36
+ public boolean strokeDef = false;
37
+ public boolean stroke = false;
38
+ public int strokeColor = 0xff000000;
39
+
40
+ public boolean strokeAlphaDef = false;
41
+ public int strokeAlpha = 0xff000000;
42
+
43
+ public boolean strokeWeightDef = false;
44
+ public float strokeWeight = 1F;
45
+
46
+ public boolean strokeCapDef = false;
47
+ public int strokeCap = RG.PROJECT;
48
+
49
+ public boolean strokeJoinDef = false;
50
+ public int strokeJoin = RG.MITER;
51
+
52
+ private boolean oldFill = false;
53
+ private int oldFillColor = 0;
54
+
55
+ private boolean oldStroke = false;
56
+ private int oldStrokeColor = 0;
57
+ private float oldStrokeWeight = 1F;
58
+ private int oldStrokeCap = RG.PROJECT;
59
+ private int oldStrokeJoin = RG.MITER;
60
+
61
+ public RStyle(){}
62
+
63
+ public RStyle(RStyle p){
64
+ texture = p.texture;
65
+
66
+ fillDef = p.fillDef;
67
+ fill = p.fill;
68
+ fillColor = p.fillColor;
69
+ fillAlphaDef = p.fillAlphaDef;
70
+ fillAlpha = p.fillAlpha;
71
+
72
+ strokeDef = p.strokeDef;
73
+ stroke = p.stroke;
74
+ strokeColor = p.strokeColor;
75
+ strokeAlphaDef = p.strokeAlphaDef;
76
+ strokeAlpha = p.strokeAlpha;
77
+
78
+ strokeWeightDef = p.strokeWeightDef;
79
+ strokeWeight = p.strokeWeight;
80
+
81
+ strokeCapDef = p.strokeCapDef;
82
+ strokeCap = p.strokeCap;
83
+
84
+ strokeJoinDef = p.strokeJoinDef;
85
+ strokeJoin = p.strokeJoin;
86
+ }
87
+
88
+ protected void setStyle(String styleString){
89
+ //RG.parent().println("Style parsing: " + styleString);
90
+ String[] styleTokens = PApplet.splitTokens(styleString, ";");
91
+
92
+ for (String styleToken : styleTokens) {
93
+ String[] tokens = PApplet.splitTokens(styleToken, ":");
94
+ tokens[0] = PApplet.trim(tokens[0]);
95
+ switch (tokens[0]) {
96
+ case "fill":
97
+ setFill(tokens[1]);
98
+ break;
99
+ case "fill-opacity":
100
+ setFillAlpha(tokens[1]);
101
+ break;
102
+ case "stroke":
103
+ setStroke(tokens[1]);
104
+ break;
105
+ case "stroke-width":
106
+ setStrokeWeight(tokens[1]);
107
+ break;
108
+ case "stroke-linecap":
109
+ setStrokeCap(tokens[1]);
110
+ break;
111
+ case "stroke-linejoin":
112
+ setStrokeJoin(tokens[1]);
113
+ break;
114
+ case "stroke-opacity":
115
+ setStrokeAlpha(tokens[1]);
116
+ break;
117
+ case "opacity":
118
+ setAlpha(tokens[1]);
119
+ break;
120
+ default:
121
+ PApplet.println("Attribute '" + tokens[0] + "' not known. Ignoring it.");
122
+ break;
123
+ }
124
+ }
125
+ }
126
+
127
+ public void setFill(boolean _fill){
128
+ fillDef = true;
129
+ fill = _fill;
130
+ }
131
+
132
+ public void setFill(int _fillColor){
133
+ //RG.parent().println("Setting fill by int: " + RG.parent().hex(_fillColor));
134
+ setFill(true);
135
+ fillColor = (fillColor & 0xff000000) | (_fillColor & 0x00ffffff);
136
+ }
137
+
138
+ public void setFill(String str){
139
+ //RG.parent().println("id: " + id);
140
+ //RG.parent().println(" set fill: " + str);
141
+ if(str.equals("none")){
142
+ setFill(false);
143
+
144
+ }else{
145
+ setFill(getColor(str));
146
+
147
+ }
148
+ //RG.parent().println(" fillColor after: " + RG.parent().hex(fillColor));
149
+ }
150
+
151
+ public void setStroke(boolean _stroke){
152
+ strokeDef = true;
153
+ stroke = _stroke;
154
+ }
155
+
156
+ public void setStroke(int _strokeColor){
157
+ setStroke(true);
158
+ strokeColor = (strokeColor & 0xff000000) | (_strokeColor & 0x00ffffff);
159
+ }
160
+
161
+ public void setStroke(String str){
162
+ //RG.parent().println(" set stroke: " + str);
163
+ if(str.equals("none")){
164
+ setStroke(false);
165
+
166
+ }else{
167
+ setStroke(getColor(str));
168
+
169
+ }
170
+ }
171
+
172
+ public void setStrokeWeight(float value){
173
+ //RG.parent().println(" set strokeWeight by float: " + value);
174
+ strokeWeightDef = true;
175
+ strokeWeight = value;
176
+ }
177
+
178
+ public void setStrokeWeight(String str){
179
+ //RG.parent().println(" set strokeWeight by String: " + str);
180
+ if(str.endsWith("px")){
181
+ setStrokeWeight(PApplet.parseFloat(str.substring(0, str.length() - 2)));
182
+ }else{
183
+ setStrokeWeight(PApplet.parseFloat(str));
184
+ }
185
+
186
+
187
+ }
188
+
189
+ public void setStrokeCap(String str){
190
+ //RG.parent().println(" set stroke-cap: " + str);
191
+ strokeCapDef = true;
192
+
193
+ switch (str) {
194
+ case "butt":
195
+ strokeCap = RG.PROJECT;
196
+ break;
197
+ case "round":
198
+ strokeCap = RG.ROUND;
199
+ break;
200
+ case "square":
201
+ strokeCap = RG.SQUARE;
202
+ break;
203
+ }
204
+ }
205
+
206
+ public void setStrokeJoin(String str){
207
+ //RG.parent().println(" set stroke-cap: " + str);
208
+ strokeJoinDef = true;
209
+
210
+ switch (str) {
211
+ case "miter":
212
+ strokeJoin = RG.MITER;
213
+ break;
214
+ case "round":
215
+ strokeJoin = RG.ROUND;
216
+ break;
217
+ case "bevel":
218
+ strokeJoin = RG.BEVEL;
219
+ break;
220
+ }
221
+ }
222
+
223
+ public void setStrokeAlpha(int opacity){
224
+ strokeAlphaDef = true;
225
+ strokeAlpha = opacity;
226
+ }
227
+
228
+ public void setStrokeAlpha(String str){
229
+ setStrokeAlpha((int)(PApplet.parseFloat(str) * 255F));
230
+ }
231
+
232
+ public void setFillAlpha(int opacity){
233
+ fillAlphaDef = true;
234
+ fillAlpha = opacity;
235
+ }
236
+
237
+ public void setFillAlpha(String str){
238
+ //RG.parent().println(" set fillOpacity: " + str);
239
+ setFillAlpha((int)(PApplet.parseFloat(str) * 255F));
240
+ //RG.parent().println(" fillColor after: " + RG.parent().hex(fillColor));
241
+ }
242
+
243
+ public void setAlpha(float opacity){
244
+ //RG.parent().println("Setting float opacity: " + opacity);
245
+ setAlpha((int)(opacity * 100F));
246
+ }
247
+
248
+ public void setAlpha(int opacity){
249
+ /*
250
+ RG.parent().println("setting opacity: " + RG.parent().hex(opacity));
251
+
252
+ RG.parent().println(" fillColor before: " + RG.parent().hex(fillColor));
253
+ RG.parent().println(" strokeColor before: " + RG.parent().hex(fillColor));
254
+ */
255
+
256
+ setFillAlpha(opacity);
257
+ setStrokeAlpha(opacity);
258
+
259
+ //fillColor = ((opacity << 24) & 0xff000000) | (fillColor & 0x00ffffff);
260
+ //strokeColor = ((opacity << 24) & 0xff000000) | (strokeColor & 0x00ffffff);
261
+
262
+ /*
263
+ RG.parent().println(" fillColor now: " + RG.parent().hex(fillColor));
264
+ RG.parent().println(" strokeColor now: " + RG.parent().hex(fillColor));
265
+ */
266
+ }
267
+
268
+ public void setAlpha(String str){
269
+ //RG.parent().println("Setting string opacity: " + str);
270
+ setAlpha(PApplet.parseFloat(str));
271
+ }
272
+
273
+ protected void saveContext(PGraphics g){
274
+ oldFill = g.fill;
275
+ oldFillColor = g.fillColor;
276
+ oldStroke = g.stroke;
277
+ oldStrokeColor = g.strokeColor;
278
+ oldStrokeWeight = g.strokeWeight;
279
+ oldStrokeCap = g.strokeCap;
280
+ oldStrokeJoin = g.strokeJoin;
281
+ }
282
+
283
+ protected void saveContext(PApplet p){
284
+ oldFill = p.g.fill;
285
+ oldFillColor = p.g.fillColor;
286
+ oldStroke = p.g.stroke;
287
+ oldStrokeColor = p.g.strokeColor;
288
+ oldStrokeWeight = p.g.strokeWeight;
289
+ oldStrokeCap = p.g.strokeCap;
290
+ oldStrokeJoin = p.g.strokeJoin;
291
+ }
292
+
293
+ protected void saveContext(){
294
+ saveContext(RG.parent());
295
+ }
296
+
297
+ protected void restoreContext(PGraphics g){
298
+ g.fill(oldFillColor);
299
+ if(!oldFill){
300
+ g.noFill();
301
+ }
302
+
303
+ g.stroke(oldStrokeColor);
304
+ g.strokeWeight(oldStrokeWeight);
305
+
306
+ try{
307
+ g.strokeCap(oldStrokeCap);
308
+ g.strokeJoin(oldStrokeJoin);
309
+ }catch(RuntimeException e){}
310
+
311
+ if(!oldStroke){
312
+ g.noStroke();
313
+ }
314
+ }
315
+
316
+ protected void restoreContext(PApplet p){
317
+ p.fill(oldFillColor);
318
+ if(!oldFill){
319
+ p.noFill();
320
+ }
321
+
322
+ p.stroke(oldStrokeColor);
323
+ p.strokeWeight(oldStrokeWeight);
324
+
325
+ try{
326
+ p.strokeCap(oldStrokeCap);
327
+ p.strokeJoin(oldStrokeJoin);
328
+ }catch(RuntimeException e){}
329
+
330
+ if(!oldStroke){
331
+ p.noStroke();
332
+ }
333
+ }
334
+
335
+ protected void restoreContext(){
336
+ restoreContext(RG.parent());
337
+ }
338
+
339
+ protected void setContext(PGraphics g){
340
+ if(fillAlphaDef){
341
+ if(fillDef){
342
+ fillColor = ((fillAlpha << 24) & 0xff000000) | (fillColor & 0x00ffffff);
343
+ }else{
344
+ if(g.fill){
345
+ g.fill(((fillAlpha << 24) & 0xff000000) | (g.fillColor & 0x00ffffff));
346
+ }
347
+ }
348
+ }
349
+
350
+ if(fillDef){
351
+ g.fill(fillColor);
352
+ if(!fill){
353
+ g.noFill();
354
+ }
355
+ }
356
+
357
+ if(strokeWeightDef){
358
+ g.strokeWeight(strokeWeight);
359
+ }
360
+
361
+ try{
362
+ if(strokeCapDef){
363
+ g.strokeCap(strokeCap);
364
+ }
365
+
366
+ if(strokeJoinDef){
367
+ g.strokeJoin(strokeJoin);
368
+ }
369
+ }catch(RuntimeException e){}
370
+
371
+ if(strokeAlphaDef){
372
+ if(strokeDef){
373
+ strokeColor = ((strokeAlpha << 24) & 0xff000000) | (strokeColor & 0x00ffffff);
374
+ }else{
375
+ if(g.stroke){
376
+ g.stroke(((strokeAlpha << 24) & 0xff000000) | (g.strokeColor & 0x00ffffff));
377
+ }
378
+ }
379
+ }
380
+
381
+ if(strokeDef){
382
+ g.stroke(strokeColor);
383
+ if(!stroke){
384
+ g.noStroke();
385
+ }
386
+ }
387
+ }
388
+
389
+ protected void setContext(PApplet p){
390
+
391
+ if(fillAlphaDef){
392
+ if(fillDef){
393
+ fillColor = ((fillAlpha << 24) & 0xff000000) | (fillColor & 0x00ffffff);
394
+ }else{
395
+ if(p.g.fill){
396
+ p.fill(((fillAlpha << 24) & 0xff000000) | (p.g.fillColor & 0x00ffffff));
397
+ }
398
+ }
399
+ }
400
+
401
+ if(fillDef){
402
+ p.fill(fillColor);
403
+ if(!fill){
404
+ p.noFill();
405
+ }
406
+ }
407
+
408
+ if(strokeWeightDef){
409
+ p.strokeWeight(strokeWeight);
410
+ }
411
+
412
+ try{
413
+ if(strokeCapDef){
414
+ p.strokeCap(strokeCap);
415
+ }
416
+
417
+ if(strokeJoinDef){
418
+ p.strokeJoin(strokeJoin);
419
+ }
420
+ }catch(RuntimeException e){}
421
+
422
+ if(strokeAlphaDef){
423
+ if(strokeDef){
424
+ strokeColor = ((strokeAlpha << 24) & 0xff000000) | (strokeColor & 0x00ffffff);
425
+ }else{
426
+ if(p.g.stroke){
427
+ p.stroke(((strokeAlpha << 24) & 0xff000000) | (p.g.strokeColor & 0x00ffffff));
428
+ }
429
+ }
430
+ }
431
+
432
+ if(strokeDef){
433
+ p.stroke(strokeColor);
434
+ if(!stroke){
435
+ p.noStroke();
436
+ }
437
+ }
438
+ }
439
+
440
+ protected void setContext(){
441
+ setContext(RG.parent());
442
+ }
443
+
444
+
445
+ private int getColor(String colorString){
446
+ colorString = PApplet.trim(colorString);
447
+
448
+ if(colorString.startsWith("#")){
449
+ return PApplet.unhex("FF"+colorString.substring(1));
450
+ }else if(colorString.startsWith("rgb")){
451
+ String[] rgb = PApplet.splitTokens(colorString, "rgb( , )");
452
+ return (int)RG.parent().color(PApplet.parseInt(rgb[0]), PApplet.parseInt(rgb[1]), PApplet.parseInt(rgb[2]));
453
+ }else{
454
+ switch (colorString) {
455
+ case "black":
456
+ return 0;
457
+ case "red":
458
+ return RG.parent().color(255, 0, 0);
459
+ case "green":
460
+ return RG.parent().color(0, 255, 0);
461
+ case "blue":
462
+ return RG.parent().color(0, 0, 255);
463
+ case "yellow":
464
+ return RG.parent().color(0, 255, 255);
465
+ }
466
+ }
467
+ return 0;
468
+ }
469
+ }