绘制直角坐标系,并实现点击鼠标右键,坐标系移动到鼠标右键点击屏幕位置
视频及讲解:
https://mbd.baidu.com/newspage/data/videolanding?nid=sv_5661261822248069171
主程序文件
#pic01.py
from pc03 import *
def main():
s=pc()
if name == ‘main’:
main()
mainloop()
绘制坐标系类文件
#pc03.py
‘’’
函数图像 版本 01.02
类的结构
绘制坐标系
移动坐标系
‘’’
from turtle import mainloop,Turtle,Screen
import pyautogui
class pc(Turtle):
def init(self):
Turtle.init(self)
self.dw=50
self.lx=1000
self.ly=800
self.dc=6
self.px=0
self.py=0
self.screen.bgcolor(“#222233”)
self.hideturtle()
self.draw_axis()
self.screen.onclick(self.change_draw,btn=3)
def draw_axis(self):
self.screen.delay(0)
self.pensize(1)
self.pencolor("#eeeedd")
lx=int((-self.lx-self.px)/self.dw)
rx=int((self.lx-self.px)/self.dw)
uy=int((self.ly-self.py)/self.dw)
dy=int((-self.ly-self.py)/self.dw)
self.up()
self.goto(-self.lx,self.py)
self.down()
self.goto(self.lx,self.py)
self.up()
self.goto(self.px,self.ly)
self.down()
self.goto(self.px,-self.ly)
for i in range(lx,rx+1,1):
self.up()
self.goto(i*self.dw+self.px,self.py)
self.down()
self.goto(i*self.dw+self.px,+self.dc+self.py)
if i!=0:
self.write(i,align="center")
for i in range(dy,uy+1,1):
self.up()
self.goto(self.px,i*self.dw+self.py)
self.down()
self.goto(self.px+self.dc,i*self.dw+self.py)
self.write(i,align="left")
def change_draw(self,x,y):
self.px=x
self.py=y
self.clear()
self.draw_axis()