Evolving JavaScript
Cultivating Genetic Algorithms for Creative Coding
!שלום Kevin Maes | ReactNext - June 24, 2024
Slide 2
11 Nachmani
Slide 3
From the way way way back machine
Slide 4
Slide 5
Slide 6
Slide 7
Kevin Maes
@kvmaes
Slide 8
Slide 9
Evolutionary Computation Genetic Programming (GP)
Evolutionary Programming (EP)
Genetic Algorithms (GA)
Evolutionary Strategies (ES)
Lawrence Fogel
John H. Holland
Evolutionary Algorithms
Slide 10
John H. Holland
Slide 11
John H. Holland Adaptation in Natural and Arti cial Systems
fi
“general theories of adaptive processes apply across biological, cognitive, social, and computational systems”
There’s a GA for that! • Designing ef cient network topologies • Automated software testing • Evolving game strategies • Scheduling Problems
fi
• Complex hardware design
Slide 14
Evolved antenna
First generation
Middle generations
Last generation
Slide 15
=
ST5-33-142-7
Slide 16
States of a genetic algorithm
Slide 17
Population Initialization
Many “individuals” Each with a potential solution Stored in their “DNA”
Mutation • Need to maintain variation • Avoid “local optima” • Strive for the “global optimum” • Mutation rate • Mutation amount
Slide 22
Canvas, easy as 1, 2, 3. 1.
// index.html <canvas id=“canvas” width=“500” height=“500”></canvas>
2.
// Access the canvas element const canvas = document.getElementById(‘canvas’);
3.
// Get the 2d canvas context const ctx = canvas.getContext(‘2d’);
See Canvas API docs for how to draw shapes, text, styles, etc.
Slide 23
Creative Coding Tips • Don’t forget to clear the canvas before drawing to the canvas • Always use requestAnimationFrame • Crank up the frame rate and be impressed • Consider OOP for particle systems
Slide 24
• Simpli ed syntax • Built-in animation loop • Event handling • Extensive library • Community resources
fi
• Playground environment
Slide 25
Things I’ve learned • Population size • Tweak the tness function • Try other selection methods
fi
• Adjust mutation rates and amounts
Slide 26
Can GAs help us? • Optimizing UI Layouts • Automating A/B Testing • Personalized content recommendations • Code optimization or readability • Dynamic pricing models • Improve website accessibility
Slide 27
Resources
Daniel Shiffman thecodingtrain.com/
New JavaScript version coming September 2024!