In this experiment I intruduce a function for generating parabolas based on start point, end point and height. I then showcase two of its uses.
#the parabola function takes the two x-intercepts and the y coordinate of the vertex, as well as an x value.
#it returns y of x for the parabola defined by these properties.
#this can be used to create a wave effect that starts at p, ends at q and in the middle has the highest point k.
define :parabola do |p, q, k, x|
parabola = -((4*k)/(1.0*((p-q)**2)))*(x-p)*(x-q)
end
#this wave structure can be used to pronounce phrases in a more natural way.
#in this example, a_range is the strength of the effect, ranging from x > 0 to 1
a_range = 0.5
#the wave structure can also be used to help with generating melodies.
#it can be used to guide our melodic contour
#in this example, m_range is used to determine how extreme out hill or swoop should be.
#m_range can be anything but 0. positve for a hill, negative for a swoop
m_range = 10
#for controlling the melody, you have a few more options
#the random seed for the melody
use_random_seed = 1234
#the scale we use
our_scale = (scale :e, :minor_pentatonic)
#where we start. this value is measured in steps within the scale
start_at = 0
#how far we can distance ourselfs from the note the parabola suggests
m_deviation = 3
melody = (ring)
16.times do
#the melody is generated here
melody = melody + (ring (chord_invert our_scale, start_at + rdist(m_deviation ,0) + parabola(0, 15, m_range, (range 0, 16).tick))[0])
end
live_loop :foo do
use_synth :piano
#we make a pause every 8 notes to seperate the phrases more clearly
if (range 0, 16).tick != 15
#here we apply our parabola shape to the amplitude.
#note that we only use 14 as our q, rather than 15, since the pause we make isn't part of the phrase
play melody.look, amp: 1-a_range+parabola(0, 14, a_range, (range 0, 16).look)
end
sleep 0.25
end