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

func_seed added #201

Merged
merged 5 commits into from
Dec 5, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `get_cmap` function
- `Gateway` enum
### Changed
- `func_seed` parameter added to GenerativeImage `__init__`
- minor edits in `functions.py`
- `DEFAULT_CMAP` renamed to `DEFAULT_CMAP_NAME`
- `pillow` added to conda dependencies
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Samila is a generative art generator written in Python, Samila lets you create i
```
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/7.png">

* You can change function generation seed by `func_seed` parameter in `GenerativeImage`

### Basic
```pycon
>>> import random
Expand Down
12 changes: 11 additions & 1 deletion samila/genimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ class GenerativeImage:
>>> GI = GenerativeImage(f1, f2)
"""

def __init__(self, function1=None, function2=None, data=None, config=None):
def __init__(
self,
function1=None,
function2=None,
data=None,
config=None,
func_seed=None):
"""
Init method.

Expand All @@ -38,6 +44,8 @@ def __init__(self, function1=None, function2=None, data=None, config=None):
:type data: (io.IOBase & file)
:param config: generative image config
:type config: (io.IOBase & file)
:param func_seed: random seed for function generation
:type func_seed: Any
"""
_GI_initializer(self, function1, function2)
if config is not None:
Expand All @@ -53,6 +61,8 @@ def __init__(self, function1=None, function2=None, data=None, config=None):
self.python_version,
self.__version__),
RuntimeWarning)
if func_seed is not None:
random.seed(func_seed)
if self.function1 is None:
if self.function1_str is None:
self.function1_str = random_equation_gen()
Expand Down
9 changes: 9 additions & 0 deletions test/overall_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@
True
>>> del(g1)
>>> del(g2)
>>> random.seed(22)
>>> g = GenerativeImage()
>>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2)
>>> g_ = GenerativeImage(func_seed=22)
>>> g_.generate(start=-2*math.pi, step=0.1, stop=math.pi/2)
>>> g.function1_str == g_.function1_str
True
>>> g.function2_str == g_.function2_str
True
>>> os.remove("test.png")
>>> os.remove("test2.png")
>>> os.remove("data.json")
Expand Down
Loading