Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Art Gallery/sample/sample_image_0.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 Art Gallery/sample/sample_image_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 Art Gallery/sample/sample_image_10.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 Art Gallery/sample/sample_image_11.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 Art Gallery/sample/sample_image_12.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 Art Gallery/sample/sample_image_13.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 Art Gallery/sample/sample_image_14.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 Art Gallery/sample/sample_image_15.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 Art Gallery/sample/sample_image_16.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 Art Gallery/sample/sample_image_17.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 Art Gallery/sample/sample_image_18.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 Art Gallery/sample/sample_image_19.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 Art Gallery/sample/sample_image_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 Art Gallery/sample/sample_image_20.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 Art Gallery/sample/sample_image_21.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 Art Gallery/sample/sample_image_22.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 Art Gallery/sample/sample_image_23.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 Art Gallery/sample/sample_image_24.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 Art Gallery/sample/sample_image_25.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 Art Gallery/sample/sample_image_26.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 Art Gallery/sample/sample_image_27.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 Art Gallery/sample/sample_image_28.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 Art Gallery/sample/sample_image_29.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 Art Gallery/sample/sample_image_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 Art Gallery/sample/sample_image_30.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 Art Gallery/sample/sample_image_31.png
Binary file added Art Gallery/sample/sample_image_4.png
Binary file added Art Gallery/sample/sample_image_5.png
Binary file added Art Gallery/sample/sample_image_6.png
Binary file added Art Gallery/sample/sample_image_7.png
Binary file added Art Gallery/sample/sample_image_8.png
Binary file added Art Gallery/sample/sample_image_9.png
165 changes: 165 additions & 0 deletions Generate_Art.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
from PIL import Image, ImageDraw, ImageChops
import random
import os
import colorsys
import argparse

from numpy import reciprocal

def random_point(image_size_px: int, padding: int) -> tuple:
"""Generate a random point within the given image size,
and avoid the boundaries with the given padding value.

Args:
image_size_px (int): size of the image in pixels.
padding (int): size of the padding of the boader to be avoided.

Return:
tuple: (x, y) coordinate.
"""
return (random.randint(padding, image_size_px - padding),
random.randint(padding, image_size_px - padding))

def random_color() -> tuple:
"""First Generate a random color in HSV(Hue, Saturation, Value) format,
with fully saturated and fully bright color and then convert the
color into RGB Format.

Args:
None

Return:
tuple: (R, G, B) color.
"""
random_H = random.random()
S = 1
V = 1
color_RGB = colorsys.hsv_to_rgb(random_H, S, V)
color_RGB = [int(channel * 255) for channel in color_RGB]

return tuple(color_RGB)

def interpolate(start_color: tuple, end_color: tuple, factor: float) -> tuple:
"""Return the blend color of start_color and end_color depending on the factor.
or finding the color that is exactly factor (0.0 - 1.0) between the two colors.

Args:
start_color (tuple): (R, G, B) color format.
end_color (tuple): (R, G, B) color format.
factor (float): factor between 0 and 1.

Returns:
tuple: (R, G, B) color.
"""
reciprocal = 1 - factor

return (int(start_color[0]*reciprocal + end_color[0]*factor),
int(start_color[1]*reciprocal + end_color[1]*factor),
int(start_color[2]*reciprocal + end_color[2]*factor))

def generate_art(art_collection: str, art_name: str, art_size_px: int, total_line: int):
"""This is the main function to generate a art image,
and store it in the given collection path with the
given name.

Args:
art_collection (str): path of the folder.
art_name (str): name of the image.
art_size_px (int): size of the image in px.
total_line (int): Total number of lines to be drawn.
"""
print("Generating Art!")

# Create the path to the directory where we will store the images
Art_Gallery_Path = os.path.join("Art Gallery", art_collection)
Art_Path = os.path.join(Art_Gallery_Path, f"{art_name}.png")

# Setting The Size Parameter
RESCALE_FACTOR = 2
Image_Size_Px = art_size_px * RESCALE_FACTOR
PADDING = int(Image_Size_Px * 0.1)

# Create the directory to store the Arts
os.makedirs(Art_Gallery_Path, exist_ok = True)

