source: js/standard_expdef_demo/js/world/object/text.js @ 1326

Last change on this file since 1326 was 1326, checked in by Maciej Komosinski, 4 months ago

Updated standard.expdef animated demo: uses the most recent Framsticks SDK, supports 6 genetic encodings, adjustable mutation and crossover probabilities, shows colored genotypes, allows user to manually increase/decrease fitness of the current individual, displays its neural network

File size: 1.2 KB
Line 
1/**
2 * @file Text Helper
3 * @author Patryk Gliszczynski
4 * @version 1.0
5 */
6
7var Text = {
8        styleRegex: /<style>.*<\/style>/,
9        numberRegex : /-?\d+(\.\d+)?/g,
10        roundMatch: function(match) {
11        return roundNumber(match,2).toString();
12    },
13
14  getGenotypeMesh: function(genotype,genotypeType) {
15        const genman = new Module.GenMan();
16        genotype = genotype.replace(this.numberRegex, this.roundMatch);
17        genotype = genotype.replaceAll("\n","⤶");
18    if (genotype.length > 20) {
19       genotype = genotype.slice(0,30) + "..."
20    }
21    var element = document.createElement("div");
22    element.innerHTML = genman.HTMLize(genotype).c_str();
23        element.innerHTML = element.innerHTML.replace(this.styleRegex,"").replace(genotypeType,"");
24        Module.destroy(genman);
25    return new CSS3DObject(element);
26  },
27
28  getFitnessMesh: function(fitness) {
29    var element = document.createElement("div");
30    element.className = "fitness";
31    element.textContent = fitness;
32    return new CSS3DObject(element);
33  },
34
35  getInfoMesh: function(info) {
36    var element = document.createElement("div");
37    element.className = "info";
38    element.textContent = info;
39    return new CSS3DObject(element);
40  }
41}
Note: See TracBrowser for help on using the repository browser.