├── .gitignore ├── Images ├── capaFundoClaro.png ├── capaFundoEscuro.png ├── logoFundoClaro.png ├── logoFundoEscuro.png └── logoEscuroSemFundo.png ├── public ├── Classes │ ├── Ponto.js │ ├── Historico.js │ ├── Infos.js │ ├── Alimento.js │ ├── Circulo.js │ ├── DNA.js │ ├── Retangulo.js │ ├── Vetor.js │ ├── Carnivoro.js │ ├── Herbivoro.js │ ├── QuadTree.js │ └── Organismo.js ├── style.css ├── chart.js └── index.js ├── README.md └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | 3 | -------------------------------------------------------------------------------- /Images/capaFundoClaro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-llo/evolv-e/HEAD/Images/capaFundoClaro.png -------------------------------------------------------------------------------- /Images/capaFundoEscuro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-llo/evolv-e/HEAD/Images/capaFundoEscuro.png -------------------------------------------------------------------------------- /Images/logoFundoClaro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-llo/evolv-e/HEAD/Images/logoFundoClaro.png -------------------------------------------------------------------------------- /Images/logoFundoEscuro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-llo/evolv-e/HEAD/Images/logoFundoEscuro.png -------------------------------------------------------------------------------- /Images/logoEscuroSemFundo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-llo/evolv-e/HEAD/Images/logoEscuroSemFundo.png -------------------------------------------------------------------------------- /public/Classes/Ponto.js: -------------------------------------------------------------------------------- 1 | class Ponto { 2 | constructor(x, y, userData){ 3 | this.posicao = new Vetor(x, y); 4 | this.userData = userData; 5 | } 6 | } -------------------------------------------------------------------------------- /public/Classes/Historico.js: -------------------------------------------------------------------------------- 1 | class Historico { 2 | constructor() { 3 | this.herbivoros = new Infos(); 4 | this.carnivoros = new Infos(); 5 | this.segundos = []; 6 | this.taxa_alimentos = []; // Alimentos por segundo 7 | } 8 | 9 | clear() { 10 | this.herbivoros.clear(); 11 | this.carnivoros.clear(); 12 | this.segundos.length = 0; 13 | } 14 | } -------------------------------------------------------------------------------- /public/Classes/Infos.js: -------------------------------------------------------------------------------- 1 | class Infos { 2 | constructor(){ 3 | this.populacao = []; 4 | this.velocidade = []; 5 | this.agilidade = []; 6 | this.raio = []; 7 | this.deteccao = []; 8 | this.energia = []; 9 | this.gasto = []; 10 | this.tamanho_medio_ninhada = []; 11 | } 12 | 13 | clear() { 14 | this.populacao.length = 0 15 | this.velocidade.length = 0 16 | this.agilidade.length = 0 17 | this.raio.length = 0 18 | this.deteccao.length = 0 19 | this.energia.length = 0 20 | this.gasto.length = 0 21 | this.tamanho_medio_ninhada.length = 0; 22 | } 23 | } -------------------------------------------------------------------------------- /public/Classes/Alimento.js: -------------------------------------------------------------------------------- 1 | class Alimento{ 2 | static alimentos = []; 3 | static id = 0; 4 | 5 | constructor(x, y, raio){ 6 | this.posicao = new Vetor(x, y); 7 | this.raio = raio; 8 | // a energia do pedaço de alimento é proporcinal à sua área 9 | this.energia_alimento = Math.floor(Math.PI * Math.pow(this.raio, 2)) * 15; 10 | 11 | Alimento.alimentos.push(this); 12 | 13 | // ID 14 | this.id = Alimento.id++; 15 | } 16 | 17 | display(){ 18 | c.beginPath(); 19 | c.arc(this.posicao.x, this.posicao.y, this.raio, 0, Math.PI * 2); 20 | c.fillStyle = "rgb(115, 158, 115)"; 21 | c.fill(); 22 | } 23 | 24 | 25 | checaId(id){ 26 | return (id == this.id); 27 | } 28 | } -------------------------------------------------------------------------------- /public/Classes/Circulo.js: -------------------------------------------------------------------------------- 1 | class Circulo{ 2 | constructor(x,y,r){ 3 | this.x = x; 4 | this.y = y; 5 | this.r = r; 6 | } 7 | 8 | // Checa se o ponto está contido dentro de seus limites (fronteiras) 9 | contemPonto(ponto){ 10 | let xPonto = ponto.posicao.x; 11 | let yPonto = ponto.posicao.y; 12 | 13 | return( 14 | Math.sqrt(Math.pow(xPonto - this.x, 2) + Math.pow(yPonto - this.y, 2)) <= this.r // Se a distância do ponto até o círculo for menor ou igual ao raio 15 | ); 16 | } 17 | 18 | // Método para saber se os retângulos se interseptam 19 | intersepta(alcance){ 20 | return !( // Se essa expressão for verdade, eles NÃO se interceptam 21 | alcance.x - alcance.w > this.x + this.w || 22 | alcance.x + alcance.w < this.x - this.w || 23 | alcance.y - alcance.h > this.y + this.h || 24 | alcance.y + alcance.h < this.y - this.h 25 | ); 26 | } 27 | } -------------------------------------------------------------------------------- /public/Classes/DNA.js: -------------------------------------------------------------------------------- 1 | class DNA{ 2 | constructor(raio_inicial, vel_max, forca_max, cor, raio_deteccao_inicial, intervalo_ninhada, sexo){ 3 | this.raio_inicial = raio_inicial; 4 | this.vel_max = vel_max; 5 | this.forca_max = forca_max; 6 | this.cor = cor; 7 | this.raio_deteccao_inicial = raio_deteccao_inicial; 8 | this.intervalo_ninhada = intervalo_ninhada; 9 | this.sexo = sexo; // string que pode ser XX (fêmea) ou XY (macho) 10 | } 11 | 12 | mutar(){ 13 | var dna_mutado; 14 | 15 | // raio inicial 16 | var raio_inicial_filho = newMutacao(this.raio_inicial); 17 | if(raio_inicial_filho < 0){ 18 | raio_inicial_filho = 0; 19 | } 20 | // velocidade máxima 21 | var vel_max_filho = newMutacao(this.vel_max); 22 | if(vel_max_filho < 0){ 23 | vel_max_filho = 0; 24 | } 25 | 26 | // força máxima 27 | var forca_max_filho = newMutacao(this.forca_max); 28 | 29 | // cor 30 | var cor_filho = corMutacao(this.cor); 31 | 32 | // raio de detecção inicial 33 | var raio_deteccao_inicial_filho = newMutacao(this.raio_deteccao_inicial); 34 | if(raio_deteccao_inicial_filho < raio_inicial_filho){ 35 | raio_deteccao_inicial_filho = raio_inicial_filho; 36 | } 37 | 38 | // tamanho da ninhada 39 | var intervalo_ninhada_filho = mutacaoNinhada(this.intervalo_ninhada[0], this.intervalo_ninhada[1]); 40 | 41 | dna_mutado = new DNA( 42 | raio_inicial_filho, 43 | vel_max_filho, 44 | forca_max_filho, 45 | cor_filho, 46 | raio_deteccao_inicial_filho, 47 | intervalo_ninhada_filho 48 | ) 49 | 50 | return dna_mutado; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 | 3 | ## Genetic Algorithm in Javascript 4 | 5 | * Web application that aims at **simulating evolution** by natural selection using genetic algorithms in Javascript. 6 | 7 | ## 📖How does it work? 8 | It is a 2D virtual environment in which organisms with randomly generated genes evolve over the generations. The user has the ability to alter some of the properties that rule the environment in order to analyse how each gene (attribute) is affected. Each object - organism - may or may not conceive new descendents, which will carry their father's attributes values with themselves, but with a slight chance for each of the genes of undergoing a mutation. 9 | 10 | ## 🧰Tools 11 | The interface used for the simulation is primarily HTML Canvas. However, alongside it there's a dashboard containing interactive graphics which showcase the frequency of each gene in the population over time. 12 | 13 | ## ⁉️Why? 14 | Our goal is to demonstrate how natural selection enables complex populations and behaviors to spontaneously emerge even in rigid environments ruled by simplistic laws. 15 | 16 | --- 17 | ## 👩💻 Try it on 18 | * [Click here to see how it works](https://e-llo.github.io/evolv-e/) 19 | * You can also run this application locally 20 | 21 | ## How can I run this locally? 22 | ### ☁️ Clone this repository 23 | ```bash 24 | https://github.com/e-llo/evolv-e.git 25 | ``` 26 | 46 | Then open the index.html file on your browser 47 | 48 | --- 49 | 50 | ## 👩💻👨💻👨💻 Contributors 51 |
|
54 |
55 | 56 | 57 | Julia Rolemberg 58 | 59 | 60 | |
61 |
62 |
63 | 64 | 65 | Pedro Heck 66 | 67 | 68 | |
69 |
70 |
71 | 72 | 73 | Raphael Menezes de Jesus 74 | 75 | 76 | |
77 |
49 |