sphere.py

Created by vnap0v

Created on May 04, 2025

711 Bytes

This code draws a rotating sphere using the kandinsky module. It also uses the sleep function of the time module and sin(), cos() from the math module. Tested on the calculator using software version 23.2.6.


from math import *
import kandinsky
import time

def ellipse(xc, yc, w, h, N, angle):
  for i in range(N):
      x = w * sin(2 * pi* i / N)
      y = h * cos(2 * pi * i / N)
      xr = cos(angle) * x - sin(angle) * y
      yr = sin(angle) * x + cos(angle) * y
      xr += xc
      yr += yc
      kandinsky.set_pixel(int(xr), int(yr), "yellow")
for turns in range(2):
    angle_steps = 40
    np=100
    for a in range(angle_steps):
      angle = 2 * pi * a / angle_steps
      kandinsky.fill_rect(0,0,320,240,"black")
      for k in range(0, 120, 20):
        ellipse(160, 110, k, 100, np, angle)
      for k in range(0, 120, 20):
        ellipse(160, 110, 100, k, np, angle)
      time.sleep(0.2)

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.