Skip to content

Commit

Permalink
Merge pull request #1 from tdotholla/khb/tryforvercel
Browse files Browse the repository at this point in the history
Khb/tryforvercel
  • Loading branch information
Kiel-H-Byrne authored Oct 7, 2021
2 parents 3f1a9a3 + d37e356 commit 5e3d34d
Show file tree
Hide file tree
Showing 33 changed files with 13,656 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

/.idea
/.idea
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,55 @@ When you are all ready, run the following command and your outputted art will be
npm run build
```



# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).



29 changes: 29 additions & 0 deletions _tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "esnext",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"outDir": "dist",
"allowJs": true,
"importHelpers": true,
"removeComments": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true
},
"include": [
"src"
]
}
File renamed without changes.
46 changes: 46 additions & 0 deletions gen/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// const layersOrder = [
// { name: 'background', number: 1 },
// { name: 'shine', number: 1 },
// { name: 'ball', number: 2 },
// { name: 'iris', number: 3 },
// { name: 'bottom lid', number: 3 },
// { name: 'top lid', number: 3 },
// { name: 'eye color', number: 12 },
// ];

const layersOrder = [
{ name: 'nameplate', number: 1 },
// { name: 'background', number: 2 },
{ name: 'face', number: 1 },
{ name: 'hair', number: 1 },
{ name: 'moustache', number: 1 },
{ name: 'eyebrows', number: 1 },
{ name: 'goatee', number: 2 },
{ name: 'nose', number: 1 },
{ name: 'eyes', number: 1 },
{ name: 'teeth', number: 1 },
{ name: 'pupils', number: 1 },
{ name: 'lips', number: 1 },
{ name: 'blunt_body', number: 4 },
{ name: 'blunt_smoke', number: 4 },
];

// const format = {
// width: 230,
// height: 230
// };

const format = {
width: 540,// 10800,
height: 720// 14400
}

const rarity = [
{ key: "", val: "original" },
{ key: "_r", val: "rare" },
{ key: "_sr", val: "super rare" },
];

const defaultEdition = 4;

export { layersOrder, format, rarity, defaultEdition };
4 changes: 2 additions & 2 deletions index.js → gen/generate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const myArgs = process.argv.slice(2);
const { buildSetup, createFiles, createMetaData } = require("./src/main.js");
const { defaultEdition } = require("./src/config.js");
const { buildSetup, createFiles, createMetaData } = require("./main.js");
const { defaultEdition } = require("./config.js");
const edition = myArgs.length > 0 ? Number(myArgs[0]) : defaultEdition;

(() => {
Expand Down
11 changes: 11 additions & 0 deletions gen/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defaultEdition } from "./config";
import { buildSetup, createFiles, createMetaData } from "./main";
const myArgs = process.argv.slice(2);
const edition = myArgs.length > 0 ? Number(myArgs[0]) : defaultEdition;

(() => {
buildSetup();
createFiles(edition);
createMetaData();
})();

2 changes: 1 addition & 1 deletion src/main.js → gen/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const createMetaData = () => {
fs.stat(`${buildDir}/${metDataFile}`, (err) => {
if(err == null || err.code === 'ENOENT') {
fs.writeFileSync(`${buildDir}/${metDataFile}`, JSON.stringify(metadata, null, 2));
console.log(JSON.stringify(metadata, null, 2))
// console.log(JSON.stringify(metadata, null, 2))
} else {
console.log('Oh no, error: ', err.code);
}
Expand Down
151 changes: 151 additions & 0 deletions gen/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import * as fs from "fs";
import { createCanvas, loadImage } from "canvas";
import console from "console";
import { layersOrder, format, rarity } from "./config";

const canvas = createCanvas(format.width, format.height);
const ctx = canvas.getContext("2d");

if (!process.env.PWD) {
process.env.PWD = process.cwd();
}

const buildDir = `${process.env.PWD}/build`;
const metDataFile = '_metadata.json';
const layersDir = `${process.env.PWD}/layers`;

let metadata: any[] = [];
let attributes: any[] = [];
let hash: any[] = [];
let decodedHash: any[] = [];

const addRarity = (_str: string) => {
let itemRarity;

rarity.forEach((r) => {
if (_str.includes(r.key)) {
itemRarity = r.val;
}
});

return itemRarity;
};

const cleanName = (_str: string) => {
let name = _str.slice(0, -4);
rarity.forEach((r) => {
name = name.replace(r.key, "");
});
return name;
};

const getElements = (path: string) => {
return fs
.readdirSync(path)
.filter((item) => !/(^|\/)\.[^\/\.]/g.test(item))
.map((i, index) => {
return {
id: index + 1,
name: cleanName(i),
fileName: i,
rarity: addRarity(i),
};
});
};

const layersSetup = (layersOrder: any[]) => {
const layers = layersOrder.map((layerObj, index) => ({
id: index,
name: layerObj.name,
location: `${layersDir}/${layerObj.name}/`,
elements: getElements(`${layersDir}/${layerObj.name}/`),
position: { x: 0, y: 0 },
size: { width: format.width, height: format.height },
number: layerObj.number
}));

return layers;
};

const buildSetup = () => {
if (fs.existsSync(buildDir)) {
fs.rmdirSync(buildDir, { recursive: true });
}
fs.mkdirSync(buildDir);
};

const saveLayer = (_canvas: any, _edition: number) => {
fs.writeFileSync(`${buildDir}/${_edition}.png`, _canvas.toBuffer("image/png"));
};

const addMetadata = (_edition: number) => {
let dateTime = Date.now();
let tempMetadata = {
hash: hash.join(""),
decodedHash: decodedHash,
edition: _edition,
date: dateTime,
attributes: attributes,
};
metadata.push(tempMetadata);
attributes = [];
hash = [];
decodedHash = [];
};

const addAttributes = (_element: any, _layer: any) => {
let tempAttr = {
id: _element.id,
layer: _layer.name,
name: _element.name,
rarity: _element.rarity,
};
attributes.push(tempAttr);
hash.push(_layer.id);
hash.push(_element.id);
decodedHash.push({ [_layer.id]: _element.id });
};

const drawLayer = async (_layer: any, _edition: number) => {
const rand = Math.random();
let element =
_layer.elements[Math.floor(rand * _layer.number)] ? _layer.elements[Math.floor(rand * _layer.number)] : null;
if (element) {
addAttributes(element, _layer);
const image = await loadImage(`${_layer.location}${element.fileName}`);

ctx.drawImage(
image,
_layer.position.x,
_layer.position.y,
_layer.size.width,
_layer.size.height
);
saveLayer(canvas, _edition);
}
};

const createFiles = (edition: number) => {
const layers = layersSetup(layersOrder);

for (let i = 1; i <= edition; i++) {
layers.forEach((layer) => {
drawLayer(layer, i);
});
addMetadata(i);
console.log("Creating edition " + i);
}
};

const createMetaData = () => {
fs.stat(`${buildDir}/${metDataFile}`, (err) => {
if (err == null || err.code === 'ENOENT') {
fs.writeFileSync(`${buildDir}/${metDataFile}`, JSON.stringify(metadata, null, 2));
// console.log(JSON.stringify(metadata, null, 2))
} else {
console.log('Oh no, error: ', err.code);
}
});
};

export { buildSetup, createFiles, createMetaData };
57 changes: 47 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,52 @@
{
"name": "art_generator",
"version": "1.0.0",
"description": "",
"main": "index.js",
"name": "app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@chakra-ui/react": "^1.6.9",
"@emotion/react": "11",
"@emotion/styled": "11",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"canvas": "^2.8.0",
"esm": "^3.2.25",
"framer-motion": "4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
"devDependencies": {
"@types/jest": "^26.0.15",
"@types/node": "^16.10.3",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0"
},
"scripts": {
"build": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"code-gen": "node gen/generate.js",
"start": "react-scripts start",
"build": "yarn code-gen && react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"author": "Daniel Eugene Botha",
"license": "ISC",
"dependencies": {
"canvas": "^2.8.0"
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added public/favicon.ico
Binary file not shown.
Binary file added public/gallery/1.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 public/gallery/2.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 public/gallery/3.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 public/gallery/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

1 comment on commit 5e3d34d

@vercel
Copy link

@vercel vercel bot commented on 5e3d34d Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.