Anna Larionova

Interaction Designer



Anna Larionova

Interaction Designer


Interactive Simulation

Client Timeframe

1 week, Fall 2023

Working Code





Create a sketch that would simulate an existing natural system - look at physics, biology, and other natural sciences for good examples. Start with the environment - where is the system situated? What are the forces the environment might exert on the system? Examine the agents in the system, their relationships to each other and the environment they are in. The look at how this system would develop over time. What are the rules that you are going to come up with, what are the parameters you are going to feed into them and what effect will the changes have on the development of the system.
  • create classes of entities to represent the components of the system
  • use vectors to represent forces existing in the system
  • use randomness or noise to generate at least one
  • add direct or indirect mouse or keyboard controls

The Idea

A solar system where the user can manipulate the rules of physics by changing values.


I found Daniel Shiffman’s Coding Challenge code:

Planet sun;

void setup() {
    size(600, 600);
    sun = new Planet(50, 0, 0);
    sun.spawnMoons(5, 1);

void draw() {
    translate(width/2, height/2);;

Unfortunately this has more to do with translation than actual forces so I kept searching. On I found a beautiful Processing sketch that looked like it dealt with Kepler’s laws of planetary motion.

These were the two functions I looked at in particular to understand the calculations they made for this effect.

void update() {
if (drop) {
qx = 0;
qy = 0;
// Catch it when it gets close to the center
else if ((qx > -5 && qx < 5) && (qy > -5 && qy < 5)) {
drop = true;
} else {
// Approximate calculation using Runge-Kutta method
RK( qx, qy, px, py, 0);
RK( qx+0.5*qxk[0], qy+0.5*qyk[0], px+0.5*pxk[0], py+0.5*pyk[0], 1);
RK( qx+0.5*qxk[1], qy+0.5*qyk[1], px+0.5*pxk[1], py+0.5*pyk[1], 2);
RK( qx+qxk[2], qy+qyk[2], px+pxk[2], py+pyk[2], 3);

qx += (qxk[0] + 2*qxk[1] + 2*qxk[2] + qxk[3])*(1.0/6);
qy += (qyk[0] + 2*qyk[1] + 2*qyk[2] + qyk[3])*(1.0/6);
px += (pxk[0] + 2*pxk[1] + 2*pxk[2] + pxk[3])*(1.0/6);
py += (pyk[0] + 2*pyk[1] + 2*pyk[2] + pyk[3])*(1.0/6);
ellipse(qx, qy, radi*2, radi*2);

void RK(float qx, float qy, float px, float py, int n) {
float q, qi3;
q = sqrt(qx*qx + qy*qy);
qi3 = 1.0/(q*q*q);
qxk[n] = px/M*dT;
qyk[n] = py/M*dT;
pxk[n] = -GM*M*qx*qi3*dT;
pyk[n] = -GM*M*qy*qi3*dT;

Here’s another sketch on that is closer to the user-input aspect of my original idea.

Then I went to my friend, ChatGPT and started a conversation to try to make this work.

My first prompt was:“can you write a processing sketch that simulates planetary orbit but lets the user manipulate the laws of physics“

To which it made some code was running some errors (missing functions and error codes), so we did a little back and forth to sort it out.

What you see on the right is very close to what I’m going for!

I wanted to add the ability to adjust the mass of the sun with a slider, which also affects it’s visible size.

I’m using this equation to do this:sunDiameter = sqrt(mass / PI);

and the slider line is as follows:
sunMassSlider = cp5.addSlider("Sun Mass").setPosition(10, 70).setRange(100, 5000).setValue(sun.mass);

The look of the sliders is default for now.

It works kind of well as a game whose object is to maintain an orbit, but when the planet goes flying it does not come back.