Calculating Euclidean Rhythmns using the Bresenham Algorithm

Nikolaus Gradwohl2017-11-24T06:43:52+01:00

Recently I started playing with euclidean rhythms and implemented the bjorklund algorithm shown in the paper by Godfired Toussaint in ruby. The implementation isn't really rocket science (actually it's ring accelerator science :-)) but it uses recursive function calls, two arrays, multiple stages, ... and I had the feeling that this is far more complicated than it needs to be. After reading several posts, blogs and papers about the implementations of the algorithm I read somewhere that the algorithm produces the same result as the bresenham algorithm - at first I ignored the sentence and unfortunately I have no idea anymore where I read it but today I implemented a simple version of it an the results I get are the same as my recursive version - or rotations, which is fine because you usually loop over the sequences and are free to choose a starting point - so in case anyone is interested here is my bresenhamish method for calculating euclidean rhythms in ruby - shouldn't be too complicated to port it to different languages

def eucledean(k,n)
    f = 1.0*n/k
    res =,0);
    a = 0
    k.times do |i|
        res[a.to_i] = 1
        a += f
    return res

(1..8).each do |i|
print eucledian(i,8)
print "\n"

and this are the results I get for the 8 possible rhythms with 8 steps

[1, 0, 0, 0, 0, 0, 0, 0]
[1, 0, 0, 0, 1, 0, 0, 0]
[1, 0, 1, 0, 0, 1, 0, 0]
[1, 0, 1, 0, 1, 0, 1, 0]
[1, 1, 0, 1, 1, 0, 1, 0]
[1, 1, 1, 0, 1, 1, 1, 0]
[1, 1, 1, 1, 1, 1, 1, 0]
[1, 1, 1, 1, 1, 1, 1, 1]
read more ...

ruby rhyme generator

Nikolaus Gradwohl2012-07-08T09:43:04+02:00

I made a ruby rhyme generator - a simple commandline utility to generate nonsense rhymes like this

    si ninu si - na ma boto
    mo sito mo - de sa tato

    te dini ma - no ne dibi
    di nodi te - be be sebi

or this

    bo nibe bomeku
    te dibu domiku

    nu sibe keteso
    me tiba beneso

you can specify the number of verses and the rhythmic pattern on the commandline

Usage: rhyme [options]
    -p, --pattern PATTERN            the rythmic pattern
    -c, --count COUNT                number of verses

the default pattern is 121-112 like in the first example

read more ...

Curling Animation II

Nikolaus Gradwohl2010-08-22T14:02:35+02:00

I made another animation with Context Free Art and a small ruby script. The scroll down to see the sourcecode I have used for this file. This animation uses the same technique i used for my first one

Curling Recursion 2 from Nikolaus Gradwohl on Vimeo.

read more ...

Blinking Logfile Map

Nikolaus Gradwohl2010-06-05T18:17:00+02:00

I always wanted to see where the readers of my blog are comming from, so I took a picture frame and inserted a world map, a handfull of leds and an arduino. Some soldering and some rubyscripts later I had my hardware geo-aware logfile visualization.

I have a script running at the server that parses new ip adresses from the log file and geocodes them. Than the continent code is sent to my mac where i have a little script that forwards the continent code to the serial port. And finally the arduino in the picture frame is making the leds blink. The whole project was hacked together as a weekend project so the scripts might need some "fine-tuning" :-)

This is my day 5 project for 30DaysOfCreativity

so please read my blog to make the leds blink :-)

blinklog blinklog

read more ...

Curling Recursion

Nikolaus Gradwohl2010-06-03T10:30:00+02:00

I made this animation with Context Free Art and a small ruby script. The scroll down to see the sourcecode I have used for this file

Curling Recursion from Nikolaus Gradwohl on Vimeo.

read more ...

Set operations on ruby arrays

Nikolaus Gradwohl2009-11-28T05:23:00+01:00

Ruby provides some very interesting set operations on arrays.

given the two arrays A and B wich look like this

