Skip to content

Commit b526bb8

Browse files
committed
Added text renders
1 parent 1f4c27d commit b526bb8

2 files changed

Lines changed: 52 additions & 23 deletions

File tree

src/config.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,18 @@
33
const path = require("path");
44
const isLocal = typeof process.pkg === "undefined";
55
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);
6-
const { MODE } = require("../constants/blend_mode.js");
6+
const { MODE } = require(path.join(basePath, "constants/blend_mode.js"));
77
const description =
88
"This is the description of your NFT project, remember to replace this";
99
const baseUri = "ipfs://NewUriToReplace";
1010

1111
const layerConfigurations = [
1212
{
13-
growEditionSizeTo: 10,
13+
growEditionSizeTo: 5,
1414
layersOrder: [
15-
{
16-
name: "Background",
17-
options: {
18-
blend: MODE.destinationIn,
19-
opcacity: 0.4,
20-
displayName: "BackGround Extra",
21-
},
22-
},
15+
{ name: "Background" },
2316
{ name: "Eyeball" },
24-
{
25-
name: "Eye color",
26-
options: {
27-
blend: MODE.colorBurn,
28-
displayName: "Awesome Color",
29-
},
30-
},
17+
{ name: "Eye color" },
3118
{ name: "Iris" },
3219
{ name: "Shine" },
3320
{ name: "Bottom lid" },
@@ -45,13 +32,28 @@ const format = {
4532
height: 512,
4633
};
4734

35+
const text = {
36+
only: true,
37+
color: "#ffffff",
38+
size: 20,
39+
xGap: 40,
40+
yGap: 40,
41+
align: "left",
42+
baseline: "top",
43+
weight: "regular",
44+
family: "Courier",
45+
spacer: " => ",
46+
};
47+
4848
const pixelFormat = {
4949
ratio: 2 / 128,
5050
};
5151

5252
const background = {
5353
generate: true,
5454
brightness: "80%",
55+
static: true,
56+
default: "#000000",
5557
};
5658

5759
const extraMetadata = {};
@@ -80,4 +82,5 @@ module.exports = {
8082
debugLogs,
8183
extraMetadata,
8284
pixelFormat,
85+
text,
8386
};

src/main.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const { createCanvas, loadImage } = require(path.join(
1111
));
1212
const buildDir = path.join(basePath, "/build");
1313
const layersDir = path.join(basePath, "/layers");
14-
console.log(path.join(basePath, "/src/config.js"));
1514
const {
1615
format,
1716
baseUri,
@@ -23,6 +22,7 @@ const {
2322
shuffleLayerConfigurations,
2423
debugLogs,
2524
extraMetadata,
25+
text,
2626
} = require(path.join(basePath, "/src/config.js"));
2727
const canvas = createCanvas(format.width, format.height);
2828
const ctx = canvas.getContext("2d");
@@ -111,7 +111,7 @@ const genColor = () => {
111111
};
112112

113113
const drawBackground = () => {
114-
ctx.fillStyle = genColor();
114+
ctx.fillStyle = background.static ? background.default : genColor();
115115
ctx.fillRect(0, 0, format.width, format.height);
116116
};
117117

@@ -147,10 +147,32 @@ const loadLayerImg = async (_layer) => {
147147
});
148148
};
149149

150-
const drawElement = (_renderObject) => {
150+
const addText = (_sig, x, y, size) => {
151+
ctx.fillStyle = text.color;
152+
ctx.font = `${text.weight} ${size}pt ${text.family}`;
153+
ctx.textBaseline = text.baseline;
154+
ctx.textAlign = text.align;
155+
ctx.fillText(_sig, x, y);
156+
};
157+
158+
const drawElement = (_renderObject, _index, _layersLen) => {
151159
ctx.globalAlpha = _renderObject.layer.opacity;
152160
ctx.globalCompositeOperation = _renderObject.layer.blend;
153-
ctx.drawImage(_renderObject.loadedImage, 0, 0, format.width, format.height);
161+
text.only
162+
? addText(
163+
`${_renderObject.layer.name}${text.spacer}${_renderObject.layer.selectedElement.name}`,
164+
text.xGap,
165+
text.yGap * (_index + 1),
166+
text.size
167+
)
168+
: ctx.drawImage(
169+
_renderObject.loadedImage,
170+
0,
171+
0,
172+
format.width,
173+
format.height
174+
);
175+
154176
addAttributes(_renderObject);
155177
};
156178

@@ -266,8 +288,12 @@ const startCreating = async () => {
266288
if (background.generate) {
267289
drawBackground();
268290
}
269-
renderObjectArray.forEach((renderObject) => {
270-
drawElement(renderObject);
291+
renderObjectArray.forEach((renderObject, index) => {
292+
drawElement(
293+
renderObject,
294+
index,
295+
layerConfigurations[layerConfigIndex].layersOrder.length
296+
);
271297
});
272298
debugLogs
273299
? console.log("Editions left to create: ", abstractedIndexes)

0 commit comments

Comments
 (0)