local enumerations = require 'enumerations' local twintree = require 'twintree' local step = coroutine.wrap( twintree.buildIncremental ) local a = enumerations.Dyad() local b = enumerations.Random() step( a, b ) --Use LOVE for plotting. local love = assert( love ) local canvas = love.graphics.newCanvas() local numMapped, pointList = 0 local function swap( i, j ) b[i], b[j] = b[j], b[i] end local function reset() print( "changing coroutine" ) step = coroutine.wrap( twintree.buildIncremental ) print( "swapping" ) for i = 1, 10000 do swap( i, math.random( 1, 10000 ) ) end pointList = nil numMapped = 0 print( "step" ) step( a, b ) end local function new() pointList = step() numMapped = numMapped + 1 end local function paint() local type = type --Make sure the whole point list consists of numbers! --We use the __call metamethod in non-number elements to coerce to numbers. --TODO: make this more generic, maybe amenable to FFI types. for i = 1, #pointList do if type( pointList[i] ) ~= 'number' then pointList[i] = pointList[i]() end end --print( "Points: " ) --for i = 1, #pointList - 1, 2 do -- print(pointList[i], pointList[i + 1] ) --end love.graphics.setCanvas( canvas ) love.graphics.clear() love.graphics.setColor( 1, 1, 1, 0.5 ) love.graphics.print( numMapped ) love.graphics.push() love.graphics.scale( love.graphics.getWidth(), love.graphics.getHeight() ) love.graphics.translate( 0, 1 ) love.graphics.scale( 1, -1 ) love.graphics.points( pointList ) love.graphics.line( pointList ) love.graphics.pop() love.graphics.setCanvas() end function love.wheelmoved() for i = 1, 3 do new() end paint() --[[ for i = 1, #sb do print( i, sb[i], dy[i] ) end]] end function love.mousepressed() --[[for i = 1, #sb do print( i, sb[i] ) end]] end function love.draw() love.graphics.setCanvas() love.graphics.setColor( 1, 1, 1, 1 ) love.graphics.draw( canvas ) end function love.keypressed() print( "pressed key!" ) return reset() and love.wheelmoved() end function love.load() love.graphics.setLineWidth( 0.001 ) end