Koch Snowflake

His sister an grandma visiting from snowy Russia making paper snowflakes inspired Simon…

Right is Simon’s sister’s snowflake, left is Simon’s:

DSC_0050

 

Advertisements

Live Stream #6. (Mostly) Chapter 2 of Living Code: Forces.

Simon’s latest live stream on Thursday, January 11 was a blast! For the first time in his programming career he actually had quite a few viewers – largely thanks to Daniel Shiffman, who posted an announcement about Simon’s live session in his Twitter:

During the session, Simon recorded 6 tutorials:

  • a bonus video about vectors,
  • a video about forces in general,
  • a video about mass,
  • a video about the Friction Force,
  • a video about Air Resistance
  • and a video about Gravitational Attraction.

All as part of his “Living Code” Course. The lessons in the course are loosely based on Daniel Shiffman’s book “The Nature of Code“, but focus on JavaScript.

Simon was worried in the beginning, because he had forgotten to prepare for the stream and had no choice but do the theory (on physical forces) on the fly. It was wonderful to see how the competent viewers gave him a helping hand every now and then and generally encouraged him in the live chat. He even got a real Q&A session in the end, something he had always dreamed of:

Schermafbeelding 2018-01-11 om 20.38.49Schermafbeelding 2018-01-11 om 20.39.27Schermafbeelding 2018-01-11 om 20.39.42Schermafbeelding 2018-01-11 om 20.40.01Schermafbeelding 2018-01-11 om 20.40.20Schermafbeelding 2018-01-11 om 20.40.45Schermafbeelding 2018-01-11 om 20.41.01Schermafbeelding 2018-01-11 om 20.41.14Schermafbeelding 2018-01-11 om 20.41.24

Magic around New Year’s Eve

This magical time of the year, Simon’s craziest, most daring dreams come true! First, his guru from the New York University Daniel Shiffman sends Simon his book and the words he writes there are the most beautiful words anyone has ever told him. Then, on the last day of the awesome year 2017, Simon’s other hero, the glamorous knight of AI Siraj Raval materialises in our living room, directly from YouTube! Happy New Year full of miracles and discoveries everyone!

DSC_3314

Daniel Shiffman’s book “The Nature of Code” that Simon had already largely read online and now also reads before bed. It also comforted him recently when he was in pain, he cuddled up of the sofa with this big friendly tome on his lap.

dsc_33401897498871.jpg

Daniel Shiffman signed the book for Simon:

dsc_33441647117253.jpg

dsc_33421879896746.jpg

Siraj Raval stepped out of the YouTube screen straight into our Antwerp apartment on December 31. Simon has been following Siraj’s channel for months, learning about the types of neural networks and the math behind machine learning. It is thanks to Siraj’s explanations that Simon has been able to build his first neural nets :

DSC_3370

DSC_3364

Schermafbeelding 2018-01-05 om 02.07.56

Flocking System Painting with Pixels

Flocking painting Live Video 8 Aug 2017

This is one Simon’s most beautiful projects recently! Simon saw the idea to link the webcam image to the boids of a flocking system in a video by Daniel Shiffman, but the code featured in this project Simon wrote himself. The Flocking code is based on Daniel Shiffman’s example from his book The Nature of Code. (Flocking is a steering behavior that consists of separation, alignment and cohesion – which are also steering behaviors – combined).

Simon’s sis also posed for the camera:

Flocking painting Live Video 8 Aug 2017 2

Simon is also about to make a JavaScript version of this fun project, because JavaScript allows to host it easily online, so that everyone can play with it. With JavaScript, he may even be able to write it in an online editor, so there won’t even be a need to host it. Check in later for an update to this post!

UPDATE: Simon encountered a problem trying to translate his Flocking System Painting with Pixels into JavaScript: P5 runs much slower than Processing after Simon added steering behavior. He doesn’t know how to solve this. Simon’s JavaScript code is online at https://codepen.io/simontiger/pen/ZJKBbN?editors=0011

Back to Attractor with ToxicLibs

Simon returned to his old Attractor sketch in Processing once again, now adding some new functions:

The code original came from Daniel Shiffman’s book The Nature of Code, Chapter 5 (Physics Libraries) and from the ToxicLibs library, but Simon has customized it quite a bit.

Error with Genetic Algorithm. What is wrong?

