Skip to content

Commit

Permalink
Scalar Speed Patch and Large number printing
Browse files Browse the repository at this point in the history
  • Loading branch information
AwesomeDude091 committed Nov 22, 2022
1 parent 9acf798 commit 6a87686
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 26 deletions.
Binary file modified 0-rect.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 modified 0.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 modified 1-rect.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 modified 1.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 modified 2-rect.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 modified 2.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 modified 3-rect.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 modified 3.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 modified 4-rect.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 modified 4.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 modified 5-rect.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 modified 5.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 modified 6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 14 additions & 10 deletions MandelView.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

import cv2
import pygame
from PIL import Image
Expand All @@ -7,7 +9,7 @@


class MandelView:
def __init__(self, width, height, cores, iterations, color_iterations):
def __init__(self, width, height, cores, iterations, color_iterations, scalar=1):
self.width = width
self.height = height
self.cores = cores
Expand All @@ -21,10 +23,11 @@ def __init__(self, width, height, cores, iterations, color_iterations):
self.window_x_end = 8/3
self.window_y = -1.5
self.window_y_end = 1.5
self.scalar = scalar
self.img = None

def start(self):
index = 0
self.index = 0
monitor = None
for m in get_monitors():
if m.is_primary:
Expand All @@ -42,7 +45,7 @@ def start(self):
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_CROSSHAIR)
pygame.display.set_caption('Mandelbulb')
screen.blit(self.pilImageToSurface(tempImg), (0, 0))
pygame.image.save(screen, str(index) + '.png')
pygame.image.save(screen, str(self.index) + '.png')
pygame.display.flip()
first_click = True
image_ready = False
Expand Down Expand Up @@ -73,12 +76,12 @@ def start(self):
image_ready = True
elif e.type == pygame.KEYDOWN:
if pygame.key.name(e.key) == 'return' and image_ready:
pygame.image.save(screen, str(index) + '-rect.png')
pygame.image.save(screen, str(self.index) + '-rect.png')
self.img = self.give_game_image(monitor)
screen.blit(self.pilImageToSurface(self.img), (0, 0))
pygame.display.flip()
index += 1
pygame.image.save(screen, str(index) + '.png')
self.index += 1
pygame.image.save(screen, str(self.index) + '.png')
image_ready = False
elif pygame.key.name(e.key) == 'q':
pygame.quit()
Expand All @@ -87,8 +90,8 @@ def set_iterations(self, iterations):
self.iterations = iterations

def give_game_image(self, monitor):
brot = Mandelbrot(self.width, self.height, self.cores, self.iterations, debug=True,
color_iteration=self.color_iterations)
brot = Mandelbrot(self.width, self.height, self.cores, int(self.iterations * math.pow(self.scalar, self.index + 1)),
debug=True, color_iteration=self.color_iterations)
real_start_x = ((self.start_x * (self.width / monitor.width) *
(self.window_x_end - self.window_x)) / self.width) + self.window_x
real_end_x = ((self.end_x * (self.width / monitor.width) *
Expand All @@ -105,7 +108,8 @@ def give_game_image(self, monitor):
self.window_y = real_start_y
self.window_y_end = real_end_y
print("Area: ")
print(real_start_x, real_end_x, real_start_y)
print(format(real_start_x, '.100g'), format(real_end_x, '.100g'), format(real_start_y, '.100g'))
print("Iterations: " + str((self.iterations * math.pow(self.scalar, self.index + 1))))
return tempImg.resize((monitor.width, monitor.height))

@staticmethod
Expand All @@ -115,4 +119,4 @@ def pilImageToSurface(pilImage):


if __name__ == '__main__':
MandelView(3840, 2160, 24, 16384, 1).start()
MandelView(3840, 2160, 24, 256, 8, scalar=3).start()
32 changes: 16 additions & 16 deletions Mandelbrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ def generate_image(self, start_x: float, end_x: float, start_y: float):
img = cv2.flip(cv2.cvtColor(self.get_image_array(), cv2.COLOR_RGB2BGR), 0)
cv2.imwrite('test.jpg', img)

def get_image_array(self):
return self.array

def is_out_of_bounds(self, cmplx):
z = complex(0, 0)
t = 0
for i in range(0, self.max_iterations):
z = z ** 2 + cmplx
t = i
if abs(z) > 1000:
break

if abs(z) >= 2:
return t
return 0

def generate_gpu_image(self, start_x: float, end_x: float, start_y: float):
os.environ['CUDA_PATH'] = 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.8'
start_x, end_x, start_y, end_y = self.calc_window(start_x, end_x, start_y)
Expand Down Expand Up @@ -156,22 +172,6 @@ def cuda_points(self, array, start_x, start_y, x_iteration, y_iteration, y_max,
np.int32(self.image_width), block=(1024, 1, 1))
return np.array(fractal.get(), dtype=np.uint8)

def get_image_array(self):
return self.array

def is_out_of_bounds(self, cmplx):
z = complex(0, 0)
t = 0
for i in range(0, self.max_iterations):
z = z ** 2 + cmplx
t = i
if abs(z) > 1000:
break

if abs(z) >= 2:
return t
return 0


if __name__ == '__main__':
clock = time.time()
Expand Down
Binary file modified test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6a87686

Please sign in to comment.