-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathREADME
142 lines (105 loc) · 3.55 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
COPYRIGHT
---------------
Copyright 2006-2008 Ricard Marxer <[email protected]>
This product includes software developed by the Solution Engineering, Inc. (http://www.seisw.com/).
This product includes software developed by the The Apache Software Foundation (http://www.apache.org/).
INSTALL
---------------
Unzip the geomerative-XX.zip in the Processing libraries directory.
The result shoul look like this:
/path/to/processing/libraries/geomerative/library/geomerative.jar
USAGE
---------------
In the Processing IDE Sketch > Import Library > geomerative
DOCUMENTATION
---------------
The documentation is in the documentation folder. Just open the index.html with any web browser.
MINI-TUTORIAL
---------------
This geometry library consists of three main classes:
RShape - Contains subshapes formed of commands (move,lines,beziers,...)
RPolygon - Contains contours formed of points
RMesh - Contains strips formed of vertices
There are several uses of the library:
+ Draw shapes with holes, in order to do so, we create a new shape and add commands to it. Once the shape is created we can:
- draw it using draw(g) (note the use of g in order to draw the shape to the main PGraphics object)
- convert it to a polygon using toPolygon()
- acces its subshapes' commands or the points of these commands, accesing its attribute subshapes and the RSubshape methods
+ Draw polygons with holes, in order to do so, we create a new polygon and add points (addPoint(x,y)) or contours (addContour()) to it. Once the polygon is created we can:
- draw it using draw(g)
- convert it to a mesh using toMesh()
- acces its contours' points, accesing its attribute contours and the RContour methods
- do binary operations over two polygons, using the methods diff(), union(), xor() and intersection()
EXAMPLE
--------------
/// Example to draw a simple shape with a hole
/// Converting the shape to a mesh in the setup() avoids having to tesselate it for each frame, therefore the use of RMesh
import geomerative.*;
RPolygon p;
RShape s;
RMesh m;
int t = 0;
void setup(){
size(100,100,P3D);
framerate(34);
background(255);
fill(0);
//noFill();
stroke(255,0,0);
s = new RShape();
s.addMoveTo(-30,250);
s.addLineTo(30,150);
s.addArcTo(50,75,100,30);
s.addBezierTo(130,90,75,100,90,150);
s.addLineTo(130,250);
s.addBezierTo(80,200,70,200,-30,250);
s.addMoveTo(60,120);
s.addBezierTo(75,110,85,130,75,140);
s.addBezierTo(70,150,65,140,60,120);
p = s.toPolygon(100);
m = p.toMesh();
}
void draw(){
scale(0.25);
translate(200,50);
background(255);
rotateY(PI/65*t);
fill(0);
m.draw(g);
rotateY(PI/64*t);
noFill();
p.draw(g);
t++;
}
/// End of example
/// Example calculating the difference of two polygons
/// Note the use of predefined polygons (createStar(), createCircle(), createRing(),...)
import geomerative.*;
RMesh m;
RPolygon p = RPolygon.createStar(120,70,6);
RPolygon p2 = RPolygon.createStar(60,50,30);
float t=0;
void setup(){
size(400,400,P3D);
framerate(24);
//smooth();
noStroke();
fill(0);
p=p.diff(p2);
m = p.toMesh();
}
void draw(){
background(255);
translate(width/2,height/2);
rotateX(t/39);
m.draw(g);
rotateY(-t/5);
scale(0.3);
m.draw(g);
t++;
}
/// End of example
KNOWN ISSUES
-------------
- Under certain renderers there's a big loss of precision, resulting in really ugly renderings of fonts and polygons in general.
- When we decrease the font size we get bad results, bad shapes. This must have to do with the font fixed point arithmetics, haven't studied any of that yet.