rubyk

Open source (MIT license) real time, dynamic signal processing tool (patcher). Rubyk is the super glue between many nice tools like Lua, OpenGL, Midi, OpenCV, etc.

Source code

The source code can be retrieved with git on github.com/rubyk/rubyk.

Bug tracking

If anything seems wrong with this library, please open a ticket (if this seems too much, sent an email to the mailing-list).

Current status: alpha (works, but API may change without notice).

latest blog entries

  • OpenCV bindings with Lua

    Geeez I’ve been waiting for this one. Finally after 39 hours work non-stop (I feel drunk) and the creation of a new ruby gem called Dub (Doxygen based Ubiquitous Binder which generates 10'018 lines of code that compile without a warning, I can PLAY with OpenCV in Rubyk.

    The only source for images right now is the video signal, but that quite fun already.

    opencv in ruby

    If you want to reproduce the stupid rotating cube with your own face on it, heres the code:

    (It is also an example in examples/GLLua/opencv.lua)

    Rk patch

    # run from build directory with
    # ./rubyk ../examples/GLLua/opencv.rk
    win = GLWindow()
    cv = GLLua("../examples/GLLua/opencv.lua")
    win => cv
    video = VideoIn()
    video => video~cv
    m = Metro(3000)
    m => win

    Lua code

    The code has been updated to use the new texture based rendering.

    require('cv')
    
    -- size must be a power of 2
    size  = cv.Size(128,128)
    res   = res   or cv.Mat()
    
    n = n or 0
    x = x or 0
    y = y or 0
    z = z or 0
    
    function video(frame)
      cv.resize(frame, res, size, 0, 0, cv.INTER_LINEAR)
      frame_changed = true
    
      n = n + math.pi / 300
      x = math.cos(n / 0.9) * 360 / math.pi
      y = math.sin(n / 0.7) * 360 / math.pi
      z = math.sin(n) * 360 / math.pi
    end
    inlet('video', MatrixIO('send me images'))
    
    function draw()
      gl.Clear( "COLOR_BUFFER_BIT, DEPTH_BUFFER_BIT")
      --gl.ClearDepth(1.0)
      gl.MatrixMode("MODELVIEW")
      gl.LoadIdentity()
    
      if frame_changed then
        rk.makeTexture(res, tex)
        frame_changed = false
      end
    
      gl.Translate(0.0, 0.0, -6.0)
    
      gl.Rotate(x, 1.0, 0.0, 0.0)
      gl.Rotate(y, 0.0, 1.0, 0.0)
      gl.Rotate(z, 0.0, 0.0, 1.0)
    
      gl.Color(0.5,0.5,0.0)--,0.3)
      gl.LineWidth(1.0)
      glut.WireCube(2.6)
    
      gl.Color(0.5,0.5,0.0,0.1)
      glut.SolidCube(2.6)
    
      -- simples way to draw a texture
      gl.Translate(0.0, 0.0, -1.5)
      -- do not forget to set a color or nothing will be drawn
      gl.Color(1,1,1,0.5)
      rk.drawTexture(tex, 1.3, 1.3, -1.3, -1.3)
    end
    
    function resize(width, height)
      textures = textures or gl.GenTextures(1)
      tex = textures[1]
    
      gl.Enable("BLEND")
      gl.Disable("DEPTH_TEST") -- not working ???
      gl.BlendFunc("SRC_ALPHA", "ONE_MINUS_SRC_ALPHA")
    
      gl.Enable("TEXTURE_2D")
    
      gl.Enable("LINE_SMOOTH")
      -- Select the projection matrix
      gl.MatrixMode("PROJECTION")
      -- reset
      gl.LoadIdentity()
      -- Calculate the aspect ratio of the view
      gl.Perspective(
        45.0,             -- Field of view angle
        width / height,   -- Aspect ration
        1.0,              -- zNear
        100.0             -- zFar
      )
    
      view.width  = width
      view.height = height
    end
    
    2010-03-03 - tagged: Lua, OpenCV, OpenGL - comments (0)
  • playing with the new GLLua class

    Creating Bezier curves with lua and displaying them with OpenGL (GLLua object):

    splines

    And here is the code that evaluates the curves and color transitions along the paths:

    for t = 0,1.0,(1.0/resolution) do
      ta = (1-t)^3
      tb = 3 * t * (1-t)^2
      tc = 3 * (1-t) * t^2
      td = t^3
    
      gl.Color(
        c1.r * (1-t) + c4.r * t,
        c1.v * (1-t) + c4.v * t,
        c1.b * (1-t) + c4.b * t
      )
      gl.Vertex(
        ta * p1[1] + tb * p2[1] + tc * p3[1] + td * p4[1],
        ta * p1[2] + tb * p2[2] + tc * p3[2] + td * p4[2],
        ta * p1[3] + tb * p2[3] + tc * p3[3] + td * p4[3]
      )
    end
    2010-02-21 - tagged: Lua, OpenGL - comments (0)