Software development

This page features a collection of software development projects I have worked on. In most cases the goal was to gain a better understanding of a specific programming language, programming technique or library. For this reason, I have been driven mainly to experiment with new concepts, rather than implementing features in my projects.

Basic Game Engine

C++, SDL

“BGE” for short. This was a great opportunity to learn about SDL (Simple Directmedia Layer), a library especially useful for writing games and interactive GUIs.

Rather than developing a specific game, I started by exploring the library’s capabilities and implementing some general behaviors, such as animations, particles, keystrokes and events. To test my code, I designed a simple stick-figure based rpg, which you can see in the video. The map is a simple implementation of  a procedurally generated maze.

Chemistry Graphics

C++, GTKmm, Cairomm, LibXML

This is my longest-running project, and one I did not work on just for learning, but because I believe it can be useful.

Working and studying as an organic chemist, I have accumulated countless hours using professional softwares for drawing organic chemistry diagrams, and I have come to realize many flaws and problems, which in my opinion would be easy to fix. To name just a couple: command-line utilities to export figures in batch and compatibility with linux-based systems.

On the other hand, the alternatives that do provide these functionalities are oriented towards computational chemists (I guess), and the diagrams they produce are visually unappealing and unlikely to be used in scientific publications.

I coded the Chemistry Graphics library to provide a visually appealing, customizable alternative for drawing molecular diagrams on linux (and possibly other platforms). Initially I used a short script to generate vector graphics via the library. I designed the drawings with the standard program I use, and used my own script and library for exporting them. Obviously this is not a real alternative, as it still requires the problematic software, but at least it allowed me to batch-export.

Lately I started working on a GTK-based user interface, to allow for everything to be done in one place. Although the base library is well developed, the GUI is still in its infancy (you can see in the video it still crashes often).

Screenshot of chemistry graphics editor

Bouncing Balls Simulator

Java

This Java applet simulates the motion and elastic collision of circular particles in 2D, using simple Newtonian’s physics. The initial velocity and position of the particle is set by clicking and dragging the mouse. The color of the particles represents their instant velocity from red (slowest) to white (fastest). By right-clicking, walls can be added to the simulation and the particles will bounce on them.

Screenshot of bouncing balls simulator

Particle Simulator v.1

Java, Gnuplot

This simple program solves the n-body problem in discrete intervals. It is not particularly accurate or efficient, but it allowed me to experiment with different equations describing the interactions between the bodies.

I was particularly interested in simulating collisions between objects with a defined shape in a way to allow fragmentation of the objects themselves. To achieve this, I implemented different interactions regimens based on distance, mimicking bonding and non-bonding situations. If the impact is strong enough, some bonding interactions are broken, resulting in fragmentation of the particle assembly.

With the ideal goal of implementing these algorithms in animations or games, I tried to find computationally efficient force-descriptors and suitable parameters for real-looking collisions.

At this stage I was not interested in developing a graphical user interface, so I rendered the videos with Gnuplot from particle positions generated by my program at every step.

A square object with initial velocity hitting a wall of particles. Rather than breaking or bouncing, the two objects merge into each other via the bonding type interactions. This was not the desired result.

However, note how the two objects maintain their shape until impact. This was only possible after careful tweaking of the force parameters.

Here long-range gravitational interactions are added, causing a particle to fall into a “planet”. Due to the gravitational pull, the objects are not shape persistent and tend to form circular shapes.

Particle Simulator v.2

C++, Gnuplot

The first version of the particle simulator was extremely slow, severely limiting the number of particles per simulation.

I rewrote the program in C++, which allowed me to be more careful about resource usage and increment the number of particles without having to wait tens of minutes for every simulation.

Note that the particle simulator is 3D capable, however, populating the third dimension requires way more particles for the same apparent size on video, so all examples here are in 2D only.

With a larger number of particles at my disposal, I was able to simulate a collision between two round objects (~planets). I was trying to reproduce a situation in which after impact, a smaller satellite would be formed orbiting the main body. Here you do see 2 particles floating about, but this was as close as I got.

The “breathing” effect of the planets is due to the particles starting off on a square grid and quickly rearranging into a more stable hexagonal one.

At this point I had a script to place the particles in an hexagonal grid, to avoid their rearrangement.

This simulation is similar to the “wall” collision in v.1, but a much better result was obtained: The wall appears to break in two as a result of the “bullet” hit, and the bullet bounces back a little. The key to this was implementing different “materials” for the particles, so that wall-wall attractive interactions would be stronger than wall-bullet.

Having different materials allows to forbid motion for some particles, which in this case form an open container around some fluid-like particles.

A “liquid” set of particles is easier to get if particles have longer-range but weak attractive interactions. Solids are more difficult, as strong, but short-ranged attraction forces are needed. Very often this situation is unstable, and the solids “explode” at the start of the simulation.

Reaction Kinetics Simulator

Python, MatPlotLib

MatPlotLib is an incredibly versatile python library for displaying scientific data. This proof-of-concept program generates a nice chart describing the progress of chemical reactions based on the mechanistic steps and rates provided by an input file.

Probably the most challenging part was parsing the input file, while keeping it human-readable.

What a typical input file looks like: every line describes a mechanistic step, and initial concentrations are given at the end.

This is a bit of a favorite for chemists: the Michaelis-Menten kinetics. An enzyme or other catalyst (orange) forms a complex with the substrate (blue) and starts converting it into a product (red). After an initial induction period, the complex concentration is stable and the product form at a steady rate.

This output was produced by the input file shown earlier.

Another interesting scenario is that of an autocatalytic reaction. The more product (B) is formed, the faster the product is formed. After ca. 100 seconds of slow conversion, the reaction “explodes” and all starting material is consumed within 20 seconds. 

Mol2img.py

Python, Cairo

This python script converts .mol2 molecular descriptor files (containing the coordinates of the atoms, as well as their bonding) into a nice looking 3D cartoon.

I made it to generate an artwork for the cover of my PhD thesis featuring cartoons of the interesting molecules I made. In a way the goal of the program is similar to that of the chemistry graphics library I made in C++, but this is much much simpler.

By setting the z-level and a with a little bit of trigonometry, the cartoons provide a good sense of the third dimension, albeit without perspective.

This is what a typical .mol2 file looks like. A list of atoms and their 3D positions are given.

A few interlocked molecules I put through the mol2img.py script.

ASCII-art sidescroller

Java

This is a fun little ASCII-art sidescroller game. It is actually the second chapter to the adventures of “eight the snowman”, who is the main character (literally!). The first chapter was one of the first games I programmed, before I knew anything about graphics, so I was forced to text-only. I wrote this second one as a bit of a challenge: can you make a fun sidescroller using only text?

Interestingly, you can create a level by just typing the characters in a text editor as you want them to appear on the screen! Most characters are treated as walls.

Main menu view of the game. Even the title is ASCII art!

Gameplay of the sidescroller. The character “8” is the player, “o”s are moving enemies and “*” static enemies. The player can shoot “-“s and place steps.

STRAT

Java

Another Java applet! This one is an online multiplayer strategy game. The main goal for me was to use the socket internet interface of the standard java library to connect between multiple computers. I found it to be incredibly simple and powerful, however the game itself was not really interesting.

You start with a base on a grid, there are a few building you can construct and you can create troops and move them around, but that is about it: I did not implement battles or resources.

This is the main client-applet window. Flags indicate the presence of troops, and there are some buildings too.

This is the server-applet running (in text mode). All transmissions between clients and server are logged, such as establishing a connection and requesting a certain action: e.g. “Game new 10 10” requests the creation of a new game on a 10×10 grid.

Commodore 128

6502 assembler

I am the proud owner of a commodore 64 and a commodore 128 computers, of which I am very fond.

These machines are relatively simple, especially compared to modern computers, and yet manage to accomplish amazing things. As I learned more about their inner workings, I figured I could directly program the machine in assembly language, which is actually how many games for the commodore 64 were produced.

This is a small test I did, a ghost figure can be moved on the screen in a maze of walls, until it reaches the goal and the next level loads.

Even graphics and sounds need to be hard-coded. The many limitations of the 64Kb, 8bit computer introduce interesting challenges and workarounds.

The code is written using mnemonics, which translate to processor opcodes or preset values. A preprocessor pass generates a stream of single bytes, containing the whole program.

Firefox plugins

Javascript

This is a collection of self-hosted plugins for the Firefox browser which I created to improve the interface of several web pages I have been using for work. They are hosted here to allow interested colleagues to use them.

To install, simply click on the icon (using firefox).

Fills the NMR booking form for you every time you open the page. Password, group and phone number fields are stored on your browser.

Enhances the GHX user experience, adding colors and import/export features to and from csv files.

© 2022 – Simone Pilon

Edit Template