Skip to content

Instantly share code, notes, and snippets.

@boucher
Created March 5, 2010 21:11
Show Gist options
  • Save boucher/323153 to your computer and use it in GitHub Desktop.
Save boucher/323153 to your computer and use it in GitHub Desktop.
function drawDashedLine(context, startPoint, endPoint)
{
var axis = startPoint.x === endPoint.x ? 'y' : 'x',
distance = endPoint[axis] - startPoint[axis],
dashes = CEIL(distance / 4),
index = 0,
point = CGPointMakeCopy(startPoint),
segments = [];
for (; index < dashes; ++index)
{
segments.push(CGPointMakeCopy(point));
point[axis] = MIN(point[axis] + 3.0, endPoint[axis]);
segments.push(CGPointMakeCopy(point));
point[axis] += 1.0;
}
CGContextStrokeLineSegments(context, segments);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment