Line Factories (ssk.display.*)

This library contains a number of function for creating complex and customizable lines.

Lines

Function Description
ssk.display.newLine Hyper-configurable line-segment factory, using two end-points to define the line.
ssk.display.newAngleLine Hyper-configurable line-segment factory using a start-point, an angle, and a length to define the line.
ssk.display.newPointsLine Hyper-configurable line-segment factory, using a points list to define the line.

newLine

Hyper-configurable line-segment factory, using two end-points to define the line.

ssk.display.newLine( group, startX, startY, endX, endY [, visualParams ] )

newAngleLine

Hyper-configurable line-segment factory using a start-point, an angle, and a length to define the line.

ssk.display.newAngleLine( group, startX, startY, angle, length [, visualParams ] )

newPointsLine

Hyper-configurable line-segment factory, using a points list to define the line.

ssk.display.newPointsLine( group, points [, visualParams ] )

Complete Example

Example of all line factories in use.


function test.run( group, params )
   group = group or display.currentStage
   params = params or {}

   -- Basic
   local newLine    = ssk.display.newLine
    newLine( group, 50, top + 50, 450, top + 50 )
    newLine( group, 50, top + 50 + 20, 450, top + 50 + 20, 
              { w = 2, fill = _R_ } )
    newLine( group, 50, top + 50 + 40, 450, top + 50 + 40, 
              { w = 1, dashLen = 3, gapLen = 5, fill = _C_, style = "dashed" } )
    newLine( group, 50, top + 50 + 60, 450, top + 50 + 60, 
              { radius = 3, gapLen = 5, fill = _O_, style = "dotted", 
                stroke = _Y_, strokeWidth = 1} )
    newLine( group, 50, top + 50 + 80, 450, top + 50 + 80, 
              { gapLen = 10, dashLen = 6, headSize = 4, fill = _O_, style = "arrows"} )
    newLine( group, 50, top + 50 + 100, 450, top + 50 + 100, 
              { gapLen = 10, dashLen = 0, headSize = 4, fill = _C_, style = "arrows"} )


    -- Angle lines
    local newAngleLine = ssk.display.newAngleLine
    local curY = top + 200
    local tmp = newAngleLine( group, 50, curY, 135, 200 )
    curY = curY + 20
    local tmp = newAngleLine( group, 50, curY, 135, 200, 
                              { w = 2, fill = _R_ } )
    curY = curY + 20
    local tmp = newAngleLine( group, 50, curY, 135, 200, 
                               { w = 1, dashLen = 3, gapLen = 5, fill = _C_, style = "dashed" } )
    curY = curY + 20
    local tmp = newAngleLine( group, 50, curY, 135, 200, 
                               { radius = 3, gapLen = 5, fill = _O_, style = "dotted", 
                                 stroke = _Y_, strokeWidth = 1} )
    curY = curY + 20
    local tmp = newAngleLine( group, 50, curY, 135, 200, 
                               { gapLen = 10, dashLen = 6, headSize = 4, fill = _O_, 
                                 style = "arrows"} )
    curY = curY + 20
    local tmp = newAngleLine( group, 50, curY, 135, 200, 
                               { gapLen = 10, dashLen = 1, headSize = 4, fill = _C_, 
                                 style = "arrows"} )

    -- Animated Lines
    local newPointsLine     = ssk.display.newPointsLine
    local newPoints         = ssk.points.new
    local easyIFC           = ssk.easyIFC
    local mRand             = math.random
    local reDrawLines
    local lastGroup

    reDrawLines = function()
        display.remove( lastGroup )

        lastGroup = display.newGroup()
        group:insert( lastGroup )

        lastGroup.x  = lastGroup.x + 200

        local curY = 250

        local points = newPoints()
        for i = 1, 36 do
            points:add( 50 + (i-1) * 10, curY + mRand(-5,5) )
        end
        local tmp = newPointsLine( lastGroup, points  )

        local points = newPoints()  
        curY = curY + 20
        for i = 1, 36 do
            points:add( 50 + (i-1) * 10, curY + mRand(-5,5) )
        end
        local tmp = newPointsLine( lastGroup, points, { w = 2, fill = _R_ } )

        local points = newPoints()
        curY = curY + 20    
        for i = 1, 36 do
            points:add( 50 + (i-1) * 10, curY + mRand(-5,5) )
        end
        local tmp = newPointsLine( lastGroup, points, 
                                    { w = 1, dashLen = 1, gapLen = 2, fill = _C_, 
                                      style = "dashed" } )

        local points = newPoints()
        curY = curY + 20
        for i = 1, 36 do
            points:add( 50 + (i-1) * 10, curY + mRand(-5,5) )
        end
        local tmp = newPointsLine( lastGroup, points, 
                                    { radius = 3, gapLen = 5, fill = _O_, style = "dotted", 
                                       stroke = _Y_, strokeWidth = 1} )

        local points = newPoints()
        curY = curY + 20
        for i = 1, 36 do
            points:add( 50 + (i-1) * 10, curY + mRand(-5,5) )
        end
        local tmp = newPointsLine( lastGroup, points, 
                                    { gapLen = 10, dashLen = 6, headSize = 4, fill = _O_, 
                                      style = "arrowheads"} )

        local points = newPoints()
        curY = curY + 20
        for i = 1, 36 do
            points:add( 50 + (i-1) * 10, curY + mRand(-5,5) )
        end
        local tmp = newPointsLine( lastGroup, points, { fill = {1,1,1,0.2} } )
        local tmp = newPointsLine( lastGroup, points, 
                                    { gapLen = 10, dashLen = 1, headSize = 4, fill = _C_, 
                                      style = "arrowheads"} )

        timer.performWithDelay( 100, reDrawLines )
    end

    reDrawLines()
end


RoamingGamer Copyright © Roaming Gamer, LLC. 2008-2016; All Rights Reserved