Spaces:
Sleeping

Mykelkarim commited on
Commit
f78f4c7
·
verified ·
1 Parent(s): 9cc673f

Create algorithmes/fractal_image.py

Browse files
algorithmes/algorithmes/algorithmes/algorithmes/algorithmes/algorithmes/fractal_image.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from PIL import Image
3
+
4
+ def generate_fractal_image(sequence, size=256):
5
+ img = np.zeros((size, size, 3), dtype=np.uint8)
6
+
7
+ x, y = size//2, size//2
8
+
9
+ moves = {
10
+ "A": (1, 0),
11
+ "L": (0, -1),
12
+ "F": (-1, 0),
13
+ }
14
+
15
+ color = {
16
+ "A": (255, 200, 0), # or
17
+ "L": (50, 120, 255), # bleu
18
+ "F": (255, 60, 150), # rose
19
+ }
20
+
21
+ for char in sequence:
22
+ dx, dy = moves.get(char, (0, 0))
23
+ x = (x + dx) % size
24
+ y = (y + dy) % size
25
+ img[y, x] = color.get(char, (255,255,255))
26
+
27
+ return Image.fromarray(img)