Sep 25, 2023
I've been "building" an "instrument". Thanks to some samples from Ivan Reese.

To recreate the above you need:

  1. To install LÖVE for your platform (really just Android or iOS since we're talking multitouch in this post.)
  2. Download a special build of MiniIDE containing Ivan's samples.
  3. Paste in the following 70-line script and hit 'Run':
    g = love.graphics
    draw, line, circ, pt, color = g.draw, g.line, g.circle, g.points, g.setColor
    abs,min,max = math.abs, math.min, math.max
    audio = love.audio.newSource
    if od == nil then
        od,ou,omp,omr,okp,okr = love.draw, love.update, love.mousepressed,
    love.mousereleased, love.keypressed, love.keyreleased
    end
    W,H = g.getDimensions()
    -- visuals
    cs, N = {}, 100
    function sq(x) return x*x end
    function dist2(x1,y1, x2,y2)
      return sq(x2-x1) + sq(y2-y1)
    end
    
    -- audio
    ts = {}
    
    function love.draw() -- od()
      for _,c in pairs(cs) do
        circ(c[1],c[2])
      end
    end
    
    function circ(cx,cy)
      for x=cx-N,cx+N do
        for y=cy-N,cy+N do
          local dist = dist2(cx,cy, x,y)
          if dist < N*N then
            color(abs(x-cx)/N, abs(y-cy)/N, 0.5) --, dist/N/N)
            pt(x,y) end end end
    end
    
    function love.update(dt) ou(dt)
      local touches = love.touch.getTouches()
      for _,id in ipairs(touches) do
        if cs[id] then
        cs[id][1], cs[id][2] = love.touch.getPosition(id)
        ts[id]:setPitch(pitch(cs[id][2]))
        end
      end
    end
    
    function pitch(y)
      if y <= H/2 then
        return 2 - y*2/H  -- vary pitch from 2 to 1
      else
        return 1.5 - y/H  -- vary pitch from 1 to 0.5
      end
    end
    
    function love.keypressed(key, ...) okp(key, ...)
      escape()
    end
    
    function love.touchpressed(id, x,y, ...)
      cs[id] = {x,y}
      ts[id] = audio('ivanish/MaternalBowedGuitar.mp3', 'static')
      ts[id]:setLooping(true)
      ts[id]:play()
    end
    
    function love.touchreleased(id, ...)
      cs[id] = nil
      if ts[id] then ts[id]:stop() end
      ts[id] = nil
    end
    
    function escape()
      error('StopScript')
    end
    

One of those 70 lines contains 'ivanish', and I've been playing with that line by varying the sample. (Unfortunately there isn't a way to browse the list, so you have to look inside the love/zip file.)

This post is part of my Freewheeling Apps Devlog.

Comments gratefully appreciated. Please send them to me by any method of your choice and I'll include them here.

archive
projects
writings
videos
subscribe
Mastodon
RSS (?)
twtxt (?)
Station (?)