-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridWithColor.pde
60 lines (50 loc) · 1.28 KB
/
GridWithColor.pde
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
class GridWithColor{
GridWithColor(){
}
color[] colors = {
#05668D, #028090, #02C39A, #F0F3BD
};
int largeText = 26;
void draw(int xGrid, int yGrid){
background(255);
float gw = 1.0*width/xGrid;
float gh = 1.0*height/yGrid;
noStroke();
for(int y = 0; y < yGrid; ++y){
for(int x = 0; x < xGrid; ++x){
color c = colors[(x+y)%colors.length];
fill(c);
rect(x*gw, y*gh, gw, gh);
}
}
stroke(255);
strokeWeight(2);
for(int x = 0; x <= xGrid; ++x){
line(x*gw, 0, x*gw, height);
}
for(int y = 0; y <= yGrid; ++y){
line(0, y*gh, width, y*gh);
}
noStroke();
fill(255);
for(int y = 0; y <= yGrid; ++y){
for(int x = 0; x <= xGrid; ++x){
ellipse(x*gw, y*gh, 12, 12);
}
}
textSize(largeText);
textAlign(CENTER, CENTER);
fill(255);
for(int y = 0; y < yGrid; ++y){
for(int x = 0; x < xGrid; ++x){
color c = colors[(2+x+y)%colors.length];
fill(c);
String s = getCharForNumber(y+1)+x;
text(s, (x+0.5)*gw, (y+0.5)*gh);
}
}
}
private String getCharForNumber(int i) {
return i > 0 && i < 27 ? String.valueOf((char)(i + 'A' - 1)) : null;
}
}