diff --git a/samila/functions.py b/samila/functions.py index b3a12d7..c04d653 100644 --- a/samila/functions.py +++ b/samila/functions.py @@ -1,2 +1,18 @@ # -*- coding: utf-8 -*- """Samila functions.""" + +def float_range(start, stop, step): + """ + Generate float range. + + :param start: start point + :type start: float + :param stop: stop point + :type step: float + :param step: step + :type step: float + :return: yield result + """ + while start < stop: + yield float(start) + start += step diff --git a/samila/genimage.py b/samila/genimage.py index 08a4ba3..267b0c1 100644 --- a/samila/genimage.py +++ b/samila/genimage.py @@ -1,2 +1,34 @@ # -*- coding: utf-8 -*- """Samila generative image.""" +import random +import itertools +import matplotlib.pyplot as plt +from .functions import float_range +from .params import * + +class GenerativeImage: + + def __int__(self, function1, function2): + self.function1 = function1 + self.function2 = function2 + + def generate(self, seed=None, start=DEFAULT_START, step=DEFAULT_STEP, stop=DEFAULT_STOP): + self.data1 = [] + self.data2 = [] + self.seed = seed + 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])) + + def plot(self, color=DEFAULT_COLOR, spot_size=DEFAULT_SPOT_SIZE, size=DEFAULT_IMAGE_SIZE, projection=DEFAULT_PROJECTION): + 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') + + diff --git a/samila/params.py b/samila/params.py index 4768057..b26b59c 100644 --- a/samila/params.py +++ b/samila/params.py @@ -1,2 +1,11 @@ # -*- coding: utf-8 -*- """Samila params.""" +import math + +DEFAULT_START = -1 * math.pi +DEFAULT_STOP = math.pi +DEFAULT_STEP = 0.01 +DEFAULT_COLOR = "black" +DEFAULT_IMAGE_SIZE = (10,10) +DEFAULT_SPOT_SIZE = 0.01 +DEFAULT_PROJECTION = None