Created
March 10, 2018 18:22
-
-
Save nicholas-ochoa/7ed14eb38c20f6e1678713296d745d3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 fs = require('fs'); | |
| let pureImage = require('pureimage'); | |
| let scale = 4; | |
| let width = (32 * scale) + 64; | |
| let height = (17 * scale) + 64; | |
| let image = pureImage.make(width, height); | |
| let context = image.getContext('2d'); | |
| let x = 0; | |
| let y = 0; | |
| let polygon = [ | |
| { x: 26, y: 10 }, | |
| { x: 42, y: 18 }, | |
| { x: 26, y: 26 }, | |
| { x: 10, y: 18 }, | |
| { x: 26, y: 10 }, | |
| ]; | |
| context.clearRect(0, 0, width, height); | |
| context.strokeStyle = 'rgba(0,4,255,0.5)'; | |
| context.fillStyle = 'rgba(0,4,255,0.3)'; | |
| context.lineWidth = 2 * scale; | |
| context.beginPath(); | |
| context.moveTo(polygon[0].x * scale, polygon[0].y * scale); | |
| for (let i = 1; i < polygon.length; i++) { | |
| x = polygon[i].x * scale; | |
| y = polygon[i].y * scale; | |
| context.lineTo(x, y); | |
| } | |
| context.stroke(); | |
| context.fill(); | |
| context.closePath(); | |
| pureImage.encodePNGToStream(image, fs.createWriteStream(__dirname + '/out.png')).then(() => { | |
| console.log('saved: out.png'); | |
| }).catch((e)=>{ | |
| console.log('there was an error writing: ', e); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment