2021-09-20 19:58:52 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""Samila generative image."""
|
2021-09-26 20:40:20 +00:00
|
|
|
import random
|
|
|
|
import itertools
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
from .functions import float_range
|
|
|
|
from .params import *
|
|
|
|
|
2021-09-27 07:18:06 +00:00
|
|
|
|
2021-09-26 20:40:20 +00:00
|
|
|
class GenerativeImage:
|
|
|
|
|
2021-09-26 20:54:11 +00:00
|
|
|
def __init__(self, function1, function2):
|
2021-09-26 20:40:20 +00:00
|
|
|
self.function1 = function1
|
|
|
|
self.function2 = function2
|
|
|
|
|
2021-09-27 07:18:06 +00:00
|
|
|
def generate(
|
|
|
|
self,
|
|
|
|
seed=None,
|
|
|
|
start=DEFAULT_START,
|
|
|
|
step=DEFAULT_STEP,
|
|
|
|
stop=DEFAULT_STOP):
|
2021-09-27 07:38:15 +00:00
|
|
|
"""
|
|
|
|
Generate a raw format of art.
|
|
|
|
|
|
|
|
:param seed: random seed
|
|
|
|
:type seed: int
|
|
|
|
:param start: range start point
|
|
|
|
:type start: float
|
|
|
|
:param step: range step size
|
|
|
|
:type step: float
|
|
|
|
:param stop: range stop point
|
|
|
|
:type stop: float
|
|
|
|
:return: None
|
|
|
|
"""
|
2021-09-26 20:40:20 +00:00
|
|
|
self.data1 = []
|
|
|
|
self.data2 = []
|
|
|
|
self.seed = seed
|
2021-09-27 16:13:28 +00:00
|
|
|
if seed is None:
|
|
|
|
self.seed = random.randint(0, 2 ** 20)
|
2021-09-26 20:40:20 +00:00
|
|
|
random.seed(self.seed)
|
|
|
|
range1 = list(float_range(start, stop, step))
|
|
|
|
range2 = list(float_range(start, stop, step))
|
|
|
|
range_prod = list(itertools.product(range1, range2))
|
|
|
|
for item in range_prod:
|
|
|
|
self.data1.append(self.function1(item[0], item[1]))
|
|
|
|
self.data2.append(self.function2(item[0], item[1]))
|
|
|
|
|
2021-09-27 07:18:06 +00:00
|
|
|
def plot(
|
|
|
|
self,
|
|
|
|
color=DEFAULT_COLOR,
|
|
|
|
spot_size=DEFAULT_SPOT_SIZE,
|
|
|
|
size=DEFAULT_IMAGE_SIZE,
|
|
|
|
projection=DEFAULT_PROJECTION):
|
2021-09-27 07:38:40 +00:00
|
|
|
"""
|
|
|
|
Plot the generated art.
|
|
|
|
|
|
|
|
:param color: point colors
|
|
|
|
:type color: str
|
|
|
|
:param spot_size: point spot size
|
|
|
|
:type spot_size: float
|
|
|
|
:param size: figure size
|
|
|
|
:type size: tuple
|
|
|
|
:param projection: projection type
|
|
|
|
:type projection: str
|
|
|
|
:return: None
|
|
|
|
"""
|
2021-09-26 20:40:20 +00:00
|
|
|
fig = plt.figure()
|
|
|
|
fig.set_size_inches(size[0], size[1])
|
|
|
|
ax = fig.add_subplot(111, projection=projection)
|
|
|
|
ax.scatter(self.data2, self.data1, alpha=0.1, c=color, s=spot_size)
|
|
|
|
ax.axis('off')
|