Skip to content

Commit

Permalink
Multiprocessing (#36)
Browse files Browse the repository at this point in the history
* prepare to implement multiprocessing

* slowly getting it to work...

* added threads command and cmdline options, added screenshots and more commenting

* add screenshot_threads

* use app.render_settings instead or app.settings.render_settings
  • Loading branch information
SkwalExe authored Nov 23, 2023
1 parent d0a7960 commit 29e38b0
Show file tree
Hide file tree
Showing 16 changed files with 406 additions and 228 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 1.0.0 - 2023-11-23

### Added
- multithreading (multiprocessing)
- `--threads/-t` option
- `threads` command
- screenshot threads (also command and cmdline option)
- A lot of new bugs for sure...

### Improved
- Code quality (a lot)

# 0.6.0 - 2023-11-16

### Added
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ TEXTUAL=devtools,debug python3 -m fractalistic

![Screenshot 4](https://raw.githubusercontent.com/SkwalExe/fractalistic/main/assets/screenshot4.png)

![Screenshot 5](https://raw.githubusercontent.com/SkwalExe/fractalistic/main/assets/screenshot5.png)
![Screenshot 5](https://raw.githubusercontent.com/SkwalExe/fractalistic/main/assets/screenshot5.png)

![Screenshot 6](https://raw.githubusercontent.com/SkwalExe/fractalistic/main/assets/screenshot6.png)

![Screenshot 7](https://raw.githubusercontent.com/SkwalExe/fractalistic/main/assets/screenshot7.png)

![Screenshot 8](https://raw.githubusercontent.com/SkwalExe/fractalistic/main/assets/screenshot8.png)
Binary file added assets/screenshot6.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 assets/screenshot7.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 assets/screenshot8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion fractalistic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Terminal based fractal explorer, including Mandelbrot, Burning Ship, and Julia."""

__version__ = "0.6.0"
__version__ = "1.0.0"
88 changes: 62 additions & 26 deletions fractalistic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,61 @@
from .app import FractalisticApp
from . import __version__
from .colors import color_renderers
from .vec import Vec
from .settings import Settings
from .fractals import fractal_list
###### Others
import gmpy2
###############




@extra_command(params=[])
@option("-ls", "--load-state", help="Load state from a file", type=STRING)
@option("-df", "--default-fractal", help="Default fractal to show when starting the program.", type=Choice([frac.__name__ for frac in fractal_list], False), default="Mandelbrot")
@option("-dc", "--default-color", help="Default color to use when starting the program.", type=Choice([color.__name__ for color in color_renderers], False), default="blue_brown")
@option("-p", "--decimal-precision", help="Fine-tune numeric precision by specifying the desired bit length for numeric values", type=IntRange(5), default=64)
@option("-i", "--max-iter", help="This option defines the number of iterations required to classify a point as convergent", type=IntRange(5), default=128)
@option("-s", "--size", nargs=2, help="Manually set the screenshots width and height. Wont work if you use -f.", type=IntRange(32), default=(1920, 1080))
@option("-f", "--fit", help="Fit screenshots with the canvas.", is_flag=True)
@option("-q", "--quality", help="Only when using --fit, set the quality of screenshots by multiplying the original size in the terminal by the specified scaling factor.", type=IntRange(1), default=20)
@option("-v", "--version", help="Show version number and exit", is_flag=True)
@option("--debug", help="Enable debug mode for developers.", is_flag=True)
def main(fit: bool, quality: float, size: tuple[int, int], default_fractal: str, default_color: str, debug: bool, decimal_precision: int, max_iter: int, version: bool, load_state: str):
@option("-t", "--threads",
help="Number of threads to use for rendering",
type=IntRange(1),
default=Settings.threads)
@option("-st", "--screenshot-threads",
help="Number of threads to use for rendering HQ screenshots",
type=IntRange(1),
default=Settings.screenshot_threads)
@option("-ls", "--load-state",
help="Load state from a file",
type=STRING)
@option("-df", "--default-fractal",
help="Default fractal to show when starting the program.",
type=Choice([frac.__name__ for frac in fractal_list], False),
default="Mandelbrot")
@option("-dc", "--default-color",
help="Default color to use when starting the program.",
type=Choice([color.__name__ for color in color_renderers], False),
default="blue_brown")
@option("-p", "--decimal-precision",
help="Fine-tune numeric precision by specifying the desired bit length for numeric values",
type=IntRange(5),
default=Settings.render_settings.wanted_numeric_precision)
@option("-i", "--max-iter",
help="This option defines the number of iterations required to classify a point as convergent",
type=IntRange(5),
default=Settings.render_settings.max_iter)
@option("-s", "--size",
nargs=2,
help="Manually set the screenshots width and height. Wont work if you use -f.",
type=IntRange(32),
default=(Settings.screenshot_size.x, Settings.screenshot_size.y))
@option("-f", "--fit",
help="Fit screenshots with the canvas.",
is_flag=True)
@option("-q", "--quality",
help="Only when using --fit, set the quality of screenshots by multiplying the original size in the terminal by the specified scaling factor.",
type=IntRange(1),
default=Settings.screenshot_quality)
@option("-v", "--version",
help="Show version number and exit",
is_flag=True)
@option("--debug",
help="Enable debug mode for developers.",
is_flag=True)

def main(fit: bool, quality: float, size: tuple[int, int], default_fractal: str, default_color: str, debug: bool, decimal_precision: int, max_iter: int, version: bool, load_state: str, threads: int, screenshot_threads: int):

# If -v or --version is used, show version and exit
if version:
Expand All @@ -38,20 +73,21 @@ def main(fit: bool, quality: float, size: tuple[int, int], default_fractal: str,
app = FractalisticApp()

# Set default fractal
app.fractal_index = get_fractal_index_from_name(default_fractal)
app.settings.render_settings.fractal_index = get_fractal_index_from_name(default_fractal)

# Set default color
app.color_renderer_index = get_color_index_from_name(default_color)

app.options = {
"fit_screenshots": fit,
"screenshot_quality": quality,
"size": None if size is None else Vec(size[0], size[1]),
"max_iter": max_iter,
"debug": debug,
"numeric_precision": decimal_precision,
"state_file": load_state
}
app.settings.render_settings.color_renderer_index = get_color_index_from_name(default_color)

app.settings.fit_screenshots = fit
app.settings.debug = debug
app.settings.screenshot_quality = quality
app.settings.screenshot_size = Vec(size[0], size[1])
app.settings.max_iter = max_iter
app.settings.render_settings.wanted_numeric_precision = decimal_precision
app.settings.state_file = load_state
app.settings.threads = threads
app.settings.screenshot_threads = screenshot_threads

app.run()

if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 29e38b0

Please sign in to comment.