lines_kandinsky.py

Created by vnap0v

Created on May 29, 2025

781 Bytes

The Kandinsky library has functions to directly draw to the screen but it does not contain a function to draw a line between any two point. This script defines function connect() which draws a line between two given points. It uses kandinsky.set_pixel(). The script also contains a test of that function drawing several lines of different color. Tested on the calculator using software version 23.2.6.


import kandinsky
from math import *

# function draws a line using kandinsky library
# start point:(x1,y1), end point:(x2,y2)
# optionally color can be specified
def connect(x1,y1,x2,y2,co="black"):
  xspan=x2-x1;yspan=y2-y1
  steps=max(abs(xspan),abs(yspan))
  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
    
# testing function connect()
for n in range(0,105,5):
  connect(3*n,200,300,200-2*n,"red")
  connect(3*n,0,0,200-2*n,"green")
N=40;R=100
for a in range(N):
  angle1=a/(N-1)*2*pi
  angle2=(a+N//3)/(N-1)*2*pi
  x1=int(R*cos(angle1)+150+.5)
  y1=int(R*sin(angle1)+100+.5)
  x2=int(R*cos(angle2)+150+.5)
  y2=int(R*sin(angle2)+100+.5)
  connect(x1,y1,x2,y2,"blue")

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.