# ESP32-S3 MicroPython + ILI9341 Extraordinary Geometry Demo
# Alternate pin connections
from machine import Pin, SPI
import ili9341
import time, math
# New Pin mapping (example set)
TFT_DC = 10
TFT_CS = 11
TFT_MOSI = 12
TFT_CLK = 13
TFT_RST = 14
spi = SPI(2, baudrate=40000000, polarity=0, phase=0,
sck=Pin(TFT_CLK), mosi=Pin(TFT_MOSI))
display = ili9341.ILI9341(spi, cs=Pin(TFT_CS), dc=Pin(TFT_DC), rst=Pin(TFT_RST))
W, H = display.width(), display.height()
# --- Extraordinary Geometrical Patterns ---
def rotating_polygon(sides=6, radius=80, steps=60):
cx, cy = W//2, H//2
for angle in range(0, 360, steps):
display.fill(ili9341.BLACK)
pts = []
for i in range(sides):
theta = 2*math.pi*i/sides + math.radians(angle)
x = int(cx + radius*math.cos(theta))
y = int(cy + radius*math.sin(theta))
pts.append((x,y))
for i in range(len(pts)):
x1,y1 = pts[i]
x2,y2 = pts[(i+1)%len(pts)]
color = display.color565((i*40)%255, (i*80)%255, (i*120)%255)
display.line(x1,y1,x2,y2,color)
time.sleep(0.1)
def sine_wave_pattern():
display.fill(ili9341.BLACK)
for x in range(W):
y = int(H/2 + 60*math.sin(x/20.0))
color = display.color565((x*2)%255, (y*3)%255, (x*y)%255)
display.pixel(x,y,color)
time.sleep(1)
def spiral_pattern(turns=20):
display.fill(ili9341.BLACK)
cx, cy = W//2, H//2
for t in range(1, turns*360, 5):
r = 2*t/10
x = int(cx + r*math.cos(math.radians(t)))
y = int(cy + r*math.sin(math.radians(t)))
color = display.color565((t*3)%255, (t*5)%255, (t*7)%255)
display.pixel(x,y,color)
time.sleep(1)
def fractal_tree(x, y, angle, depth, length):
if depth == 0:
return
x2 = int(x + length * math.cos(math.radians(angle)))
y2 = int(y - length * math.sin(math.radians(angle)))
color = display.color565((depth*40)%255, (depth*80)%255, (depth*120)%255)
display.line(x, y, x2, y2, color)
fractal_tree(x2, y2, angle - 20, depth - 1, length * 0.7)
fractal_tree(x2, y2, angle + 20, depth - 1, length * 0.7)
def fractal_tree_pattern():
display.fill(ili9341.BLACK)
fractal_tree(W//2, H-20, -90, 8, 60)
time.sleep(2)
def lissajous_pattern(a=3, b=4, delta=math.pi/2):
display.fill(ili9341.BLACK)
cx, cy = W//2, H//2
for t in range(0, 1000, 2):
x = int(cx + 100*math.sin(a*t/100.0 + delta))
y = int(cy + 100*math.sin(b*t/100.0))
color = display.color565((t*3)%255, (t*5)%255, (t*7)%255)
display.pixel(x,y,color)
time.sleep(2)
# --- Main Loop ---
while True:
rotating_polygon(sides=5)
rotating_polygon(sides=7)
sine_wave_pattern()
spiral_pattern()
fractal_tree_pattern()
lissajous_pattern()
https://wokwi.com/projects/new/micropython-esp32-s3