Author
Travis Kirton


Stroke Start & End Points

You can define the start and end points used to draw the stroked outline of a shape. The values must be in the range 0...1 with 0 representing the start of the path and 1 the end. Values in between zero and one are interpolated linearly along the path length.

shape.strokeStart = 0.25
shape.strokeEnd = 0.75

Example

let dy = Vector(x: 0, y: 2.0)

//create and array of points to use for lines
//start out one iteration below 0
var points = (Point()-dy, Point(canvas.width, 0.0)-dy)

//figure out the total number of lines to draw
let totalLineCount = canvas.height / 2.0 //default line width of 1.0

//figure out displacement of strokeStart and strokeEnd
let strokeDisplacement = 0.5 / totalLineCount

for i in 0..<Int(totalLineCount) {
    points.0 += dy
    points.1 += dy

    //create a new line
    let newLine = Line(points)

    //determine the current displacement of the ends of the line
    let ds = strokeDisplacement*Double(i)
    newLine.strokeStart = 0.5 - ds
    newLine.strokeEnd = 0.5 + ds

    canvas.add(newLine)
}