A = ["A", "B", "C", "D"]
B = ["C", "D", "E"]

There are three set operations we can use that union, intersection and difference.



A | B

contains all elements from both sets without doublicates. So this results in ["A", "B", "C", "D", "E"]



A - B

contains all elements from set A that are not in set B. So this results in ["A", "B"]



A & B

contains all elements that are in set A and in set B. So this results in ["C", "D"]

read more ...

Ruby Caldav Library 0.3

Nikolaus Gradwohl2009-11-07T07:14:00+01:00

have made a new version of my ruby caldav lib.

version 0.3 is a bugfix release, to make it work with the kde4 calendar

read more ...

Mapping linux input events to OSC

Nikolaus Gradwohl2009-09-06T04:48:00+02:00

In linux every input device registers under /dev/input/eventX and sends events in 16 byte blocks. these data chunks contain a timestamp the event type, the event code and a value depending on the event type the semantic of value changes. for a event type 1 (key event) value 1 means pressed and value 0 mean released.

here is a little ruby program that reacts to key press events and sends osc messages. which could trigger drum sounds, start play back, ...

key press events are not only sent by keyboards but also by mice, joystics, gamepads, a DDR mat, a buzz buzzer, ...

the code example is used to map keys of my PS3 Controller to drum sounds.

require 'osc';

c =

hh ='/drum', 's', "hh" )
bd ='/drum', 's', "bd" )
sn ='/drum', 's', "sn" )"/dev/input/event7") do |f|
  while true
    event ="llSSl")
    time = event[0] + event[1] / 1000000.0
    type = event[2]
    code = event[3]
    value = event[4]

    puts "Ti: #{time} T: #{type} C: #{code} V: #{value} " if type == 1

    c.send( bd, 0, 'localhost', 3334 ) if type == 1 && code == 298 && value == 1
    c.send( sn, 0, 'localhost', 3334 ) if type == 1 && code == 293 && value == 1
    c.send( hh, 0, 'localhost', 3334 ) if type == 1 && code == 303 && value == 1

The code was inspired by 2 articles i found recently the first one is about how to use a DDR-mat to trigger Drum Sounds and the second one shows how to read the accelerometer data from a openmonoko phone

read more ...

ruby osc seqencer version2

Nikolaus Gradwohl2009-04-13T14:57:00+02:00

i updated my osc sequencer in ruby. now it doesn't just send osc events but also react to it. i made a small processing sketch that sends osc play,pause,stop events for each track in the sequencer. i also refactored the ruby code a bit, to use classes. next steps i plan are to separate the sequencer code from the sequences and allow sequences to be added or deleted at runtime via osc messages.

the code isn't very reusable now, so i still considere this more as a prove of concept, but i like the idea of separating the frontend and the backend via osc events and having sequences that can run independently.

that should enable some nice osc controlled audio/video installations.

write me a comment or mail if you have some ideas for improvement or if you use the code in one of your projects

read more ...

processing ical-flowers-2.0

Nikolaus Gradwohl2009-02-15T08:15:00+01:00

I made a new version of the ical flowers sketch i wrote in dezember. This time it doesn't only show a flower for every event in my calender, it also shows

  • the current weather (using the rubyweather library)
  • the current temperature outside
  • the min/max temperature outside
  • the current temperature inside ( using my arduino i2c thermometer sketch)
  • the sky color changes depending on the current time

ical-flowers screen1

ical-flowers screen2

the system consists of a ruby-proxy, an arduino sketch and a processing sketch.

the ruby proxy starts a web-server on port 2000. It fetches the current weather using the rubyweather gem, fetches the events from the configured caldav calenders, and fetches the current temperature from the arduino using ruby-serial

the arduino sketch is basicaly the same as in this blog post. the only change is that the arduino only sends the temperature when the host sends a 'C' over the serial line

the processing sketch finally fetches the data via http from the proxy and displays it ( using my icap4p library. the screen is updated every 1/2 hour using the method described here

the code can be downloaded here

it's published under the LGPL

have fun :-)

read more ...