diff --git a/small-projects/nft-traits-gen/LICENSE b/small-projects/nft-traits-gen/LICENSE new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/small-projects/nft-traits-gen/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/small-projects/nft-traits-gen/README.md b/small-projects/nft-traits-gen/README.md new file mode 100644 index 0000000..1e8a251 --- /dev/null +++ b/small-projects/nft-traits-gen/README.md @@ -0,0 +1,25 @@ +# Prototyping a storytelling NFT + +For dev purpose only: the NFT drop is actually created on-chain. + + +--- + +### Running + +Create and edit an `.env` file: +``` +cp sample_env .env +``` + +Create an virtual env and install requirements: + +``` +pip3 install -r requirements.txt +``` + +Run: +``` +python3 gen_nfts.py +``` + diff --git a/small-projects/nft-traits-gen/gen_nfts.py b/small-projects/nft-traits-gen/gen_nfts.py new file mode 100644 index 0000000..78440ff --- /dev/null +++ b/small-projects/nft-traits-gen/gen_nfts.py @@ -0,0 +1,137 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python3 + +import os +import sys +import random +from pathlib import Path +from dotenv import load_dotenv +from PIL import Image, ImageDraw, ImageFont + + + +def create_dest_dir(final_dir): + """Crete a destination dir for NFTs""" + try: + os.mkdir("nfts") + except FileExistsError: + return + + +def get_config(key, env_path=None): + """Given a key, get the value from the env file. + Arguments: + key (str) + Return: + value(str) + """ + env_path = env_path or Path('.') / '.env' + load_dotenv(dotenv_path=env_path) + value = os.getenv(key) + + if not value: + print('📛 Please set {} in .env'.format(key)) + sys.exit(0) + return value + + +def open_trait_file(filename): + """Open a file with a list of trait strings and return that list. + Arguments: + filename (str) - file to be open + Return: + items(list) - content of the file + """ + items = [] + try: + with open(filename, "r") as f: + items = f.readlines() + items = [line.rstrip('\n') for line in items] + except IOError: + print("Could not open {}".format(filename)) + sys.exit(1) + + return items + + +def save_image(nft_num, this_nft): + """Save the the list of strings in a NFT into an image. + Arguments: + nft_num(str) - this NFT id + this_nft(str) - the content of this nft + """ + img = Image.new('RGB', (600, 600), color=(255, 255, 255)) + d = ImageDraw.Draw(img) + + fnt = ImageFont.truetype("Roboto-Medium.ttf", 30) + d.text((20, 150), this_nft, font=fnt, fill=(0, 0, 0)) + d.text((550, 30), "#{}".format(str(nft_num)), font=fnt, fill=(0, 0, 0)) + + try: + nft_name = "nft_{}.png".format(str(nft_num)) + img.save(nft_name) + except: + print("Could not save {0} with {1}".format(nft_num, this_nft)) + + +def get_traits_list(num_trait_lines): + """Return a multi-dimensional array with every trait list. + Arguments: + num_trait_lines(str) - the number of trait lines in one nft + Returns: + the final string for NFT + """ + trait_file_str = get_config("TRAIT_FILE_STR") + traits_list = [] + + for n in range(int(num_trait_lines)): + trait_file = trait_file_str.format(n) + traits_list.append(open_trait_file(trait_file)) + + return traits_list + + +def get_this_nft(num_trait_lines, traits_list): + """ Get the random content of one NFT. + Arguments: + num_trait_lines (str) - the number of trait lines in one nft + traits_list (list) - multi-dimensional list with all traits + Return: + this_nft (list) - what composes the current NFT + """ + this_nft = [] + for n in range(int(num_trait_lines)): + this_trait_list = traits_list[n] + random_trait_n = random.randint(0, len(this_trait_list)-1) + random_trait_str = this_trait_list[random_trait_n] + this_nft.append(random_trait_str) + + return "\n".join(this_nft) + + +def generate_nfts(num_edition, num_trait_lines, traits_list): + """Create and save NFT images + Arguments: + num_edition(str) - num of NFTs to be generated + num_trait_lines (str) - the number of trait lines in one nft + traits_list (list) - multi-dimensional list with all traits + """ + for n in range(1, int(num_edition) + 1): + this_nft = get_this_nft(num_trait_lines, traits_list) + save_image(n, this_nft) + + +def main(): + + num_trait_lines = get_config("NUM_TRAIT_LINES") + final_dir = get_config("FINAL_DIR") + num_edition = get_config("NUM_EDITION") + + create_dest_dir(final_dir) + traits_list = get_traits_list(num_trait_lines) + + generate_nfts(num_edition, num_trait_lines, traits_list) + + +if __name__ == "__main__": + main() diff --git a/small-projects/nft-traits-gen/nfts/nft_1.png b/small-projects/nft-traits-gen/nfts/nft_1.png new file mode 100644 index 0000000..3e51211 Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_1.png differ diff --git a/small-projects/nft-traits-gen/nfts/nft_10.png b/small-projects/nft-traits-gen/nfts/nft_10.png new file mode 100644 index 0000000..a4047cc Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_10.png differ diff --git a/small-projects/nft-traits-gen/nfts/nft_2.png b/small-projects/nft-traits-gen/nfts/nft_2.png new file mode 100644 index 0000000..2328d3b Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_2.png differ diff --git a/small-projects/nft-traits-gen/nfts/nft_3.png b/small-projects/nft-traits-gen/nfts/nft_3.png new file mode 100644 index 0000000..5abdf39 Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_3.png differ diff --git a/small-projects/nft-traits-gen/nfts/nft_4.png b/small-projects/nft-traits-gen/nfts/nft_4.png new file mode 100644 index 0000000..a677bbd Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_4.png differ diff --git a/small-projects/nft-traits-gen/nfts/nft_5.png b/small-projects/nft-traits-gen/nfts/nft_5.png new file mode 100644 index 0000000..da5e611 Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_5.png differ diff --git a/small-projects/nft-traits-gen/nfts/nft_6.png b/small-projects/nft-traits-gen/nfts/nft_6.png new file mode 100644 index 0000000..bac9617 Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_6.png differ diff --git a/small-projects/nft-traits-gen/nfts/nft_7.png b/small-projects/nft-traits-gen/nfts/nft_7.png new file mode 100644 index 0000000..b5df330 Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_7.png differ diff --git a/small-projects/nft-traits-gen/nfts/nft_8.png b/small-projects/nft-traits-gen/nfts/nft_8.png new file mode 100644 index 0000000..fd2c860 Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_8.png differ diff --git a/small-projects/nft-traits-gen/nfts/nft_9.png b/small-projects/nft-traits-gen/nfts/nft_9.png new file mode 100644 index 0000000..f13049e Binary files /dev/null and b/small-projects/nft-traits-gen/nfts/nft_9.png differ diff --git a/small-projects/nft-traits-gen/requirements.txt b/small-projects/nft-traits-gen/requirements.txt new file mode 100644 index 0000000..bfa1e59 --- /dev/null +++ b/small-projects/nft-traits-gen/requirements.txt @@ -0,0 +1,3 @@ +pillow +python-dotenv +pathlib diff --git a/small-projects/nft-traits-gen/resources/Roboto-Medium.ttf b/small-projects/nft-traits-gen/resources/Roboto-Medium.ttf new file mode 100644 index 0000000..e89b0b7 Binary files /dev/null and b/small-projects/nft-traits-gen/resources/Roboto-Medium.ttf differ diff --git a/small-projects/nft-traits-gen/sample_env b/small-projects/nft-traits-gen/sample_env new file mode 100644 index 0000000..cb44b6a --- /dev/null +++ b/small-projects/nft-traits-gen/sample_env @@ -0,0 +1,4 @@ +NUM_TRAIT_LINES = 6 +TRAIT_FILE_STR = "./{}.txt" +FINAL_DIR = "nfts" +NUM_EDITION = 10 diff --git a/small-projects/nft-traits-gen/traits/0.txt b/small-projects/nft-traits-gen/traits/0.txt new file mode 100644 index 0000000..3bf6875 --- /dev/null +++ b/small-projects/nft-traits-gen/traits/0.txt @@ -0,0 +1,8 @@ +Drama +Comedy +Action +Fantasy +Horror +Romance +Western +Thriller \ No newline at end of file diff --git a/small-projects/nft-traits-gen/traits/1.txt b/small-projects/nft-traits-gen/traits/1.txt new file mode 100644 index 0000000..f286375 --- /dev/null +++ b/small-projects/nft-traits-gen/traits/1.txt @@ -0,0 +1,10 @@ +Cape Town +Los Angeles +Prague +Lisbon +Paris +Seatle +London +Berlin +New York City +New Orleans diff --git a/small-projects/nft-traits-gen/traits/2.txt b/small-projects/nft-traits-gen/traits/2.txt new file mode 100644 index 0000000..ddd86a2 --- /dev/null +++ b/small-projects/nft-traits-gen/traits/2.txt @@ -0,0 +1,9 @@ +Robert Downey, Jr. +Samuel L. Jackson +Scarlett Johansson +Chris Hemsworth +Chris Evans +Zoe Saldana +Chris Pratt +Tom Hanks +Vin Diesel \ No newline at end of file diff --git a/small-projects/nft-traits-gen/traits/3.txt b/small-projects/nft-traits-gen/traits/3.txt new file mode 100644 index 0000000..2c99dbc --- /dev/null +++ b/small-projects/nft-traits-gen/traits/3.txt @@ -0,0 +1,8 @@ +INT. Hallway +INT. Bedroom +INT. Park +INT. Office +INT. Kitchen +EXT. Park +EXT. Lake +EXT. Highway \ No newline at end of file diff --git a/small-projects/nft-traits-gen/traits/4.txt b/small-projects/nft-traits-gen/traits/4.txt new file mode 100644 index 0000000..40199cc --- /dev/null +++ b/small-projects/nft-traits-gen/traits/4.txt @@ -0,0 +1,6 @@ +Red Dragon +Blackmagic +Hasselblade +Canon Mark V +Panasonic Lumix +ARRI Alexa \ No newline at end of file diff --git a/small-projects/nft-traits-gen/traits/5.txt b/small-projects/nft-traits-gen/traits/5.txt new file mode 100644 index 0000000..dcae984 --- /dev/null +++ b/small-projects/nft-traits-gen/traits/5.txt @@ -0,0 +1,4 @@ +popcorn +diet coke +cotton candy +bubble gum \ No newline at end of file