pi_circles.py

Created by martin-garel-528

Created on February 23, 2025

1.29 KB

Application that draw circles in a loop with varying radius


from kandinsky import *
from math import *
from ion import *

cx = 320 // 2
cy = 222 // 2

x = 0
y = 0
r = 0
vr = 50
t = 0
n = 0
step = 0.01

t = 2*pi
while t < 2*pi:
  set_pixel(cx + round(cos(t) * (r+1)),cy + round(sin(t) * (r+1)),(0,0,0))
  t += 0.001

draw_string("n= " + str(n),0,0)
 
kdown = False
while True:
  if keydown(KEY_UP) and not kdown:
    n += 0.2
    kdown = True
    fill_rect(0,0,320,222,(255,255,255))
    t = 0
    draw_string("n= " + str(n),0,0)
  
  if keydown(KEY_DOWN) and not kdown:
    n -= 0.2
    kdown = True
    fill_rect(0,0,320,222,(255,255,255))
    t = 0
    draw_string("n= " + str(n),0,0)
 
  if not keydown(KEY_DOWN) and not keydown(KEY_UP):
    kdown = False

  if keydown(KEY_BACKSPACE):
    fill_rect(0,0,320,222,(255,255,255))
    draw_string("n= " + str(n),0,0)
    t = 0
 
  x = round(cos(t) * r)
  y = round(sin(t) * r)
  
  c = (abs(sin(t))*255,abs(cos(t*2))*255,abs(cos(sin(t*0.5)))*255)
  #fill_rect(cx, cy, x, y,c)
  #fill_rect(cx, cy, -x, -y,c)
  set_pixel(cx + round(cos(t) * (r+1)),cy + round(sin(t) * (r+1)),c)
  set_pixel(cx - round(cos(t) * (r+1)),cy - round(sin(t) * (r+1)),c)
  set_pixel(cx - round(cos(t) * (r+1)),cy + round(sin(t) * (r+1)),c)
  set_pixel(cx + round(cos(t) * (r+1)),cy - round(sin(t) * (r+1)),c)
  
  r = cos(n*t)*vr
  t += step

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.