Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Making cool lines in Sketch
let sketch = require('sketch')
let document = sketch.getSelectedDocument()
let page = document.selectedPage
page.layers = []
let Artboard = sketch.Artboard
let myArtboard = new Artboard({
frame: { x: 0, y: 0, width: 400, height: 400 },
parent: page,
background: { color: "#000", enabled: true }
})
let Group = sketch.Group
let myGroup = new Group({
parent: myArtboard,
})
let ShapePath = sketch.ShapePath
let path = new ShapePath({
type: ShapePath.ShapeType.Rectangle,
frame: { x: 100, y: 100, width: 200, height: 200 },
style: { fills: [], borders: ['#FF0000']},
parent: myGroup,
})
myGroup.adjustToFit()
let l = 100.0
let m = 4.0
let n = l/m
let createLine = function(x1,y1,x2,y2) {
let line = new ShapePath({
frame: { x:0, y: 0, width: 200, height: 200 },
style: { borders: ['#FF00004D'] },
points: [{ point: { x: x1/l, y: y1/l }, pointType: 'Straight'}, { point: { x: x2/l, y: y2/l }, pointType: 'Straight'}],
parent: myGroup,
})
return line
}
for (let i = 0; i <= n; i++) {
createLine(l,m*i,l-m*i,l)
}
for (let i = 0; i <= n; i++) {
createLine(l-m*i, l, 0, l-m*i)
}
for (let i = 0; i <= n; i++) {
createLine(m*i, 0, 0, l-m*i)
}
for (let i = 0; i <= n; i++) {
createLine(l, m*i, m*i, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment