-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateMandelbrot.js
53 lines (46 loc) · 1.48 KB
/
generateMandelbrot.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Generation by this file does not allow for the generation of different colors or replicas afterwards, as no values are stored.
* Generates Mandelbrot set images.
* By default images are stored to ./images.
* Modify width variable to change image size.
*/
const { convertColor, generateMandelbrot } = require('./modules/functions');
const Jimp = require('jimp');
// Set the width and height of image
// Modify width variable to generate different size images
let width = 2048;
let height = width / 2;
// Store file title for later use, single variable allows for change
// at single line of code.
const fileTitle = `mandelbrot-${width}x${height}`;
// Variable for the image data can become
// very large and take up a decent amount of RAM.
// imageValues[columns/x][rows/y]
let imageValues = []
for (let x = 0; x < width; x++) { // Loop through columns.
let column = []
for (let y = 0; y < height; y++) { // Loop through rows.
// Store image color values
column.push(
convertColor(
generateMandelbrot(
(x - (0.75 * width)) / (width / 4),
(y - (width / 4)) / (width / 4)
)
)
);
}
console.log(`( ${x} ) | ( ${width - x} )`)
imageValues.push(column);
}
let image = new Jimp(width, height, 0x0, (err, image) => {
if (err) {
process.exit();
}
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
image.setPixelColor(imageValues[x][y], x, y);
}
}
image.write(`./images/${fileTitle}.png`);
});