armstrong.py

Created by schraf

Created on November 22, 2023

791 Bytes


from math import *
from random import random
from kandinsky import *

fill_rect(0, 0, 320, 222, (0, 0, 0))

coul = (0,0,0), (255,0,0), (255,255,0), (255,255,255)

for i in range(2e5):
 x = i * sqrt(2) % 1 * 2 - 1
 y = i * sqrt(3) % 1 * 1.2 - 0.7
 c, p = -3 * (y < 0), 0.1
 d = x * x
 r = d + y * y
 if abs(x) < 0.6 and y < 0.4: c, p = 3, (x + y + 0.8) * 0.2
 if d + 2 * (y + 0.8) ** 2 < 0.8: c, p = 3, (x - y + 0.2) * 0.4
 if r < 0.2:
  c, p = 3, (x + 0.4)
  if d + (y + 0.1) ** 2 < 0.18:
   c, p = 2, 0.1 - (abs(y) < 0.06 and abs(x - 0.1) < 0.02)
   if (p < 1 and d + (y + 2) ** 2 > 4 or (x + y / 6 < -0.1 and x - y / 5 > -0.05)): c = 0
 if (0.2 > x + y > 0)  and (1.2 > x - y > 1): c = 1
 if p > random(): set_pixel(int(160 * (x + 1)), int(222 - 160 * (y + 0.7)), coul[c])