-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
108 lines (89 loc) · 2.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//Dipendenze generali
const console = require("console");
const dotenv = require("dotenv");
dotenv.config(); // Inizializziamo dotenv
// Moralis
const Moralis = require("moralis/node");
// Canvas
const { createCanvas } = require("canvas");
// Import config
const {
layers,
width,
height,
editionSize,
startEditionFrom,
rarityWeights,
} = require("./input/config");
// metadata
const { compileMetadata } = require("./src/metadata");
// save files
const { createFile } = require("./src/filesystem");
// setup img
const canvas = createCanvas(width, height);
const ctx = canvas.getContext("2d");
// Dipendenze express
const express = require("express");
const app = express();
const port = 5000; // Local listening on this port
// Moralis cred
const serverUrl = process.env.SERVER_URL;
const appId = process.env.APP_ID;
const masterKey = process.env.MASTER_KEY;
const apiUrl = process.env.API_URL;
const apiKey = process.env.API_KEY;
// Start Moralis
Moralis.start({ serverUrl, appId, masterKey });
// Start creation
const startCreating = async () => {
console.log("##################");
console.log("# Generative Art #");
console.log("# - Generating your NFT collection");
console.log("##################");
// image data collection
let imageDataArray = [];
// create NFTs from startEditionFrom to editionSize
let editionCount = startEditionFrom;
while (editionCount <= editionSize) {
console.log("-----------------");
console.log("Creating %d of %d", editionCount, editionSize);
const handleFinal = async () => {
// create image files and return object array of created images
[...imageDataArray] = await createFile(
canvas,
ctx,
layers,
width,
height,
editionCount,
editionSize,
rarityWeights,
imageDataArray
);
};
await handleFinal();
// iterate
editionCount++;
}
await compileMetadata(
apiUrl,
apiKey,
editionCount,
editionSize,
imageDataArray
);
console.log();
console.log("#########################################");
console.log("Welcome to Rekt City - Meet the Survivors");
console.log("#########################################");
console.log();
};
app.get("/", (req, res) => {
res.send('Server in ascolto')
});
app.get("/startCreate", (req, res) => {
startCreating()
});
app.listen(port, () => {
console.log(`Server in ascolto su porta ${port}`);
});