star.py

Created by vnap0v

Created on June 17, 2025

804 Bytes

Simple but kind of pretty, a colored star.

The idea came from a piece of code in the basic language encountered on the web.

It uses a function connect() which allows to draw a line between two arbitrary points using set_pixel() from the kandisnky library. This sort of function is not included in kandinsky library.

Tested on the calculator using software version 23.2.6.


import kandinsky
from math import *
# draw a line between any two points
def connect(x1,y1,x2,y2,co="black"):
  xspan=x2-x1;yspan=y2-y1
  steps=max(abs(xspan),abs(yspan))
  if steps==0:
    kandinsky.set_pixel(x1,y1,co)
    return
  dx=xspan/steps;dy=yspan/steps
  x=x1;y=y1
  for k in range(steps):
    kandinsky.set_pixel(int(x+.5),int(y+.5),co)
    x+=dx;y+=dy
# draw the star
# x,y: center posistion
# n: number of points
# r: radius
def drawstar(x,y,n,r):
  col=("red","green","blue")
  xx=[];yy=[]
  for k in range(n):
    angle=k/n*2*pi
    xx.append(int(r*cos(angle)+x))
    yy.append(int(r*sin(angle)+y))
  for k in range(n):
    for m in range(k,n):
      c=col[m%3]
      connect(xx[k],yy[k],xx[m],yy[m],c)

kandinsky.fill_rect(0,0,320,230,"black")

drawstar(160,110,20,105)






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.