# Geometry Free Collision Detection. Attractors.

Simon returned to his “old” code (something he wrote about a month ago) and fixed the collision detection in it. He called this “geometry free”collision detection because he doesn’t use any geometry for this project, but only attraction behaviour. The particles repel each other when the distance between them is 20 pixels.

Here the particles are attracted to the black blobs:

# Spring Animation Tool (Simon’s own code)

The next exciting step in writing his own code about spring force: Simon actually created an interface to allow anyone to build his own shape made of springs and particles! Simon put this project on GitHub and hosted it to make it accessible online.

The online interface to play with: https://simon-tiger.github.io/spring-animation-tool/

He also wrote the instructions himself and placed them in the GitHub Wiki: https://github.com/simon-tiger/spring-animation-tool/wiki/Intro

Videos of the project step by step:

Simon doesn’t consider this project finished. He wants to come up with a way to apply spring force to all the springs simultaneously to make sure the shape’s sides are equal in the final stage.

# Soft Springs (Simon’s own code)

Simon used Chapter 3 (Oscillation) of Daniel Shiffman’s book The Nature of Code as the theoretical basis for creating his own code. First, he played around with what he calls “soft springs” – multiple spring arrays connecting multiple particles (some of them locked but most of them moving) – allowing for most interesting designs thanks to spring force.

Simon called the video below “a mess” that “doesn’t look promising”, but to me it’s my favourite pattern. To me it resembles a constructivist poster turned alive, something like an El Lissitzky animation:

Other soft springs step by step (Simon explains what soft springs are in the first video):

Simon eventually stepped over t trying to create sets of springs and particles that unfold into certain geometrical shapes, like a trapezoid here:

And finally, a hexagon:

# Oscillation and Drag Force: Spring Project.

Today Simon was watching Daniel Shiffman’s tutorials to learn about drag force and how to apply it when building a spring simulation in p5.js. Simon wrote the formula for drag force in Microfost Word and looked up all the variables:

While building a spring in p5.js, Simon talks about the 3 laws of Isaac Newton:

The project is based upon Daniel Shiffman’s book The Nature of Code, specifically Chapter 3 (Oscillation). Simon spent the rest of the evening studying “simple harmonic motion”, periods and amplitudes. Here is an excerpt from Daniel Shiffman’s book:

# Microsoft Kinect (v2) in Processing using the Open Kinect for Processing library

Our Kinect adapter has finally arrived! Simon had been waiting for about one and a half months and was extremely hyper to try out the code he had already written ages ago, following Daniel Shiffman’s tutorials on Computer Vision.  The code involved processing the pixels of the “depth image” and mapping depth to brightness. Simon also learned how to find the average location of a set of pixels within a minimum and maximum depth threshold (can be useful for basic hand tracking).

# Path Following (Simon’s own code). Applying restitution.

On Thursday Simon was busy with writing his own code in Java. He called it “Path Following”. The project basically involved simulating different phenomena with a physics particle (having it follow a path, fall and bounce).

The most interesting part of this challenge Simon invented for himself was applying restitution to make the particle bounce in a realistic way (Simon failed several times but eventually succeeded). “If a bound hits the physics particle I’m going to multiply the physics particle’s velocity by -0.8 (0.8 is the arbitrary restitution, so I multiply the velocity by the negative restitution)”, Simon explained.

He also planned to incorporate collision detection in this project but didn’t succeed.

Here the particle is drawing a graph (“noise without a noise function”):

Here Simon adds one more particle and is trying to create collision detection and make the particles restitute:

Debugging and using inheritance for the second particle:

Making the particle remember the graph:

Applying gravity to the physics particle:

Trying to make the physics particle bounce (apply restitution). In this video Simon doesn’t succeed.

Simon manages to control the particle’s bounce (with the mouse) but there’s still no restitution:

In the following video Simon finally won: he figured out how to apply restitution to the bouncing particle making it look like a bouncing ball. After a few bounces however, the particle collapsed (Simon solved the collapsing problem later on: in his code, the < and > should be <= and >=).

In a steering behavior variation, trying to teach a particle to follow a given path (road). Simon hoped to apply a genetic algorithm here but got stuck:

# Simulating Evolution: Evolutionary Steering Behaviors

On Wednesday Simon went on with playing god (evolution simulation) and translated Daniel Shiffman’s Evolutionary Steering Behaviors Coding Challenge from JavaScript to Java.  The goal of the challenge is to create a system where autonomous steering agents (smart rockets) evolve the behavior of eating food (green dots) and avoiding poison (red dots).

This challenge is part of the spring 2017 “Intelligence and Learning” course at NYU’s Tisch School of the Arts Interactive Telecommunications Program. Simon was especially happy to find out that Daniel Shiffman left a couple of personal comments praising Simon’s progress and offering help in pushing his code to Danniel’s GitHub repo.

Here is Simon’s translation on GitHub: https://github.com/simon-tiger/steering-behaviors-evolution

The rockets have their own DNA consisting of four genes:

The challenge step by step:

# Autonomous Agents and Genetic Algorithms

Today Simon spent hours watching videos and reading Daniel Shiffman’s book The Nature of Code, concentrating on more complicated matters than ever: autonomous agents and evolution (genetic algorithms). In The Nature of Code there are two separate chapters covering these topics.  The term autonomous agent is defined as “an entity that makes its own choices about how to act in its environment without any influence from a leader or global plan”. This basically means that Simon has decided to try programming smart entities, that are like living things (have their DNA’s, behaviours, evolution).

The Autonomous Agent chapter also talks about steering force:

In the videos below, Simon has studied the steering behaviors in Daniel Shiffman’s code (Seek, Flee and Arrival) and changed the code slightly (third video) to be able to switch between the behaviours with a click of the mouse:

I also saw Simon go through the paper called Steering behaviours For Autonomous Characters by Craig W. Reynolds and reading about Persuit and Evade steering behaviours at this game development page.

In the video below Simon adjusted the Evolve Flow Field code to be able to see the possible behaviours (velocity vectors) of his smart rockets.

The code comes from the chapter Evolution of Code in Daniel Shiffman’s book, the chapter mainly devoted to genetic algorithms: it looks at the core principles behind Darwinian evolutionary theory and develops a set of algorithms inspired by these principles.

One of the most interesting notions Simon came across today was fitness, as in survival of the fittest. In the video you see Simon creating obstacles for the smart rockets. Together we observed how, as many generations of rockets passed, they learned to go around the obstacles better. This was possible because the rocket’s fitness was programmed to be greatly reduced every time it hit an obstacle.

All the rockets also have DNA’s: “We are marching through the array of PVectors and applying them one at a time as a force to the rocket”, Daniel Shiffman explains.

Simon also learned about genotypes and phenotypes, mating pool, crossover and mutation. He loved Daniel Shiffman’s example about haw many generations of strings with 18 random “genes” it would take to write “To be or not to be”.