Spin it up and down Hydra Sketch

yet another Hydra sketch running on the Tech Preview version of Sonic Pi available to patreon supporters of Sam Aaron. This one controls colour, speed and size of the sketch picture and also generates a musical accompaniment using built in synths and samples.

In the video the sketch output is sent to a browser window with sonic pi in transparent mode in front of it.

Code below

#Spin it up and down by Robin Newman, Febraury 2023
hydra "solid(0,0,0).out(o0)"
set_link_bpm! 30
link
set :finish,false

use_synth_defaults amp: 0.5
#developed from Alexandre Rangel hydra sketch

t=2*Math::PI
pt=[-1,1]
with_fx :reverb, room: 0.6,mix: 0.7 do
  live_loop :b,sync: :music do
    sample :drum_snare_hard
    sample :ambi_glass_rub, rpitch: note(:c4)-note(:fs4)+[0,-12].choose
    tick
    s1=["0,1,2","1,1,2","1,2,1","1,1,2","1-1,2"].look
    c1=["0,1","1,0"].look
    i=rrand_i(0,1).to_s
    sc=["1","1.5","2"].look
    sp=(1* current_bpm/60).to_s
    
    hydra "
speed="+sp+"
shape(99,.15,.5).color("+s1+")
.invert("+i+")
.diff( shape(240,.4,0).scrollX(.2).color("+c1+",.75))
.diff( shape(240,.4,0).scrollX(-.2).color("+c1+",.75))
.diff( shape(240,.4,0).scrollY(.2).color("+c1+",.75))
.diff( shape(240,.4,0).scrollY(-.2).color("+c1+",.75))
.rotate( ()=> Math.PI*Math.sin(time/2))

//.mask(shape(999,.56,.0)) //this line can be used instead of the following
.mult(shape(999,0.56).thresh(0.4,1e-6))

.scale("+sc+"/2.5,1,()=>window.innerWidth/window.innerHeight)

.out()
"
    
    if current_bpm <120
      div = 2
    else
      div = 4
    end
    sleep 2*Math::PI
    if get(:finish)
      hydra "solid(0,0,0).out(0)"
      stop
    end
    set_link_bpm! (ring 30,60,90,120,180,240,360,480).mirror.tick(:lbpm) if look%div==0
  end
  live_loop :music do
    set :finish,true if vt>170 #set finish time
    sample :ambi_glass_rub, rpitch: note(:c3)-note(:fs4),sustain: 0,release: t/2,pan: 1
    
    puts "current bpm",current_bpm
    use_synth :blade
    density dice(2) do
      play scale(:c4,:minor_pentatonic,num_octaves: 2).choose,release: t/4,pan: [1,-1].choose
    end
    sleep [t/4,t/10].choose
    stop if get(:finish)
  end
  
  live_loop :music2,delay: t/8 do
    sample :ambi_glass_rub, rpitch: note(:c2)-note(:fs4),sustain: 0,release: t/2,pan: -1
    puts "current bpm",current_bpm
    use_synth :fm
    density dice(2) do
      play scale(:c3,:minor_pentatonic,num_octaves: 2).choose,release: t/4,pan: [1,-1].choose
    end
    sleep [t/4,t/8].choose
    stop if get(:finish)
  end
  
end#reverb

There ar two alternaitve lines in the Hydra code, as I have discovered that the .mask command doesn’t seem to work exactly the same on the in-built Pi version as it does when running on the hydra.ojack.xyz site. It seems to give a white background in the mask rather than a black one. The alternative .mult command does give a black background

1 Like

This is really nice. I like what you have done with the bpm.

Hydra looks great :slight_smile: