from kandinsky import draw_string, fill_rect from math import sin, cos, pi from time import sleep, monotonic BG_COLOR = (0, 0, 0) STAR = "*" N_POINTS = 160 SCALE = 88 CENTER_X = 160 CENTER_Y = 111 FPS_SLEEP = 0.1 a = 3.0 b = 2.0 delta = 0.0 speed = 0.05 mode = 2 STAR_COLOR = (255, 255, 255) def clear_screen(): fill_rect(0, 0, 320, 222, BG_COLOR) def draw_lissajous(a_, b_, delta_, points=N_POINTS): t_max = 2 * pi for i in range(points): t = (i / (points - 1)) * t_max x = CENTER_X + SCALE * sin(a_ * t + delta_) y = CENTER_Y + SCALE * sin(b_ * t) draw_string(STAR, int(x), int(y), STAR_COLOR, BG_COLOR) try: t0 = monotonic() last_time = t0 while True: now = monotonic() dt = now - last_time elapsed = now - t0 if mode == 1: delta += speed * dt * 2 * pi a_use = a b_use = b else: a_use = a + 1.5 * sin(elapsed * 0.7) b_use = b + 1.2 * cos(elapsed * 0.9) delta += speed * dt * pi * 0.2 clear_screen() draw_lissajous(a_use, b_use, delta) sleep(FPS_SLEEP) last_time = now except KeyboardInterrupt: clear_screen()