Skip to content

Commit 0418660

Browse files
committed
Add corner shape.
1 parent c98ffb1 commit 0418660

File tree

2 files changed

+151
-36
lines changed

2 files changed

+151
-36
lines changed

CustomGrid.pde

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
11
enum Pattern{
22
MainGrid,
33
SubGrid,
4+
Corner
45
}
5-
6+
7+
enum CornerPattern{
8+
Plus,
9+
Cross,
10+
Circle
11+
}
12+
613
class CustomGrid{
714
CustomGrid(){
815
}
916
int grid = 8;
1017

1118
Pattern pattern = Pattern.MainGrid;
12-
int mainGridWeight = 2;
19+
CornerPattern cornerPattern = CornerPattern.Plus;
20+
float strokeWidth = 2;
1321
int subGrid = 8;
14-
int subGridWeight = 1;
22+
1523
boolean dashed = false;
24+
float cornerShapeSize = 10;
1625

17-
CustomGrid Main(int gridNum, int mainGridWeight){
26+
CustomGrid Main(int gridNum){
1827
pattern = Pattern.MainGrid;
1928
this.grid = gridNum;
20-
this.mainGridWeight = mainGridWeight;
2129
return this;
2230
}
2331

24-
CustomGrid SubGrid(int gridNum, int subGridNum, int subGridWeight){
32+
CustomGrid SubGrid(int gridNum, int subGridNum){
2533
pattern = Pattern.SubGrid;
2634
this.grid = gridNum;
2735
this.subGrid = subGridNum;
28-
this.subGridWeight = subGridWeight;
36+
return this;
37+
}
38+
39+
CustomGrid Corner(int gridNum, CornerPattern cornerPattern, int cornerShapeSize){
40+
pattern = Pattern.Corner;
41+
this.grid = gridNum;
42+
this.cornerPattern = cornerPattern;
43+
this.cornerShapeSize = cornerShapeSize;
2944
return this;
3045
}
3146

@@ -34,19 +49,43 @@ class CustomGrid{
3449
return this;
3550
}
3651

52+
CustomGrid StrokeWidth(float strokeWidth){
53+
this.strokeWidth = strokeWidth;
54+
return this;
55+
}
56+
3757
String getName(String dst){
3858
String filename = dst+"T_";
3959
filename += "Grid" + grid;
60+
String dash_str = dashed ? "Dash" : "";
4061
switch(pattern){
4162
case MainGrid:
42-
filename += "_MainW" + mainGridWeight;
63+
filename += "_Main" + dash_str + "W" + int(strokeWidth);
4364
break;
4465
case SubGrid:
45-
filename += "_Sub" + subGrid + "W" + subGridWeight;
66+
filename += "_Sub" + subGrid + dash_str + "W" + int(strokeWidth);
67+
break;
68+
case Corner:
4669
break;
4770
default:
4871
break;
4972
}
73+
if(pattern == Pattern.Corner){
74+
switch(cornerPattern){
75+
case Plus:
76+
filename += "_Plus" + "W" + int(strokeWidth) + "S" + int(cornerShapeSize);
77+
break;
78+
case Cross:
79+
filename += "_Cross" + "W" + int(strokeWidth) + "S" + int(cornerShapeSize);
80+
break;
81+
case Circle:
82+
filename += "_Ciecle" + "W" + int(strokeWidth) + "S" + int(cornerShapeSize);
83+
break;
84+
default:
85+
break;
86+
}
87+
}
88+
5089
return filename + ".svg";
5190
}
5291

@@ -61,6 +100,9 @@ class CustomGrid{
61100
case SubGrid:
62101
drawSubGrid();
63102
break;
103+
case Corner:
104+
drawCorner();
105+
break;
64106
default:
65107
break;
66108
}
@@ -77,7 +119,7 @@ class CustomGrid{
77119
float gh = 1.0*height/grid;
78120
stroke(255);
79121
noFill();
80-
strokeWeight(mainGridWeight);
122+
strokeWeight(strokeWidth);
81123
strokeCap(SQUARE);
82124
for(int x = 0; x <= grid; ++x){
83125
if(dashed){
@@ -102,7 +144,7 @@ class CustomGrid{
102144
float sh = gh/subGrid;
103145
stroke(255);
104146
noFill();
105-
strokeWeight(subGridWeight);
147+
strokeWeight(strokeWidth);
106148
strokeCap(SQUARE);
107149
for(int x = 0; x <= grid; ++x){
108150
for(int sx = 1; sx < subGrid; ++sx){
@@ -124,6 +166,55 @@ class CustomGrid{
124166
}
125167
}
126168

169+
void drawCorner(){
170+
float gw = 1.0*width/grid;
171+
float gh = 1.0*height/grid;
172+
173+
switch(cornerPattern){
174+
case Plus:
175+
stroke(255);
176+
noFill();
177+
strokeWeight(strokeWidth);
178+
strokeCap(SQUARE);
179+
break;
180+
case Cross:
181+
stroke(255);
182+
noFill();
183+
strokeWeight(strokeWidth);
184+
strokeCap(SQUARE);
185+
break;
186+
case Circle:
187+
noStroke();
188+
fill(255);
189+
ellipseMode(CENTER);
190+
break;
191+
default:
192+
break;
193+
}
194+
for(int y = 0; y <= grid; ++y){
195+
for(int x = 0; x <= grid; ++x){
196+
float px = x*gw;
197+
float py = y*gh;
198+
switch(cornerPattern){
199+
case Plus:
200+
line(px-cornerShapeSize, py, px+cornerShapeSize, py);
201+
line(px, py-cornerShapeSize, px, py+cornerShapeSize);
202+
break;
203+
case Cross:
204+
float corner = cos(0.25*PI) * cornerShapeSize;
205+
line(px-corner, py-corner, px+corner, py+corner);
206+
line(px-corner, py+corner, px+corner, py-corner);
207+
break;
208+
case Circle:
209+
circle(px, py, cornerShapeSize);
210+
break;
211+
default:
212+
break;
213+
}
214+
}
215+
}
216+
}
217+
127218
void drawDashedLine(float x1, float y1, float x2, float y2, int grid, int dotNum){
128219
PVector v1 = new PVector(x1, y1);
129220
PVector v2 = new PVector(x2, y2);

GridUnitsSVG.pde

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import processing.svg.*;
2-
boolean bSave = false;
32
PFont font;
43
CustomGrid customGrid = new CustomGrid();
54

@@ -10,35 +9,60 @@ void setup(){
109
}
1110

1211
void draw(){
13-
if(bSave){
14-
15-
customGrid.Dashed(true).Main(1, 2).export();
16-
customGrid.Main(2, 2).export();
17-
customGrid.Main(3, 2).export();
18-
customGrid.Main(4, 2).export();
19-
customGrid.Main(5, 2).export();
20-
customGrid.SubGrid(1, 2, 1).export();
21-
customGrid.SubGrid(2, 2, 1).export();
22-
customGrid.SubGrid(2, 5, 1).export();
23-
customGrid.SubGrid(3, 3, 1).export();
24-
customGrid.SubGrid(3, 5, 1).export();
25-
customGrid.SubGrid(4, 2, 1).export();
26-
customGrid.SubGrid(4, 4, 1).export();
27-
customGrid.SubGrid(4, 5, 1).export();
28-
customGrid.SubGrid(5, 4, 1).export();
29-
customGrid.SubGrid(5, 5, 1).export();
30-
bSave = false;
31-
exit();
32-
}
33-
34-
customGrid.Dashed(true).Main(4, 4).render();
35-
12+
//customGrid.StrokeWidth(4).Corner(1, CornerPattern.Plus, width/12).render();
13+
//customGrid.StrokeWidth(4).Corner(1, CornerPattern.Cross, width/12).render();
14+
customGrid.StrokeWidth(4).Corner(1, CornerPattern.Circle, width/12).render();
3615
}
3716

3817
void keyPressed(){
3918
switch(key){
4019
case 's':
41-
bSave = true;
20+
customGrid.StrokeWidth(4).Dashed(false); // style
21+
customGrid.Main(1).export();
22+
customGrid.Main(2).export();
23+
customGrid.Main(4).export();
24+
customGrid.Main(5).export();
25+
26+
customGrid.StrokeWidth(4).Dashed(false); // style
27+
customGrid.SubGrid(1, 2).export();
28+
customGrid.SubGrid(2, 2).export();
29+
customGrid.SubGrid(2, 5).export();
30+
customGrid.SubGrid(4, 2).export();
31+
customGrid.SubGrid(4, 4).export();
32+
customGrid.SubGrid(4, 5).export();
33+
customGrid.SubGrid(5, 4).export();
34+
customGrid.SubGrid(5, 5).export();
35+
36+
customGrid.StrokeWidth(4).Dashed(true); // style
37+
customGrid.Main(1).export();
38+
customGrid.Main(2).export();
39+
customGrid.Main(4).export();
40+
customGrid.Main(5).export();
41+
42+
customGrid.StrokeWidth(4).Dashed(true); // style
43+
customGrid.SubGrid(1, 2).export();
44+
customGrid.SubGrid(2, 2).export();
45+
customGrid.SubGrid(2, 5).export();
46+
customGrid.SubGrid(4, 2).export();
47+
customGrid.SubGrid(4, 4).export();
48+
customGrid.SubGrid(4, 5).export();
49+
customGrid.SubGrid(5, 4).export();
50+
customGrid.SubGrid(5, 5).export();
51+
52+
customGrid.StrokeWidth(8); // style
53+
customGrid.Corner(1, CornerPattern.Plus, width/12).export();
54+
customGrid.Corner(1, CornerPattern.Cross, width/12).export();
55+
customGrid.Corner(1, CornerPattern.Circle, width/12).export();
56+
57+
customGrid.StrokeWidth(4); // style
58+
customGrid.Corner(2, CornerPattern.Plus, width/24).export();
59+
customGrid.Corner(2, CornerPattern.Cross, width/24).export();
60+
customGrid.Corner(2, CornerPattern.Circle, width/24).export();
61+
62+
customGrid.Corner(4, CornerPattern.Plus, width/48).export();
63+
customGrid.Corner(4, CornerPattern.Cross, width/48).export();
64+
customGrid.Corner(4, CornerPattern.Circle, width/48).export();
65+
exit();
4266
break;
4367
default:
4468
break;

0 commit comments

Comments
 (0)