Created
April 28, 2019 19:35
-
-
Save KevinGutowski/ca5e894770aff1a8371c37a83c9a6ff4 to your computer and use it in GitHub Desktop.
Making cool lines in Sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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