糖心TV

Skip to main content Skip to navigation

Behind the Code

Our Code:

A copy of the Python code can be found here.Link opens in a new window

There are instructions on the Python file describing how to install required modules and work the user configuration panel.

Brief Summary of the Code:

Our code takes the chosen image and divides it into vertical slices (the amount decided by the user). Then, the image properties in each slice are mapped to certain musical elements, outlined in the table below:

Image Property

Musical Element

Average RGB colour

Degree of scale

Brightest area

Octave of melodic line
Saturation Complexity of harmony
Brightness Dynamics
The code loops through each slice to create the piece of music, until it reaches the end of the image. Finally, the piece ends with a cadence, the type decided by an image property once again:
Image Property Musical Element
Overall most dominant colour of image Type of ending cadence
Other musical elements such as tonality (key of the piece) and instrumentation are decided within the user configuration panel. Rhythm, however, is randomly decided from 7 pre-defined rhythmic patterns. The code also randomly adds rests to the melodic line, with a 12% chance.

Flowchart explaining code:

Here is an explanation of how the code works in more detail, cell by cell.

Flowchart explaining code cell by cell

Let us know you agree to cookies