Looking for math everywhere

Funny how, even when training some pretty straightforward (and boring) arithmetic or Dutch reading, Simon tries to introduce more complex notions like here,

the floor, ceiling and round functions while solving a simple arithmetic word problem:

DSC_0450

DSC_0452

and lexicographic order, while sequencing Dutch story sentences:

DSC_0457

RGB Project in Codea using SVG Color Map

On Monday this week Simon spent hours converting hexadecimals into RGBA values for the 140 colors supported by all modern browsers and creating a color file in Codea. He used the w3schools color map available at https://www.w3schools.com/colors/colors_groups.asp and an html color codes converter http://html-color-codes.info/ 

Some of the color names were quite exotic (like Chartreuse or Bisque ), and we looked those up together in the dictionary. We also took a very close look at the relation between red, green and blue values and found out that red was added every time to make colors lighter, even in shades where you would not expect any red.

Simon later made a nice design pattern in Codea using the color file:

 

 

Modulus Counting in Processing

Simon wrote a modulus counting program in Processing after we were discussing why

1 % 2 = 1 and why 2 % 4 = 2. He basically told me he simply knew 1 % 60 equals 1, but he didn’t know why.  We realized later that the strange result comes from the fact that if a number (the divisor) fits into another number (the numerator) zero times then, in modulus counting, that numerator becomes the excess.

 

DSC_0407

Infinite Line in Processing. Simon’s own code.

A beautiful project in Processing (Java), Simon’s own code, resembling  an El Lissitzky painting that you can control and change with the mouse (without Simon knowing El Lissitzky). Resulted from thinking about and playing with infinite line and line segments. Simon used the following formula: slope times x plus yIntercept.

Infinite Speceship 13 Jun 2017 2

Infinite Speceship 13 Jun 2017 1

 

 

 

DSC_0410

Diffusion-Limited Aggregation translated into Codea

Simon translated Daniel Shiffman’s Diffusion-limited Aggregation Coding Challenge into Codea. The coding challenge explores the generative algorithm “Diffusion-Limited Aggregation”, whose visual pattern is generated from random walkers clustering around a seed (or set of seed) point(s).

Unfortunately, every time the iPad falls asleep the application seems to stop, so we never got a sizable tree.

 

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();
}

For Mom’s birthday 

For my birthday, Simon made me some Fireworks:

He made them look even better the following day, by adding trails:

The code is Simon’s translation into Lua (the language of the Codea app) of Daniel Shiffman’s Fireworks Coding Chalenge (JavaScript).

We’ve also thoroughly enjoyed our birthday weekend at Brugge and especially Knokke. Fine to discover such fabulous beaches in the neighborhood. Simon loves water. Perhaps, because it is somehow related to the fluidity and of his mind and because of the freedom water provides to his body.