Simon was almost done translating Smart Rockets example no. 2 (Smart Rockets Superbasic) from Daniel Shiffman’s The Nature of Code, from Processing (Java) into JavaScript in Cloud9, when he got an error using genetic algorithm: the dna seems to be undefined while Simon did define mom and dad dna.

This is Simon’s translation online in Cloud9: https://ide.c9.io/simontiger/smart-rockets#openfile-README.md

This is when he first discovered the bug and tried different solutions:

And this is the same project before he introduced the genetic algorithm:

In the next video Simon boasts he found two errors in his code and hopes that the problem would be solved, but alas, the rockets still vanish from the canvas after a few seconds:

Simon is officially stuck here.

On the positive side, this project did get us to read more about the actual human DNA and the way it works.

 

Thoughts on Fidget Spinner Simulation

DSC_0420-1
In his recent Live Stream, Daniel Shiffman announced he would make a fidget spinner simulation in the near future. Inspired by this idea, Simon has jotted down some code for the fidget spinner project. The code and part of the code description both come from The Nature of Code, Example 2.6. Simon explains that the code below has a non-static radius, because he is dealing with x and y coordinates and not angles (i.e. not spinning but moving to where the mouse is). He says he is going to use that code as a foundation. The second step will be to rely on angles instead of x and y coordinates. The third step will be to rotate have the fidget spinner keep rotating and to apply a friction force to make it stop eventually.
Simon recorded this video, where he ponders on the possibilities for the fidget spinner code:
Simon wrote the rest of this post:
Description:
This is the code for clicking and dragging an object around the screen.
To do that, you need the following data:
  • mass (radius of the object)
  • location (position of the object)
  • dragging (Is the object being dragged?)
  • rollover (Is the mouse over the object?)
  • dragOffset (offset for when the object is clicked on)

And the following functionality:

  • clicked (checks if the object is hovered over and sets dragging to true)
  • hover (checks if the object is hovered over and sets rollover to true)
  • stopDragging (sets dragging to false)
  • drag (moves the object around the screen according to the mouse)
Code and Pseudocode:
Fidget Spinner Simulation
 – Prepare mouse interaction code
  – Data (mass, location, dragging, rollover, dragOffset)
  – Functionality (clicked, hover, stopDragging, drag)
  – Code (Mover)
   – Variables
float mass;
PVector location;
boolean dragging = false;
boolean rollover = false;
PVector dragOffset;
– Functions
void clicked(int mx, int my) {
  float d = dist(mx,my,location.x,location.y);
  if (d < mass) {
    dragging = true;
    dragOffset.x = location.x-mx;
    dragOffset.y = location.y-my;
  }
}

void hover(int mx, int my) {
  float d = dist(mx,my,location.x,location.y);
  if (d < mass) {
    rollover = true;
  }
  else {
    rollover = false;
  }
}

void stopDragging() {
  dragging = false;
}



void drag() {
  if (dragging) {
    location.x = mouseX + dragOffset.x;
    location.y = mouseY + dragOffset.y;
  }
}
  – Code (Main)
   – Variables
Mover m;
   – Functions
void draw() {
  m.drag();
  m.hover(mouseX,mouseY);
}

void mousePressed() {
  m.clicked(mouseX,mouseY);
}

void mouseReleased() {
  m.stopDragging();
}

Preparing to give Dad some Processing Lessons

Simon has been giving Dad some lessons in Processing (Java), following the chapters in Daniel Shiffman’s book The Nature of Code. The have already finished Chapetr 1 (Vectors) and moved on to Chapetr 2 (Forces). I hadn’t realized until recently however that Simon doesn’t simply download all the examples for the lessons from the Processing website but manually writes them over from the html version of the book instead (to style them the way they are in the book, he said). It’s a amazing how organized he is at doing that and saving his files in separate folders.

Testing his examples Simon actually found a mistake in the book and Daniel Shiffman asked him to create an issue about it on the book’s GitHub’s page: https://github.com/shiffman/The-Nature-of-Code/issues/133

DSC_0120

Box2D into Codea, Java into Lua

Several recent translations of Box2D examples (from Daniel Shiffman’s book The Nature of Code) into Codea, that is Processing (Java) into Lua. Both Box2D and Codea are physics libraries.

Surface:

Revolute Joint (Windmill):

Car: