repl.it
@mat1/

terminal mandelbrot

Python

No description

fork
loading
Files
  • main.py
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
from numpy import complex
from math import sqrt
import time
import os

maxiter = 5

def calc_pixel(x, y):
	n = 0
	c0 = complex(x, y) 
	c = 0
	while abs(c) < 2 and n < maxiter:
		c = c ** 2 + c0
		n = n + 1
	return n

x = 0
y = 0
tcx = -1.25 # higher = right
tcy = 0.05
cx = tcx

zoom = 1

color = 'gray'


print('\033[?25l\033[H\033[2J')

while True:
	width, height = os.get_terminal_size()
	output = '\033[H'
	cy = tcy
	for y in range(0, height):
		# if y == 0:
		# 	lastinitx = tcx
		# 	lastinity = cy
		cx = tcx
		for x in range(0, width):
			p = calc_pixel(cx, cy + (1 / zoom))
			if p < maxiter:
				factor = sqrt(p / maxiter)
				intensity =	round(255 * factor)
				if color == 'green':
					r, g, b = 10 / intensity, intensity, 1000 / intensity
				elif color == 'red':
					r, g, b = intensity, 10 / intensity, 1000 / intensity
				elif color == 'blue':
					r, g, b = 1000 / intensity, 10 / intensity, intensity
				elif color == 'gray':
					r, g, b = intensity, intensity, intensity
				# surface.set_at((x,y), (10/intensity,intensity,1000/intensity)) #10/intensity,intensity,1000/intensity
				# if intensity > 100:
				# 	output += 'O'
				# else:
				# 	output += 'o'
			else:
				r, g, b = 0, 0, 0
			r, g, b = int(r), int(g), int(b)
			output += f'\033[48;2;{r};{g};{b}m '
			cx += (5 / (zoom)) / width
		output += '\n'
		cy -= (3 / (zoom)) / height
	draw_time_start = time.time()
	print(output.strip('\n'), end='')
	draw_time_end = time.time()
	time.sleep(max(.25, draw_time_end - draw_time_start))
	zoom *= 2

Fetching token
?