Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 #214

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

V3 #214

Show file tree
Hide file tree
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
75 changes: 41 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const fs = require("fs");
const { createCanvas, loadImage } = require("canvas");
const {
layers,
width,
height,
description,
baseImageUri,
editionSize,
startEditionFrom,
endEditionAt,
rarityWeights,
races,
raceWeights,
} = require("./input/config.js");
const console = require("console");
const canvas = createCanvas(width, height);
Expand All @@ -26,8 +26,8 @@ const saveImage = (_editionCount) => {
};

const signImage = (_sig) => {
ctx.fillStyle = "#000000";
ctx.font = "bold 30pt Courier";
ctx.fillStyle = "#ffffff";
ctx.font = "bold 30pt Verdana";
ctx.textBaseline = "top";
ctx.textAlign = "left";
ctx.fillText(_sig, 40, 40);
Expand All @@ -50,7 +50,7 @@ const addMetadata = (_dna, _edition) => {
dna: _dna.join(""),
name: `#${_edition}`,
description: description,
image: `${baseImageUri}/${_edition}`,
image: `${baseImageUri}/${_edition}.png`,
edition: _edition,
date: dateTime,
attributes: attributesList,
Expand All @@ -62,8 +62,8 @@ const addMetadata = (_dna, _edition) => {
const addAttributes = (_element) => {
let selectedElement = _element.layer.selectedElement;
attributesList.push({
name: selectedElement.name,
rarity: selectedElement.rarity,
trait_type: _element.layer.name,
value: selectedElement.name,
});
};

Expand All @@ -85,11 +85,11 @@ const drawElement = (_element) => {
addAttributes(_element);
};

const constructLayerToDna = (_dna = [], _layers = [], _rarity) => {
let mappedDnaToLayers = _layers.map((layer, index) => {
let selectedElement = layer.elements[_rarity][_dna[index]];
const constructLayerToDna = (_dna = [], _races = [], _race) => {
let mappedDnaToLayers = _races[_race].layers.map((layer, index) => {
let selectedElement = layer.elements.find((e) => e.id == _dna[index]);
return {
location: layer.location,
name: layer.name,
position: layer.position,
size: layer.size,
selectedElement: selectedElement,
Expand All @@ -99,28 +99,31 @@ const constructLayerToDna = (_dna = [], _layers = [], _rarity) => {
return mappedDnaToLayers;
};

const getRarity = (_editionCount) => {
let rarity = "";
rarityWeights.forEach((rarityWeight) => {
if (
_editionCount >= rarityWeight.from &&
_editionCount <= rarityWeight.to
) {
rarity = rarityWeight.value;
const getRace = (_editionCount) => {
let race = "No Race";
raceWeights.forEach((raceWeight) => {
if (_editionCount >= raceWeight.from && _editionCount <= raceWeight.to) {
race = raceWeight.value;
}
});
return rarity;
return race;
};

const isDnaUnique = (_DnaList = [], _dna = []) => {
let foundDna = _DnaList.find((i) => i.join("") === _dna.join(""));
return foundDna == undefined ? true : false;
};

const createDna = (_layers, _rarity) => {
const createDna = (_races, _race) => {
let randNum = [];
_layers.forEach((layer) => {
let num = Math.floor(Math.random() * layer.elements[_rarity].length);
_races[_race].layers.forEach((layer) => {
let randElementNum = Math.floor(Math.random() * 100) + 1;
let num = 0;
layer.elements.forEach((element) => {
if (randElementNum >= 100 - element.weight) {
num = element.id;
}
});
randNum.push(num);
});
return randNum;
Expand All @@ -130,36 +133,40 @@ const writeMetaData = (_data) => {
fs.writeFileSync("./output/_metadata.json", _data);
};

const saveMetaDataSingleFile = (_editionCount) => {
fs.writeFileSync(
`./output/${_editionCount}.json`,
JSON.stringify(metadataList.find((meta) => meta.edition == _editionCount))
);
};

const startCreating = async () => {
writeMetaData("");
let editionCount = startEditionFrom;
while (editionCount <= endEditionAt) {
console.log(editionCount);

let rarity = getRarity(editionCount);
console.log(rarity);

let newDna = createDna(layers, rarity);
console.log(dnaList);
let race = getRace(editionCount);
let newDna = createDna(races, race);

if (isDnaUnique(dnaList, newDna)) {
let results = constructLayerToDna(newDna, layers, rarity);
let results = constructLayerToDna(newDna, races, race);
let loadedElements = []; //promise array

results.forEach((layer) => {
loadedElements.push(loadLayerImg(layer));
});

await Promise.all(loadedElements).then((elementArray) => {
ctx.clearRect(0, 0, width, height);
drawBackground();
// drawBackground();
elementArray.forEach((element) => {
drawElement(element);
});
signImage(`#${editionCount}`);
saveImage(editionCount);
addMetadata(newDna, editionCount);
console.log(`Created edition: ${editionCount} with DNA: ${newDna}`);
saveMetaDataSingleFile(editionCount);
console.log(
`Created edition: ${editionCount}, Race: ${race} with DNA: ${newDna}`
);
});
dnaList.push(newDna);
editionCount++;
Expand Down
Binary file modified input/.DS_Store
Binary file not shown.
Binary file added input/1-background/LightBlue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/1-background/Orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/10-headwear/GlassDome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/10-headwear/Headset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/10-headwear/Helmet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/10-headwear/NFTHelmet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/10-headwear/NoHeadwear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/10-headwear/Robber.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/10-headwear/Stealth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/2-suit/Orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/2-suit/Regular.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/3-shoulder/LunaFlag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/3-shoulder/USA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/4-pin/LunaBluePin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/4-pin/Smiley.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/5-skin/Skull.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/6-facial-hair/NoFacialHair.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/7-mask/Mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/7-mask/NoMask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/8-hair/BlondeBun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/8-hair/Pink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input/9-accessories/NoAcc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed input/ball/.DS_Store
Binary file not shown.
Binary file removed input/ball/original/.DS_Store
Binary file not shown.
Binary file removed input/ball/original/grey eye ball.png
Binary file not shown.
Binary file removed input/ball/original/red eye ball.png
Binary file not shown.
Binary file removed input/ball/original/white eye ball.png
Binary file not shown.
Binary file removed input/ball/rare/.DS_Store
Binary file not shown.
Binary file removed input/ball/rare/eye ball rare.png
Diff not rendered.
Binary file removed input/ball/rare/green eye ball rare.png
Diff not rendered.
Binary file removed input/ball/super_rare/.DS_Store
Binary file not shown.
Binary file removed input/ball/super_rare/red eye ball super rare.png
Diff not rendered.
Binary file removed input/bottom lid/.DS_Store
Binary file not shown.
Binary file removed input/bottom lid/original/.DS_Store
Binary file not shown.
Binary file removed input/bottom lid/original/high bottom.png
Diff not rendered.
Binary file removed input/bottom lid/rare/.DS_Store
Binary file not shown.
Binary file removed input/bottom lid/rare/tilted bottom rare.png
Diff not rendered.
Binary file removed input/bottom lid/super_rare/.DS_Store
Binary file not shown.
Diff not rendered.
Loading