# Create an Canvas for the Art
BACKGROUND_COLOR = (0, 0, 0) # Black
canvas = Image.new(mode = "RGB", size = (Image_Size_Px, Image_Size_Px), color = BACKGROUND_COLOR)

# Generate random points for the lines
points = []

for _ in range(total_line):
points.append(random_point(Image_Size_Px, PADDING))

# Get The Minimum and Maximum x and y Coordinates.
min_x = min([point[0] for point in points])
max_x = max([point[0] for point in points])
min_y = min([point[1] for point in points])
max_y = max([point[1] for point in points])

# centralize the art in the image.
delta_x = min_x - Image_Size_Px + max_x
delta_y = min_y - Image_Size_Px + max_y

# Centralize all the points.
points = [(point[0] - delta_x // 2, point[1] - delta_y // 2) for point in points]

# Select Random Color
Start_Color = random_color()
End_Color = random_color()

# Line Drawing Parameter
Thickness = 1
THICKNESS_FACTOR = total_line // 5
Total_Points = len(points)

# Draw The Art
for i, point in enumerate(points):
# create a overlay canvas
overlay_art = Image.new(mode = "RGB", size = (Image_Size_Px, Image_Size_Px), color = BACKGROUND_COLOR)
overlay_draw = ImageDraw.Draw(overlay_art)

if i == Total_Points - 1:
# connect the last point back to the first point.
second_point = points[0]
else:
# connect the next point.
second_point = points[i + 1]

# interpolate the colors
interpolate_factor = i / (Total_Points - 1)
line_color = interpolate(start_color = Start_Color, end_color = End_Color, factor = interpolate_factor)

# Draw the line.
overlay_draw.line(xy = (point, second_point), fill = line_color, width = Thickness)

# Increase the thickness of the line.
Thickness += THICKNESS_FACTOR

# Add the overlay channel.
canvas = ImageChops.add(overlay_art, canvas)

# Art is Ready! Now resize it to be smooth.
canvas = canvas.resize(size = (art_size_px, art_size_px),
resample = Image.ANTIALIAS)

# Save the Art
canvas.save(Art_Path)


if(__name__ == "__main__"):
parser = argparse.ArgumentParser()
parser.add_argument("-n", type = int, default = 1, help = "Number of arts to be generated.")
parser.add_argument("--gallery", type = str, help = "Art Collection Gallery name.")
parser.add_argument("--size", type = int, default = 256, help = "Size of the Image.")
parser.add_argument("--l", type = int, default = 10, help = "Total number of lines in the Image.")

args = parser.parse_args()
n = args.n
gallery_collection = args.gallery
image_size = args.size
l = args.l

for i in range(n):
generate_art(gallery_collection, f"{gallery_collection}_image_{i}", image_size, l)
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,34 @@ pip install pillow
You can run it like this.

```bash
# Generates a collection called 'foo' with 32 pieces into ./output/foo/
python src/generate_art.py -n 32 --collection "foo"
# The above command will create a directory "Art Gallery" and a child Directory named "sample". Inside the "sample" directory the art image of size 1024 x 1024 will be generated and stored.
python Generate_Art.py -n 32 --gallery "sample" --size 1024 --l 15
```

It should generate an image like this:

![example_image](images/gamma_image_5.png)
<a href = "https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_12.png">
<img src="https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_12.png" alt="sample art 1" width="256px" height="256px"/>
</a>

<a href = "https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_2.png">
<img src="https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_2.png" alt="sample art 2" width="256px" height="256px"/>
</a>

<a href = "https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/srajan/srajan_image_0.png">
<img src="https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/srajan/srajan_image_0.png" alt="sample art 3" width="256px" height="256px"/>
</a>

<a href = "https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_31.png">
<img src="https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_31.png" alt="sample art 4" width="256px" height="256px"/>
</a>

<a href = "https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_13.png">
<img src="https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_13.png" alt="sample art 5" width="256px" height="256px"/>
</a>

<a href = "https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_18.png">
<img src="https://github.com/srajan-kiyotaka/NFT-Generative-Art-using-Python/blob/master/Art%20Gallery/sample/sample_image_18.png" alt="sample art 6" width="256px" height="256px"/>
</a>

### Contributed by [Srajan Chourasia](https://github.com/srajan-kiyotaka)
135 changes: 0 additions & 135 deletions src/generate_art.py

This file was deleted.