Skip to content

Commit 3e3c9a7

Browse files
authored
Merge pull request #5 from HashLips/v2
V2
2 parents 0fcbeb4 + b1bb8e3 commit 3e3c9a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+553
-49
lines changed

.DS_Store

6 KB
Binary file not shown.

index.js

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
const fs = require("fs");
2-
const myArgs = process.argv.slice(2);
32
const { createCanvas, loadImage } = require("canvas");
4-
const { layers, width, height } = require("./input/config.js");
3+
const {
4+
layers,
5+
width,
6+
height,
7+
description,
8+
baseImageUri,
9+
editionSize,
10+
startEditionFrom,
11+
endEditionAt,
12+
rarityWeights,
13+
} = require("./input/config.js");
514
const console = require("console");
615
const canvas = createCanvas(width, height);
716
const ctx = canvas.getContext("2d");
8-
const editionSize = myArgs.length > 0 ? Number(myArgs[0]) : 1;
917
var metadataList = [];
1018
var attributesList = [];
1119
var dnaList = [];
@@ -40,6 +48,9 @@ const addMetadata = (_dna, _edition) => {
4048
let dateTime = Date.now();
4149
let tempMetadata = {
4250
dna: _dna.join(""),
51+
name: `#${_edition}`,
52+
description: description,
53+
image: `${baseImageUri}/${_edition}`,
4354
edition: _edition,
4455
date: dateTime,
4556
attributes: attributesList,
@@ -58,9 +69,7 @@ const addAttributes = (_element) => {
5869

5970
const loadLayerImg = async (_layer) => {
6071
return new Promise(async (resolve) => {
61-
const image = await loadImage(
62-
`${_layer.location}${_layer.selectedElement.fileName}`
63-
);
72+
const image = await loadImage(`${_layer.selectedElement.path}`);
6473
resolve({ layer: _layer, loadedImage: image });
6574
});
6675
};
@@ -76,9 +85,9 @@ const drawElement = (_element) => {
7685
addAttributes(_element);
7786
};
7887

79-
const constructLayerToDna = (_dna = [], _layers = []) => {
88+
const constructLayerToDna = (_dna = [], _layers = [], _rarity) => {
8089
let mappedDnaToLayers = _layers.map((layer, index) => {
81-
let selectedElement = layer.elements[_dna[index]];
90+
let selectedElement = layer.elements[_rarity][_dna[index]];
8291
return {
8392
location: layer.location,
8493
position: layer.position,
@@ -90,15 +99,28 @@ const constructLayerToDna = (_dna = [], _layers = []) => {
9099
return mappedDnaToLayers;
91100
};
92101

102+
const getRarity = (_editionCount) => {
103+
let rarity = "";
104+
rarityWeights.forEach((rarityWeight) => {
105+
if (
106+
_editionCount >= rarityWeight.from &&
107+
_editionCount <= rarityWeight.to
108+
) {
109+
rarity = rarityWeight.value;
110+
}
111+
});
112+
return rarity;
113+
};
114+
93115
const isDnaUnique = (_DnaList = [], _dna = []) => {
94116
let foundDna = _DnaList.find((i) => i.join("") === _dna.join(""));
95117
return foundDna == undefined ? true : false;
96118
};
97119

98-
const createDna = (_layers) => {
120+
const createDna = (_layers, _rarity) => {
99121
let randNum = [];
100122
_layers.forEach((layer) => {
101-
let num = Math.floor(Math.random() * layer.elements.length);
123+
let num = Math.floor(Math.random() * layer.elements[_rarity].length);
102124
randNum.push(num);
103125
});
104126
return randNum;
@@ -110,14 +132,18 @@ const writeMetaData = (_data) => {
110132

111133
const startCreating = async () => {
112134
writeMetaData("");
113-
let editionCount = 1;
114-
while (editionCount <= editionSize) {
135+
let editionCount = startEditionFrom;
136+
while (editionCount <= endEditionAt) {
115137
console.log(editionCount);
116138

117-
let newDna = createDna(layers);
139+
let rarity = getRarity(editionCount);
140+
console.log(rarity);
141+
142+
let newDna = createDna(layers, rarity);
118143
console.log(dnaList);
144+
119145
if (isDnaUnique(dnaList, newDna)) {
120-
let results = constructLayerToDna(newDna, layers);
146+
let results = constructLayerToDna(newDna, layers, rarity);
121147
let loadedElements = []; //promise array
122148

123149
results.forEach((layer) => {

input/.DS_Store

10 KB
Binary file not shown.

input/background/black.png

-2.37 KB
Binary file not shown.

input/ball/.DS_Store

8 KB
Binary file not shown.

input/ball/original/.DS_Store

6 KB
Binary file not shown.
98.2 KB
File renamed without changes.
File renamed without changes.

input/ball/rare/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)