Computer Simulations in Physics. Numerical modelling of natural phenomena. All written by me in C/C++/HTML5. Most of them are with the code available from me,
Wednesday, March 28, 2018
FELP.PL - Physics Apps for Kids
I recently gave two lectures about physics and computer science in my kids school (2018-02). The lecture covered simple physics experiments plus some software show and self playing.
The kids were very OK with it and - because this is hard for them to type and find internet adresses of those many scattered web toy I made simple linking website, named it felp.pl and published. Enjoy!
I would say these apps are for children at age 2-102. Keep in mind, not all the apps here are mine - some of them I wrote by myself but to some of them I simply link there. Anyway, I will be happy to get some feedback on that and ideas what more to include here!
Wednesday, March 14, 2018
Mean Square Displacement in 1D Random Walk
Mean Square Displacement in 1D Random Walk
by Maciej Matyka
I realized that calculating MSD (mean square displacement) may be a little tricky for students and beginners. Have a look here, this may help to demistify it a little bit. It is a C++ implementation based on simple 1D random walk.
Reference: https://en.wikipedia.org/wiki/Mean_squared_displacement
-------------------------------------------------------------------------------------------
Results:
-------------------------------------------------------------------------------------------
/**
* Mean Square Displacement
* Definition: https://en.wikipedia.org/wiki/Mean_squared_displacement
* Implementation by Maciej Matyka
* 14-03-2018 http://panoramix.ift.uni.wroc.pl/~maq/eng/
**/
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(void)
{
srand(time(NULL));
float x0=0, y0=0;
float x=x0,y=y0;
float xn = 0; // position at step n
int STEPS = 100000;
float averagex =0;
float msd = 0;
for(int N=0; N<1000; N++)
{
averagex =0;
msd = 0;
for(int s=0; s<STEPS;s++)
{
x=x0;
for(int t=0; t<N; t++)
{
float dx = rand()/float(RAND_MAX); // 1d random walk
if(dx>0.5) dx=1; else dx=-1;
x = x+dx;
}
averagex = averagex + x;
msd = msd + (x-x0)*(x-x0);
}
averagex/=(float)STEPS;
msd/=(float)STEPS;
cout << N << "\t" << averagex << "\t" << msd << endl;
}
}
-------------------------------------------------------------------------------------------
by Maciej Matyka
I realized that calculating MSD (mean square displacement) may be a little tricky for students and beginners. Have a look here, this may help to demistify it a little bit. It is a C++ implementation based on simple 1D random walk.
Reference: https://en.wikipedia.org/wiki/Mean_squared_displacement
-------------------------------------------------------------------------------------------
Results:
| Exeplary trajectory of particle in 1D |
| MSD calculated with the code in this post. |
-------------------------------------------------------------------------------------------
/**
* Mean Square Displacement
* Definition: https://en.wikipedia.org/wiki/Mean_squared_displacement
* Implementation by Maciej Matyka
* 14-03-2018 http://panoramix.ift.uni.wroc.pl/~maq/eng/
**/
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(void)
{
srand(time(NULL));
float x0=0, y0=0;
float x=x0,y=y0;
float xn = 0; // position at step n
int STEPS = 100000;
float averagex =0;
float msd = 0;
for(int N=0; N<1000; N++)
{
averagex =0;
msd = 0;
for(int s=0; s<STEPS;s++)
{
x=x0;
for(int t=0; t<N; t++)
{
float dx = rand()/float(RAND_MAX); // 1d random walk
if(dx>0.5) dx=1; else dx=-1;
x = x+dx;
}
averagex = averagex + x;
msd = msd + (x-x0)*(x-x0);
}
averagex/=(float)STEPS;
msd/=(float)STEPS;
cout << N << "\t" << averagex << "\t" << msd << endl;
}
}
-------------------------------------------------------------------------------------------
Monday, March 12, 2018
2D Ripple Algorithm
2D Ripple Algorithm
by Maciej Matyka, Wrocław, 2018-03-13(play here)
Once upon a time... I saw this on the famous Hugo Elias website (bouncy 2d graphics website). It was around 1998. Now I found it's web archived version of the algorithm and quickly done some re-implementation in javascript.
The basic algorithm works on two 2D tables. You ping-pong the data between tables, so you first run from 1 to 2 and then back from 2 to 1.
The main wave propagation goes like this:
for each particle (x.y) calculate:
map2(x,y) = (map(x-1, y) +
map(x+1, y) +
map(x, y+1) +
map(x, y-1)) /2 - map2(x,y)
map2(x,y) = map2(x,y) * damping
where damping is a number between 0-1. After one step map becomes map2 and vice-versa.
It is worth to add some smoothing as well (simply average each pixel between rendering).
Note: I discovered that using single pixel as the starting point for the wave gives really ugly picture and, thus I put the 3x3 picel each time I want to seed the wave.
Below is the first result of the model implemented in 2018 by me.
The app will be soon available at http://felp.pl.
Wednesday, February 28, 2018
Soda Constructor (Revisited)
Soda Constructor (Revisited)
(2026 - New website: https://maciejmatyka.github.io/lovesoda/0.36cbeta.html
https://maciejmatyka.github.io/constructor/ )
(2024 version - here)
(2020 - here)
(2019 - here)
(2018 - here)
Yeah, that was the famous Soda Constructor from Ed Burton and Soda company. It was the experience one never forget - the app was fabolous. It was Java based applet in which you could build simple spring-mass system based models with muscles and make them live.. This app was very popular and many people created their own robots, walkers, etc. Later, Soda has changed the app into something bigger, there was Soda Zoo, Soda Race and even the second version of Constructor was released. For me, however, none of them were that magical as the original one.
![]() |
| Original Soda Constructor by SodaPlay. |
Soda Today
Now, as we have 2018 and I am after more than 15 years of my studies in physics doing stuff like simulations I realized that it would be funny to show this app to my kids. And what? Nothing. There is nothing left in the internet - the app dissapeared same as the Java applet technology. There was some try to raise Kickstarter campaign to get Soda back, but it was not successful.
Therefore, I didn't wait long and decided to write my own version of the app from scratch. From the physical point of view it was rather simple, eventually this is a bunch of springs, masses and some time varying sinous muscles. Nothing fancy, especially that whole thing works fine with Euler integrator which surprised me a lot. I used several sources to make it as close as possible to the original app and - it is 50% done I'd say. While I am not going to repeat the sound synhesis part (is it needed anyway?) I decided to make the physical part as close as possible to original.
I recommend you to play it now on the San Jose website.
Results
Please have a look below to see some of the creations I've made with the program.
San Jose was written from scratch. This is the main view, where you can
either go into construction or play mode. The default object of dainty
walker based model is loaded.
|
![]() | |||
| Adding more masses attached in the back and increase of gravity made the walker less efficient (this is the result of 2018 app). |
I added one additional feature to the app - you may easily load/save your model by using its internal text format for the models. The user may either paste his model from clipboard or edit values by hand. Of course models done using graphics editor may be easily converted to this format (by clicking save). I hope this (easy) way people may share their creations.
Possibilities
There are many ways the app may be used, please have a look on the talk given by the author of original app Ed Burton. Shortly after I wrote my version I realized there is someone doing the same stuff as open constructor as well as springy thingies from KrazyDad. However, all those versions have their own flavour and I think mine has the spirit :-)
Enjoy, it's free. Play it here and have fun!
Maciej Matyka, 2018-03-01, Wrocław
Contact: maciej.matyka@gmail.com
Constructor2018 is the part of http://felp.pl project
ps My collection of links important for the Soda Constructor project and its history:
https://web.archive.org/web/20040212024753/http://www.warptera.com/
https://web.archive.org/web/20031208183323/http://www.sodaplaycentral.com:80/models.php
http://www.lightcycle.org/workspace/spring_set/spring_set_appvar.pde
https://processing.org/discourse/alpha/board_Contribution_Simlation_action_display_num_1083008179.html
http://www.lightcycle.org/workspace/spring_set/
http://www.tom-carden.co.uk/p5/soda_rip/appvar/index.html
https://web.archive.org/web/20031210110220/http://www.sodaplaycentral.com:80/articles/mss.php
https://web.archive.org/web/20031208180149/http://www.sodaplaycentral.com:80/articles/articles.php
https://web.archive.org/web/20160417141419/http://www.warptera.com:80/
https://web.archive.org/web/20050309104454/http://sodaplay.com:80/constructor/beta/daintywalker.xml
Subscribe to:
Posts (Atom)
-
Soda Constructor (Revisited) (2026 - New website: https://maciejmatyka.github.io/lovesoda/0.36cbeta.html https://maci...
-
Introduction This tutorial is the first part of the mini compute shader serie. See part 2 on continuation with more specific fluid flow 3D ...
-
This is the list of shaders I will live code and present (teach) during the Xenium2022 demo party in Katowice. Feel free to learn and enjoy...




