forked from PiAir/SymbolicDisarray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolicDisarray.pde
More file actions
162 lines (124 loc) · 3.86 KB
/
SymbolicDisarray.pde
File metadata and controls
162 lines (124 loc) · 3.86 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import processing.svg.*; // library for SVG export
//Label
String label = "SYMBOLIC DISARRAY";
//Plotter dimensions
int xMin = 0;
int yMin = 0;
int xMax = 600;
int yMax = 800;
float startX = 20; //offset
float startY = 30;
float symbolW = 40;
float spaceH = 40; //spacing
float spaceW = 40;
//Current rows and cols
int row = 0;
int col = 0;
int cols = int((xMax - 2*startY) / spaceW); //Total cols. Current column is stored in 'col'
int rows = int((yMax - 2*startX - 40) / spaceH); //Total rows. Current row is stored in 'row'
//Let's set this up
void setup(){
size(600, 800, SVG, "symbolic01.svg");
noLoop();
}
void draw(){
background(233, 233, 220);
textSize(14);
fill(0, 0, 0);
text("SYMBOLIC DISARRAY",xMax-150,yMax-20); //Draw label
/* Draw a grid of predefined symbols */
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
drawSymbol(col,row); //only draw if within bounds
}
}
}
void drawSymbol(int c, int r){
float phi = 0; //initial rotation
Symbol s = new Symbol(100, 100*phi, 100, 100, -15); // Ignore?
//Make sure the first row is straight, then randomize
if (r>1){
phi = random(-r,r);
}
s = new Symbol(startX+spaceW*r+phi, startY+spaceH*c+phi, symbolW, symbolW, phi);
s.drawIt();
}
/*************************
Symbol class
*************************/
class Symbol{
float tx, ty;
float w, h;
float r;
ArrayList<PVector> points = new ArrayList<PVector>();
Symbol(float xpos, float ypos, float scaleX, float scaleY, float rot){
tx = xpos;
ty = ypos;
w = scaleX; //scale
h = scaleY;
r = radians(rot);
//here's a cube, but you can make any contiguous symbol with this simple coordinate system
points.add( new PVector(1,0) );
points.add( new PVector(1,1) );
points.add( new PVector(0,1) );
points.add( new PVector(0,0) );
points.add( new PVector(1,0) );
/*
//here's an example of a triangle symbol
points.add( new PVector(0,0) );
points.add( new PVector(1,1) );
points.add( new PVector(1,0) );
points.add( new PVector(0,0) );
//here's a chevron
points.add( new PVector(0,0) );
points.add( new PVector(0.5,0.5) );
points.add( new PVector(0,1) );
points.add( new PVector(1,1) );
points.add( new PVector(1.5,0.5) );
points.add( new PVector(1,0) );
points.add( new PVector(0,0) );
//here's a bunch of upside down crosses \m/
w /= 3; //scale down to a third of the size
h /= 3;
points.add( new PVector(0,1) );
points.add( new PVector(2,1) );
points.add( new PVector(2,0) );
points.add( new PVector(3,0) );
points.add( new PVector(3,1) );
points.add( new PVector(4,1) );
points.add( new PVector(4,2) );
points.add( new PVector(3,2) );
points.add( new PVector(3,3) );
points.add( new PVector(2,3) );
points.add( new PVector(2,2) );
points.add( new PVector(0,2) );
points.add( new PVector(0,1) );
//here's a simple lightning bolt shape
w /= 7; //scale down
h /= 7;
points.add( new PVector(5,0) );
points.add( new PVector(0,4) );
points.add( new PVector(4.2, 2.3) );
points.add( new PVector(4,5) );
points.add( new PVector(9,1) );
points.add( new PVector(4.8,2.7) );
points.add( new PVector(5,0) );
*/
}
void drawIt(){
//draw shape
for (int i=0; i<points.size()-1; i++){
float x1 = rotX(points.get(i).x, points.get(i).y)*w+tx;
float y1 = rotY(points.get(i).x, points.get(i).y)*h+ty;
float x2 = rotX(points.get(i+1).x, points.get(i+1).y)*w+tx;
float y2 = rotY(points.get(i+1).x, points.get(i+1).y)*h+ty;
line(y1,x1,y2,x2);
}
}
float rotX(float inX, float inY){
return (inX*cos(r) - inY*sin(r));
}
float rotY(float inX, float inY){
return (inX*sin(r) + inY*cos(r));
}
}