Skip to content

Commit f8b189f

Browse files
committed
Updated config
1 parent a7e633d commit f8b189f

4 files changed

Lines changed: 92 additions & 26 deletions

File tree

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ const layerConfigurations = [
101101
];
102102
```
103103

104-
Then optionally, update your `format` size, ie the outputted image size, and the `growEditionSizeTo` on each `layerConfigurations` object, which is the amount of variation outputted.
104+
Update your `format` size, ie the outputted image size, and the `growEditionSizeTo` on each `layerConfigurations` object, which is the amount of variation outputted.
105+
106+
You can mix up the `layerConfigurations` order on how the images are saved by setting the variable `shuffleLayerConfigurations` in the `config.js` file to true. It is false by default and will save all images in numerical order.
107+
108+
If you want to have logs to debug and see what is happening when you generate images you can set the variable `debugLogs` in the `config.js` file to true. It is false by default, so you will only see general logs.
105109

106110
If you want to play around with different blending modes, you can add a `blend: MODE.colorBurn` field to the layersOrder object. If you need a layers to have a different opacity then you can add the `opacity: 0.7` field to the layersOrder object as well. Both the `blend: MODE.colorBurn` and `opacity: 0.7` can be addes on the same layer if you want to.
107111

@@ -157,7 +161,7 @@ const MODE = {
157161
};
158162
```
159163

160-
When you are all ready, run the following command and your outputted art will be in the `build/images` directory and the json in the `build/json` directory:
164+
When you are ready, run the following command and your outputted art will be in the `build/images` directory and the json in the `build/json` directory:
161165

162166
```sh
163167
npm run build
@@ -192,6 +196,20 @@ The program will output all the images in the `build/images` directory along wit
192196
}
193197
```
194198

199+
You can also add extra metadata to each metadata file by adding your extra items, (key: value) pairs to the `extraMetadata` object variable in the `config.js` file.
200+
201+
```js
202+
const extraMetadata = {
203+
creator: "Daniel Eugene Botha",
204+
};
205+
```
206+
207+
If you don't need extra metadata, simply leave the object empty. It is empty by default.
208+
209+
```js
210+
const extraMetadata = {};
211+
```
212+
195213
That's it, you're done.
196214

197215
## Utils
@@ -232,14 +250,14 @@ The output will look something like this:
232250

233251
```sh
234252
Trait type: Bottom lid
235-
{ trait: 'High', chance: '20', occurrence: '40' }
236-
{ trait: 'Low', chance: '40', occurrence: '60' }
237-
{ trait: 'Middle', chance: '40', occurrence: '0' }
238-
239-
Trait type: Top lid
240-
{ trait: 'High', chance: '30', occurrence: '20' }
241-
{ trait: 'Low', chance: '20', occurrence: '40' }
242-
{ trait: 'Middle', chance: '50', occurrence: '40' }
253+
{ trait: 'High', chance: '20', occurrence: '15% out of 100%' }
254+
{ trait: 'Low', chance: '40', occurrence: '40% out of 100%' }
255+
{ trait: 'Middle', chance: '40', occurrence: '45% out of 100%' }
256+
257+
Trait type: Iris
258+
{ trait: 'Large', chance: '20', occurrence: '15% out of 100%' }
259+
{ trait: 'Medium', chance: '20', occurrence: '15% out of 100%' }
260+
{ trait: 'Small', chance: '60', occurrence: '70% out of 100%' }
243261
```
244262
245263
Hope you create some awesome artworks with this code 👄

src/config.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);
66
const { MODE } = require(path.join(basePath, "src/blendMode.js"));
77
const description =
88
"This is the description of your NFT project, remember to replace this";
9-
const baseUri = "ipfs://QmNfPMWLPTEbFpBtPFy4wkYEHRVWcz8dzjziTcPbebzF53";
9+
const baseUri = "ipfs://NewUriToReplace";
1010

