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)