Home

Awesome

draft

About

draft is a simple drafting module for LÖVE 2D. It makes it easy to draft primitive shapes, and some more luxurious ones.

Loading the module

To load the module, use the following code.

-- modify the path depending where draft resides
local Draft = require('draft')
local draft = Draft(modeOption)

Setting mode is optional. The default is fill.

The drafting functions can then be called inside the love.draw() function.

Usage example

local Draft = require('draft')
local draft = Draft()

function love.draw()
  draft:rectangle(300, 100, 50, 30)
  draft:rectangle(500, 100, 50, 30)
  draft:rhombus(400, 200, 65, 65)
  draft:bow(390, 280, 100, 2.5, 0, 10, 'line')
end

Notes

Draft function list

Initialization

draft(mode)

Getters and Setters

draft:getMode()
draft:setMode(mode)

Shapes

Primary Shapes (using core drawing functions)

draft:line(points, mode)
draft:triangleIsosceles(cx, cy, width, height, mode)
draft:triangleRight(cx, cy, width, height, mode)
draft:rectangle(cx, cy, width, height, mode)
draft:polygon(vertices, mode)

Secondary Shapes (using primary shape functions)

draft:triangleEquilateral(cx, cy, width, mode)
draft:square(cx, cy, length, mode)
draft:trapezoid(cx, cy, width, height, widthTop, widthTopOffset, mode)
draft:rhombus(cx, cy, width, height, mode)
draft:trapezium(cx, cy, widthLeft, widthRight, height, depth, mode)
draft:gem(cx, cy, widthTop, widthMiddle, height, depth, mode)
draft:diamond(cx, cy, width, mode)

Tertiary Shapes (using secondary shape functions)

draft:rhombusEquilateral(cx, cy, length, mode)
draft:lozenge(cx, cy, width, mode)
draft:kite(cx, cy, width, height, depth, mode)
draft:trapezoidIsosceles(cx, cy, width, height, widthTop, mode)
draft:parallelogram(cx, cy, width, height, widthOffset, mode)

Curved Shapes

draft:compass(cx, cy, width, arcAngle, startAngle, numSegments, wrap, scale, mode)
draft:circle(cx, cy, radius, numSegments, mode)
draft:arc(cx, cy, radius, arcAngle, startAngle, numSegments, mode)
draft:bow(cx, cy, radius, arcAngle, startAngle, numSegments, mode)
draft:pie(cx, cy, radius, arcAngle, startAngle, numSegments, mode)
draft:ellipse(cx, cy, width, height, numSegments, mode)
draft:ellipticArc(cx, cy, width, height, arcAngle, startAngle, numSegments, mode)
draft:ellipticBow(cx, cy, width, height, arcAngle, startAngle, numSegments, mode)
draft:ellipticPie(cx, cy, width, height, arcAngle, startAngle, numSegments, mode)
draft:semicircle(cx, cy, width, startAngle, numSegments, mode)
draft:dome(cx, cy, width, startAngle, numSegments, mode)

Complex Shapes

draft:star(cx, cy, width, widthInner, numPoints, startAngle, mode)
draft:egg(cx, cy, width, syBottom, syTop, numSegments, mode)

Linkers

draft:linkLadder(v1, v2, mode)
draft:linkTangle(v1, v2, mode)
draft:linkWeb(v, mode)
draft:linkTangleWebs(v1, v2, mode)

example_linker.lua (shows off linking)

-- load draft  
local Draft = require('draft')  
local draft = Draft()  

function love.load()  
  limitUpper = 100  
  limitLower = 4  
  numSegments = limitLower  
  direction = 'up'  
  step = 0.01  
end  

function love.update(dt)  
  if numSegments > limitUpper and direction == 'up' then  
    direction = 'down'  
  elseif numSegments < limitLower and direction == 'down' then  
    direction = 'up'
  elseif direction == 'up' then  
    numSegments = numSegments + step  
  else  
    numSegments = numSegments - step  
  end  
end  

function love.draw()  
  local v = draft:egg(400, 300, 1500, 1, 1, numSegments, 'line')  
  draft:linkWeb(v)  
end