-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageMaker.js
33 lines (26 loc) · 885 Bytes
/
imageMaker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// const { inspect } = require('util');
const fs = require('fs');
const { createCanvas } = require('canvas');
const data = require('./data');
function makeImages() {
data.map((element) => {
const atomicNum = String(element.atomicNumber).padStart(3, '0');
const elementName = element.name.toLowerCase();
const width = 450;
const height = 450;
const canvas = createCanvas(width, height);
const context = canvas.getContext('2d');
context.fillStyle = '#FFF';
context.strokeStyle = '#FFF';
context.beginPath();
context.arc(125, 125, 125, 0, 2 * Math.PI);
context.stroke();
const buffer = canvas.toBuffer('image/png');
fs.writeFile(`${atomicNum}_${elementName}.jpg`, buffer, (err) => {
if (err) throw err;
console.log(`${element.name} file is created successfully.`);
});
return element;
});
}
makeImages();