Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ const {
const console = require("console");
const canvas = createCanvas(width, height);
const ctx = canvas.getContext("2d");

//add noise to the images randomly
const drawNoise = (ctx, width, height, opacity) => {
const imageData = ctx.createImageData(width, height);
const data = imageData.data;
for (let i = 0; i < data.length; i += 4) {
const value = Math.random() * 255;
data[i] = value;
data[i + 1] = value;
data[i + 2] = value;
data[i + 3] = opacity * 255;
}
ctx.putImageData(imageData, 0, 0);
};
// saves the generated image to the output folder, using the edition count as the name
const saveImage = (_editionCount) => {
fs.writeFileSync(
Expand Down Expand Up @@ -217,7 +229,7 @@ const startCreating = async () => {

// elements are loaded asynchronously
// -> await for all to be available before drawing the image
await Promise.all(loadedElements).then((elementArray) => {
await Promise.all(loadedElements).then(async (elementArray) => {
// create empty image
ctx.clearRect(0, 0, width, height);
// draw a random background color
Expand All @@ -228,7 +240,11 @@ const startCreating = async () => {
elementArray.forEach((element) => {
drawElement(element);
attributesList.push(getAttributeForElement(element));
drawElement(element);
});
if(applyNoise){
drawNoise(ctx,width,height,0.1)
}
// add an image signature as the edition count to the top left of the image
signImage(`#${editionCount}`);
// write the image to the output directory
Expand Down