Created
September 30, 2018 14:28
-
-
Save mattdesl/dd950edbb6a20f998a3a9024c9459c06 to your computer and use it in GitHub Desktop.
example of declarative GUI support in canvas-sketch library
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
const canvasSketch = require('canvas-sketch'); | |
const settings = { | |
dimensions: [ 2048, 2048 ], | |
params: { | |
size: { | |
min: 50, | |
max: 400, | |
step: 1, | |
value: 200 | |
}, | |
lineWidth: { | |
min: 1, | |
max: 20, | |
step: 0.01, | |
value: 10 | |
}, | |
stroke: false, | |
text: 'test', | |
foreground: 'white', | |
background: '#F8C9B7' | |
} | |
}; | |
const sketch = () => { | |
return ({ context, width, height, params }) => { | |
context.clearRect(0, 0, width, height); | |
context.fillStyle = params.background; | |
context.fillRect(0, 0, width, height); | |
context.font = `${params.size}px "Andale Mono"`; | |
context.textAlign = 'center'; | |
context.textBaseline = 'middle'; | |
context.fillStyle = context.strokeStyle = params.foreground; | |
context.lineWidth = params.lineWidth; | |
context[params.stroke ? 'strokeText' : 'fillText'](params.text, width / 2, height / 2); | |
}; | |
}; | |
canvasSketch(sketch, settings); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://baku89.com/ui?lang=en