MCPcopy Create free account
hub / github.com/HashLips/generative-art-opensource / startCreating

Function startCreating

index.js:171–246  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

169let metadataList = [];
170// Create generative art by using the canvas api
171const startCreating = async () => {
172 console.log('##################');
173 console.log('# Generative Art');
174 console.log('# - Create your NFT collection');
175 console.log('##################');
176
177 console.log();
178 console.log('start creating NFTs.')
179
180 // clear meta data from previous run
181 writeMetaData("");
182
183 // prepare dnaList object
184 rarityWeights.forEach((rarityWeight) => {
185 dnaListByRarity[rarityWeight.value] = [];
186 });
187
188 // create NFTs from startEditionFrom to editionSize
189 let editionCount = startEditionFrom;
190 while (editionCount <= editionSize) {
191 console.log('-----------------')
192 console.log('creating NFT %d of %d', editionCount, editionSize);
193
194 // get rarity from to config to create NFT as
195 let rarity = getRarity(editionCount);
196 console.log('- rarity: ' + rarity);
197
198 // calculate the NFT dna by getting a random part for each layer/feature
199 // based on the ones available for the given rarity to use during generation
200 let newDna = createDna(layers, rarity);
201 while (!isDnaUnique(dnaListByRarity[rarity], newDna)) {
202 // recalculate dna as this has been used before.
203 console.log('found duplicate DNA ' + newDna.join('-') + ', recalculate...');
204 newDna = createDna(layers, rarity);
205 }
206 console.log('- dna: ' + newDna.join('-'));
207
208 // propagate information about required layer contained within config into a mapping object
209 // = prepare for drawing
210 let results = constructLayerToDna(newDna, layers, rarity);
211 let loadedElements = [];
212
213 // load all images to be used by canvas
214 results.forEach((layer) => {
215 loadedElements.push(loadLayerImg(layer));
216 });
217
218 // elements are loaded asynchronously
219 // -> await for all to be available before drawing the image
220 await Promise.all(loadedElements).then((elementArray) => {
221 // create empty image
222 ctx.clearRect(0, 0, width, height);
223 // draw a random background color
224 drawBackground();
225 // store information about each layer to add it as meta information
226 let attributesList = [];
227 // draw each layer
228 elementArray.forEach((element) => {

Callers 1

index.jsFile · 0.85

Calls 12

writeMetaDataFunction · 0.85
getRarityFunction · 0.85
createDnaFunction · 0.85
isDnaUniqueFunction · 0.85
constructLayerToDnaFunction · 0.85
loadLayerImgFunction · 0.85
drawBackgroundFunction · 0.85
drawElementFunction · 0.85
getAttributeForElementFunction · 0.85
signImageFunction · 0.85
saveImageFunction · 0.85
generateMetadataFunction · 0.85

Tested by

no test coverage detected