-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFaceGen2.pde
More file actions
155 lines (134 loc) · 3.02 KB
/
Copy pathFaceGen2.pde
File metadata and controls
155 lines (134 loc) · 3.02 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
void drawLabel( String s, int x, int y ) {
fill( 0 );
text( s, x, y);
fill( 255 );
text( s, x+1, y+1);
}
int POOL_SIZE = 9;
Gene[] genes = null;
boolean changed = true;
boolean show_data = false;
int cellWidth = 0;
int cellHeight = 0;
void setup( ) {
// TODO: eliminate the janky sizing going on here
size( 700, 700, P2D );
cellWidth = width / 3;
cellHeight = height / 3;
smooth();
newDefaultGenes();
}
// generate a blank set of genes
void newDefaultGenes() {
changed = true;
genes = new Gene[POOL_SIZE];
for (int i=0; i<genes.length; i++) {
genes[i] = new Gene(cellWidth, cellHeight);
}
}
void newBlobGenes() {
changed = true;
genes = new BlobGene[POOL_SIZE];
for (int i=0; i<genes.length; i++) {
genes[i] = new BlobGene(cellWidth, cellHeight);
}
}
void newLineGenes() {
changed = true;
genes = new LineGene[POOL_SIZE];
for (int i=0; i<genes.length; i++) {
genes[i] = new LineGene(cellWidth, cellHeight);
}
}
void newColorBlobGenes() {
changed = true;
genes = new ColorBlobGene[POOL_SIZE];
for (int i=0; i<genes.length; i++) {
genes[i] = new ColorBlobGene(cellWidth, cellHeight);
}
}
void draw( ) {
PGraphics pg;
if (changed) {
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
int i = y * 3 + x;
genes[i].render();
pg = genes[i].getImage();
pg.background( 0 );
int gapW = (height - (cellHeight * 3)) / 3;
int gapH = (width - (cellWidth * 3)) / 3;
pushMatrix( );
translate( x * (cellWidth + gapW), y * (cellHeight + gapH) );
pushMatrix( );
translate( cellWidth, 0 );
rotate( HALF_PI );
image( pg, 0, 0 );
if (true) {
noFill();
stroke(0, 0, 0);
strokeWeight(3);
rect(0, 0, width, height);
}
popMatrix();
if (show_data) {
String label = "" + i + ":" + genes[i].active_length;
drawLabel( label, 5, 15 );
}
popMatrix();
}
}
// draw grid overlay
if (false) {
stroke( 0 );
strokeWeight( 8 );
for (int y = 0; y < 3; y++) {
line( 0, y*height/3, width, y*height/3);
}
for (int x = 0; x < 3; x++) {
line( x*width/3, 0, x*width/3, height);
}
}
changed = false;
}
}
void mousePressed() {
changed = true;
// which square got clicked on?
int x = mouseX / (width/3);
int y = mouseY / (height/3);
int target = y * 3 + x;
// copy target to everything else
for (int i=0; i<9; i++) {
if (i != target) {
genes[i].copy( genes[ target ] );
genes[i].mutate(0.09);
}
}
}
void keyTyped() {
changed = true;
switch (key) {
case ' ':
// randomize every gene
for (int i=0; i<9; i++) {
genes[i].randomize();
}
break;
case 'a':
newDefaultGenes();
break;
case 'b':
newBlobGenes();
break;
case 'c':
newLineGenes();
break;
case 'd':
newColorBlobGenes();
break;
case 'z':
show_data = !show_data;
break;
}
}