jumpboxnw.py

Created by ews31415

Created on May 19, 2025

504 Bytes

A red box of size 20 pixels by 20 pixels jumps around the screen using the modules kandinsky, time, and random.

Numworks’ kandinsky does not have a clear screen (as of Version 23), we create a function to “clear” the screen. We can make the screen anything we want but the following code creates the “boring” white screen: def cls(): fill_rect(0,0,320,220,(255,255,255))

Remember the randrange does NOT include the stop value, so if we want to include the stop value, we will need to add it: randrange(start, stop + 1) randrange(start, stop + step, step)


#  for NUMWORKS

from math import *
from random import *
from kandinsky import *
from time import *

# red box jumping aroud

# create a clear screen
def cls():
  # white background
  fill_rect(0,0,320,220,(255,255,255))

# draw the red box, 20*20
# randrange(start,stop+n,n)
def redbox():
  x=randrange(0,320,20)
  y=randrange(0,220,20)
  fill_rect(x,y,20,20,(192,0,0))


# 320*220 pixels
# main routine
# 50 steps, half second
for i in range(50):
  cls()
  redbox()
  sleep(.5)
  
    

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.