#! /usr/bin/python3 # =================================================================== # animation example #1 # =================================================================== import user_interface as ui import coordinate_conversion as cc import draw_xy_axes as ax import numpy as np from graphics import * import time # ---- window dimensions win_width = 801 win_height = 801 # ------------------------------------------------------------------ # ---- animation # ---- move a circle around the origin (center coordinates) # ---- # ---- win window object # ---- dst starting distance from origin (center coordinates) # ---- deg starting angle (degrees) for animation loop # ---- inc increment (in degrees) for each step of the loop # ---- cnt loop step count # ---- sec pause (seconds) between drawing frames # ------------------------------------------------------------------- def animation(win, dst, deg, inc=5.0 ,cnt=100, sec=0.2): if not sec > 0.0: print(f'Bad seconds value ({sec})') return for _ in range(int(cnt)): rad = np.deg2rad(deg % 360.0) cx = np.sin(rad) * dst cy = np.cos(rad) * dst (wx,wy) = cc.center_to_win_coords(cx,cy,win.width,win.height) c = Circle(Point(wx,wy),5) c.setOutline('black') c.setWidth(2) c.setFill('red') c.draw(win) time.sleep(sec) c.undraw() deg += inc # ------------------------------------------------------------------- # ---- main # ------------------------------------------------------------------- # ---- create window win = GraphWin("Animation 01", win_width, win_height) win.setBackground("white") # ---- draw X,Y coordinate axes ax.draw_xy_axes(win,True) # ---- animation animation(win,150.0,0.0) # ---- end program ui.pause() win.close() print()