1111
const layerConfigurations = [
1212
{
13-
growEditionSizeTo: 20,
13+
growEditionSizeTo: 10,
1414
layersOrder: [
1515
{ name: "Background" },
1616
{ name: "Eyeball" },
@@ -23,6 +23,10 @@ const layerConfigurations = [
2323
},
2424
];
2525

26+
const shuffleLayerConfigurations = false;
27+
28+
const debugLogs = false;
29+
2630
const format = {
2731
width: 512,
2832
height: 512,
@@ -33,17 +37,19 @@ const background = {
3337
brightness: "80%",
3438
};
3539

40+
const extraMetadata = {};
41+
42+
const rarityDelimiter = "#";
43+
44+
const uniqueDnaTorrance = 10000;
45+
3646
const preview = {
3747
thumbPerRow: 5,
3848
thumbWidth: 50,
3949
imageRatio: format.width / format.height,
4050
imageName: "preview.png",
4151
};
4252

43-
const rarityDelimiter = "#";
44-
45-
const uniqueDnaTorrance = 10000;
46-
4753
module.exports = {
4854
format,
4955
baseUri,
@@ -53,4 +59,7 @@ module.exports = {
5359
layerConfigurations,
5460
rarityDelimiter,
5561
preview,
62+
shuffleLayerConfigurations,
63+
debugLogs,
64+
extraMetadata,
5665
};

src/main.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const {
2020
uniqueDnaTorrance,
2121
layerConfigurations,
2222
rarityDelimiter,
23+
shuffleLayerConfigurations,
24+
debugLogs,
25+
extraMetadata,
2326
} = require(path.join(basePath, "/src/config.js"));
2427
const canvas = createCanvas(format.width, format.height);
2528
const ctx = canvas.getContext("2d");
@@ -112,6 +115,7 @@ const addMetadata = (_dna, _edition) => {
112115
image: `${baseUri}/${_edition}.png`,
113116
edition: _edition,
114117
date: dateTime,
118+
...extraMetadata,
115119
attributes: attributesList,
116120
compiler: "HashLips Art Engine",
117121
};
@@ -188,20 +192,50 @@ const writeMetaData = (_data) => {
188192
};
189193

190194
const saveMetaDataSingleFile = (_editionCount) => {
195+
let metadata = metadataList.find((meta) => meta.edition == _editionCount);
196+
debugLogs
197+
? console.log(
198+
`Writing metadata for ${_editionCount}: ${JSON.stringify(metadata)}`
199+
)
200+
: null;
191201
fs.writeFileSync(
192202
`${buildDir}/json/${_editionCount}.json`,
193-
JSON.stringify(
194-
metadataList.find((meta) => meta.edition == _editionCount),
195-
null,
196-
2
197-
)
203+
JSON.stringify(metadata, null, 2)
198204
);
199205
};
200206

207+
function shuffle(array) {
208+
let currentIndex = array.length,
209+
randomIndex;
210+
while (currentIndex != 0) {
211+
randomIndex = Math.floor(Math.random() * currentIndex);
212+
currentIndex--;
213+
[array[currentIndex], array[randomIndex]] = [
214+
array[randomIndex],
215+
array[currentIndex],
216+
];
217+
}
218+
return array;
219+
}
220+
201221
const startCreating = async () => {
202222
let layerConfigIndex = 0;
203223
let editionCount = 1;
204224
let failedCount = 0;
225+
let abstractedIndexes = [];
226+
for (
227+
let i = 1;
228+
i <= layerConfigurations[layerConfigurations.length - 1].growEditionSizeTo;
229+
i++
230+
) {
231+
abstractedIndexes.push(i);
232+
}
233+
if (shuffleLayerConfigurations) {
234+
abstractedIndexes = shuffle(abstractedIndexes);
235+
}
236+
debugLogs
237+
? console.log("Editions left to create: ", abstractedIndexes)
238+
: null;
205239
while (layerConfigIndex < layerConfigurations.length) {
206240
const layers = layersSetup(
207241
layerConfigurations[layerConfigIndex].layersOrder
@@ -219,24 +253,29 @@ const startCreating = async () => {
219253
});
220254

221255
await Promise.all(loadedElements).then((renderObjectArray) => {
256+
debugLogs ? console.log("Clearing casvas") : null;
222257
ctx.clearRect(0, 0, format.width, format.height);
223258
if (background.generate) {
224259
drawBackground();
225260
}
226261
renderObjectArray.forEach((renderObject) => {
227262
drawElement(renderObject);
228263
});
229-
saveImage(editionCount);
230-
addMetadata(newDna, editionCount);
231-
saveMetaDataSingleFile(editionCount);
264+
debugLogs
265+
? console.log("Editions left to create: ", abstractedIndexes)
266+
: null;
267+
saveImage(abstractedIndexes[0]);
268+
addMetadata(newDna, abstractedIndexes[0]);
269+
saveMetaDataSingleFile(abstractedIndexes[0]);
232270
console.log(
233-
`Created edition: ${editionCount}, with DNA: ${sha1(
271+
`Created edition: ${abstractedIndexes[0]}, with DNA: ${sha1(
234272
newDna.join("")
235273
)}`
236274
);
237275
});
238276
dnaList.push(newDna);
239277
editionCount++;
278+
abstractedIndexes.shift();
240279
} else {
241280
console.log("DNA exists!");
242281
failedCount++;

utils/rarityData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ for (var layer in rarityData) {
7171

7272
// show two decimal places in percent
7373
rarityData[layer][attribute].occurrence =
74-
rarityData[layer][attribute].occurrence.toFixed(0);
74+
rarityData[layer][attribute].occurrence.toFixed(0) + "% out of 100%";
7575
}
7676
}
7777

0 commit comments

Comments
 (0)