From 3c0144d045a610d74c02c9fef4afc5e83d48df95 Mon Sep 17 00:00:00 2001 From: Sepand Haghighi Date: Fri, 23 Aug 2024 03:26:09 +0330 Subject: [PATCH] New `GenerateMode` (#222) * fix : f1,f2 renamed to f1_vs_index and f2_vs_index * feat : 2 new generate mode added * fix : overall_test.py updated * doc : README.md updated * fix : minor typo in overall_test.py fixed * fix : minor edit in generate method --- README.md | 4 ++-- samila/genimage.py | 14 ++++++++++---- samila/params.py | 6 ++++-- test/overall_test.py | 18 ++++++++++++------ 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9329e9d..0250544 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ Samila is a generative art generator written in Python, Samila lets you create i ```pycon >>> from samila import GenerateMode >>> g = GenerativeImage(f1, f2) ->>> g.generate(mode=GenerateMode.F1) +>>> g.generate(mode=GenerateMode.F1_VS_INDEX) >>> g.plot() >>> g.seed 883114 @@ -122,7 +122,7 @@ Samila is a generative art generator written in Python, Samila lets you create i ``` -* Supported modes : `F1_VS_F2`, `F2_VS_F1`, `F1`, and `F2` +* Supported modes : `F1_VS_F2`, `F2_VS_F1`, `F1_VS_INDEX`, `F2_VS_INDEX`, `INDEX_VS_F1` and `INDEX_VS_F2` * Default mode is `F1_VS_F2` ### Projection diff --git a/samila/genimage.py b/samila/genimage.py index 4a28181..65d7eb5 100644 --- a/samila/genimage.py +++ b/samila/genimage.py @@ -103,18 +103,24 @@ class GenerativeImage: for index, point in enumerate(range_prod): random.seed(self.seed) try: - if self.generate_mode == "f1_vs_f2": + if self.generate_mode == GenerateMode.F1_VS_F2.value: data1_ = self.function1(point[0], point[1]).real data2_ = self.function2(point[0], point[1]).real - elif self.generate_mode == "f2_vs_f1": + elif self.generate_mode == GenerateMode.F2_VS_F1.value: data2_ = self.function1(point[0], point[1]).real data1_ = self.function2(point[0], point[1]).real - elif self.generate_mode == "f2": + elif self.generate_mode == GenerateMode.F2_VS_INDEX.value: data2_ = index data1_ = self.function2(point[0], point[1]).real - elif self.generate_mode == "f1": + elif self.generate_mode == GenerateMode.F1_VS_INDEX.value: data2_ = index data1_ = self.function1(point[0], point[1]).real + elif self.generate_mode == GenerateMode.INDEX_VS_F1.value: + data1_ = index + data2_ = self.function1(point[0], point[1]).real + elif self.generate_mode == GenerateMode.INDEX_VS_F2.value: + data1_ = index + data2_ = self.function2(point[0], point[1]).real self.data1.append(data1_) self.data2.append(data2_) except Exception: diff --git a/samila/params.py b/samila/params.py index 28300f5..8236216 100644 --- a/samila/params.py +++ b/samila/params.py @@ -68,8 +68,10 @@ class GenerateMode(Enum): DEFAULT = DEFAULT_GENERATE_MODE F1_VS_F2 = "f1_vs_f2" F2_VS_F1 = "f2_vs_f1" - F1 = "f1" - F2 = "f2" + F1_VS_INDEX = "f1_vs_index" + F2_VS_INDEX = "f2_vs_index" + INDEX_VS_F1 = "index_vs_f1" + INDEX_VS_F2 = "index_vs_f2" class Gateway(Enum): diff --git a/test/overall_test.py b/test/overall_test.py index 3eb578a..2d3e4ea 100644 --- a/test/overall_test.py +++ b/test/overall_test.py @@ -372,14 +372,20 @@ True True >>> random.seed(22) >>> g = GenerativeImage() ->>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2, mode=GenerateMode.F1) ->>> g.generate_mode == GenerateMode.F1.value +>>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2, mode=GenerateMode.F1_VS_INDEX) +>>> g.generate_mode == GenerateMode.F1_VS_INDEX.value True ->>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2, mode=GenerateMode.F2) ->>> g.generate_mode == GenerateMode.F2.value +>>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2, mode=GenerateMode.F2_VS_INDEX) +>>> g.generate_mode == GenerateMode.F2_VS_INDEX.value True ->>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2, mode=GenerateMode.F2) ->>> g.generate_mode == GenerateMode.F2.value +>>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2, mode=GenerateMode.INDEX_VS_F1) +>>> g.generate_mode == GenerateMode.INDEX_VS_F1.value +True +>>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2, mode=GenerateMode.INDEX_VS_F2) +>>> g.generate_mode == GenerateMode.INDEX_VS_F2.value +True +>>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2, mode=GenerateMode.F1_VS_F2) +>>> g.generate_mode == GenerateMode.F1_VS_F2.value True >>> g.generate(start=-2*math.pi, step=0.1, stop=math.pi/2, mode=GenerateMode.F2_VS_F1) >>> g.generate_mode == GenerateMode.F2_VS_F1.value