Changeset 1336
- Timestamp:
- 05/06/25 23:00:14 (2 days ago)
- Location:
- cpp/frams/genetics/f9
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f9/f9_conv.cpp
r1287 r1336 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 3Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2025 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 125 125 void GenoConv_f90::setColors(Model &m, int last_added_part) //sets fixed (independent from genes) colors and widths on a model, purely for aesthetic purposes 126 126 { 127 //a rainbow on Joints: from the first one red, through middle green, to blue or violet - last 128 static int r[] = { 1, 1, 0, 0, 0, 1 }; 129 static int g[] = { 0, 1, 1, 1, 0, 0 }; 130 static int b[] = { 0, 0, 0, 1, 1, 1 }; 131 int maxind = int(std::size(r)) - 1; 132 133 int joints_count = m.getJointCount(); 134 for (int i = 0; i < joints_count; i++) 135 { 136 Joint *j = m.getJoint(i); 137 double x = joints_count < 2 ? 0 : (double)i / (joints_count - 1); //0..1, postion in the rainbow 138 double ind = x * maxind; 139 j->vcolor.x = mix(r, maxind, ind); 140 j->vcolor.y = mix(g, maxind, ind); 141 j->vcolor.z = mix(b, maxind, ind); 127 static const bool OLD = false; //old "rainbow" hue gradient 128 if (OLD) 129 { 130 //a rainbow on Joints: from the first one red, through middle green, to blue or violet - last 131 static int r[] = { 1, 1, 0, 0, 0, 1 }; 132 static int g[] = { 0, 1, 1, 1, 0, 0 }; 133 static int b[] = { 0, 0, 0, 1, 1, 1 }; 134 int maxind = int(std::size(r)) - 1; 135 136 int joints_count = m.getJointCount(); 137 for (int i = 0; i < joints_count; i++) 138 { 139 Joint *j = m.getJoint(i); 140 double x = joints_count < 2 ? 0 : (double)i / (joints_count - 1); //0..1, position in the rainbow 141 double ind = x * maxind; 142 j->vcolor.x = mix(r, maxind, ind); 143 j->vcolor.y = mix(g, maxind, ind); 144 j->vcolor.z = mix(b, maxind, ind); 145 } 146 } 147 else 148 { 149 int joints_count = m.getJointCount(); 150 for (int i = 0; i < joints_count; i++) 151 { 152 Joint *j = m.getJoint(i); 153 Pt3D d = j->part2->p - j->part1->p; //dx,dy,dz 154 double ax = fabs(d.x), ay = fabs(d.y), az = fabs(d.z); 155 // Pairs of colors should be easy to associate as "one family" at a glance, but different so that we use all main six parts of the spectrum. 156 // Colors are slightly brightened to make them more pastel/plastic; extreme saturation pure red=1,0,0 or blue 0,0,1 do not look good. 157 // Find the longest axis (i.e., recover the information from the genotype: was this joint created by LR, BF, or DU?) 158 if ((ax > ay) && (ax > az)) // x 159 { 160 j->vcolor = d.x < 0 ? Pt3D(1, 0.2, 0.2) : Pt3D(1, 0.2, 0.6); // red, purple red 161 } 162 else 163 if ((ay > ax) && (ay > az)) // y 164 { 165 j->vcolor = d.y < 0 ? Pt3D(0.2, 1, 0.2) : Pt3D(0.7, 1, 0.2); //green, yellowish green 166 } 167 else // z 168 { 169 j->vcolor = d.z < 0 ? Pt3D(0.2, 0.2, 1) : Pt3D(0.4, 0.9, 1); //blue, cyanish blue 170 } 171 } 142 172 } 143 173 144 174 int parts_count = m.getPartCount(); 145 SList jlist; 146 for (int i = 0; i < parts_count; i++) 147 { 148 Part *p = m.getPart(i); 149 jlist.clear(); 150 int count = m.findJoints(jlist, p); 151 Pt3D averagecolor(0, 0, 0); //Parts will get averaged colors from all attached Joints 152 FOREACH(Joint*, j, jlist) 153 averagecolor += j->vcolor; 154 p->vcolor = averagecolor / count; 155 } 156 //m.getPart(0)->vcolor = Pt3D(0, 0, 0); //mark first Part black - a visual aid for easier editing 157 m.getPart(last_added_part)->vcolor = Pt3D(1, 1, 1); //mark last Part white - a visual aid for easier editing 175 if (OLD) 176 { 177 SList jlist; 178 for (int i = 0; i < parts_count; i++) 179 { 180 Part *p = m.getPart(i); 181 jlist.clear(); 182 int count = m.findJoints(jlist, p); 183 Pt3D averagecolor(0, 0, 0); //Parts will get averaged colors from all attached Joints 184 FOREACH(Joint*, j, jlist) 185 averagecolor += j->vcolor; 186 p->vcolor = averagecolor / count; 187 } 188 } 189 else 190 { 191 //Parts will get gray colors from darker to brighter, according to their order of creation. 192 for (int i = 0; i < parts_count; i++) 193 { 194 Part *p = m.getPart(i); 195 p->vcolor.x = p->vcolor.y = p->vcolor.z = 0.3 + 0.4 * i / (parts_count - 1); //0.3..0.7, so first (black) and last (white) stand out more 196 } 197 } 198 //The first Part will be black, the last Part will be white - a visual aid for easier matching of the genotype and the corresponding phenotype. 199 if (!OLD) 200 m.getPart(0)->vcolor = Pt3D(0, 0, 0); //mark first Part black - not attractive in OLD sweet and positive color scheme 201 m.getPart(last_added_part)->vcolor = Pt3D(1, 1, 1); //mark last Part white 158 202 } 159 203 -
cpp/frams/genetics/f9/f9_oper.cpp
r1330 r1336 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 4Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2025 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 152 152 int pos = ptr - turtle_commands_f9; 153 153 int axis = pos / 2; 154 style = GENSTYLE_RGBS(axis == 0 ? 200 : 0, axis == 2 ? 200 : 0, axis == 1 ? 200 : 0, GENSTYLE_NONE); 154 bool increase = (pos % 2) == 1; // positive direction (right/forth/up, not left/back/down) gets brighter, two-dimensional rgb colors 155 // same colors as in GenoConv_f90::setColors(), but not brightened (to increase contrast on white background) 156 style = GENSTYLE_RGBS( 157 axis == 0 ? 200 : (axis == 1 && increase) ? 150 : 0, 158 axis == 1 ? 200 : (axis == 2 && increase) ? 150 : 0, 159 axis == 2 ? 200 : (axis == 0 && increase) ? 150 : 0, GENSTYLE_NONE); 155 160 } 156 161 return style;
Note: See TracChangeset
for help on using the changeset viewer.