#! /usr/bin/python3 # =================================================================== # draw X,Y axes # =================================================================== import user_interface as ui from graphics import * # ------------------------------------------------------------------- # ---- function: draw x,y axes # ------------------------------------------------------------------- def draw_xy_axes(win,linewidth=1,linecolor="black"): wx = win.width # window width wy = win.height # window height wcx = round(wx/2.0) # window center X wcy = round(wy/2.0) # window center Y # ---- X axis xl = Line(Point(0,wcy),Point(wx-1,wcy)) xl.setWidth(linewidth) xl.setFill(linecolor) xl.draw(win) # ---- Y axis yl = Line(Point(wcx,0),Point(wcx,wy-1)) yl.setWidth(linewidth) yl.setFill(linecolor) yl.draw(win) # ------------------------------------------------------------------- # ---- main # ------------------------------------------------------------------- if __name__ == '__main__': win = GraphWin("X,Y Axis", 801, 801) win.setBackground("white") draw_xy_axes(win) ui.pause() win.close()