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:

Neat! I want that :slight_smile: I see you are on a Mac. I have just compiled the latest dev branch on Ubuntu 22.04 (really Kubuntu, i. e. with KDE, but get neither Hydra nor transparency. Do you know if these features are not available on Linux?

You need to install and run Compton to get the transparency to work on Linux. There is code in there to launch it for raspberry pi in the daemon.rb file which could be added to Linux. I have built with hydra for RPi and I think it works for Ubuntu too but I would advise installing erlang and elixir using asdf and Choi’s the latest versions for each. Haven’t got access to my Linux kit till end of the eeek or I could check.

Robin

Hi Robin, many thanks! I’ll try that am come back. Ben

Good, transparency works. Compton had already been there, but was not enabled :smile: As to Hydra:
I want to give it a try. Any hints as to what params need to changed in the build process are welcome.

And a general question: What is the advantage of driving hydra from SP code over sending MIDI control messages to a browser running Hydra? Integrated Hydra code gets the Ruby code quite muddled. Is timing where the integrated solution scores?

Hydra is just the first of a number of visual systems I’m experimenting with. Processing.js is another. The Tau system is designed to be flexible and will be a fabulous system for UI experimentation in general.

With regard to Hydra specifically - the main advantage is the convenience - in that you don’t need an internet connection, to fire up an additional browser or to set up MIDI routing from Sonic Pi to the browser. Another benefit is the timing which lets you hotswap the Hydra code in time with the beat. Finally something fun to experiment with is the ability to run multiple additional external browsers and hot swap the running Hydra sketches in all of them simultaneously in time.

Of course, if Hydra running in an external browser is working for you - definitely stick with that! I’m certainly not making any claims that Sonic Pi’s integrated Hydra stuff is any better in any way. Working with an external Hydra system is going to give you access to the most recent version with the most likelihood of compatibility with community sketches.

Many thanks for all the details, Sam! I’ll sure try it both ways, intregrated and built-in, and I’m looking forward to all there is yet come with Tau.