Sonic Pi Hydra Rotator sketch

Another sketch using Sonic Pi 5 Tech Preview. Shows how you can alter the sketch as it runs. This one uses a built in loop sample to priced sound. Various parameter are changed to alter the sketch as it runs.
Thanks to Nato Hieda for the idea of using multiple colorama with a gradient feed.
code is shown below.

#Sonic Pi 5 Tech Preview Hydra example
#coded by Robin Newman, February 2023
#shows techniques for controlling and aptering a sketch in a live_loop

use_debug false
set :clobber,false #used to stop the sketch
t=2*Math::PI #time unit
at 108 do #time till clobber is set true
  set :clobber,true

with_fx :reverb, room: 0.8,mix: 0.7 do
  sample :drum_roll,amp: 4 #initial drum roll before the start
  sleep t
  live_loop :Hydra do
    #the following paramters generated as strings are inserted in the hydra sketch string
    g=[0.1,0.2,0.4].reverse.tick.to_s #gradient
    c=[0.01,0.02,0.05].look.to_s #colorama parameter
    rxy=["1,1","1,2","2,1","1,3","3,1"].look #repeat x,y parameter
    k=[5,6,7,8].choose.to_s #kaleid parameter
    i=[0,0,1,0,1].look.to_s #invert paranter: o gives no inversion
    puts "g: #{g} c: #{c} rxy: #{rxy} k: #{k} i: #{i}"
    sample :drum_cymbal_hard,amp: 2
    #next line sets up hydra code in a string and calls it with hydra function
    hydra "speed = 1
.rotate(()=> Math.PI/2*Math.sin(time%360 )).invert("+i+")
  .scale(1,25/44.0,1) //set this to adjust for screen aspect ratio 25/44 was the ratio of hegith to width in my setup
.scale(0.5) //reduces size of pattern
    if get(:clobber) #shut down initiated
      sample :drum_roll,amp: 4 #drum roll again during final pattern
      sleep t
      hydra "solid(0,0,0).out(o0)" #blank screen
      sample :drum_heavy_kick,amp: 4 #final drum hit
    sample  :loop_mika,beat_stretch: t #loop_mika repeated with beat stretch t
    sleep t #time between sketch changes
1 Like