3D世界坐标轴

如本文章标有价格,需议价或其它事情商议请加微信scratch8

python海龟3D世界坐标轴
python海龟3D世界坐标轴
"""
   3D世界坐标轴.py
"""
__author__ = '李兴球'
__blog__ = 'www.lixingqiu.com'
import turtle
import time

viewfactor = 150
xshift = 0
yshift = 0
zshift = 50
def gotoxyz(x,y,z):
    global viewfactor,xshift,yshift,zshift
    if (z+zshift) == 0 : return     
    xcor = viewfactor * (x+xshift)/(z+zshift)
    ycor = viewfactor * (y+yshift)/(z+zshift)
    turtle.goto(xcor,ycor)
    
turtle.pensize(2)
turtle.speed(0)
turtle.delay(0)
turtle.penup()
turtle.ht()
turtle.title('3D世界坐标轴by李兴球')
turtle.tracer(0)
oldx = None
oldy = None
def shift(event):
    global oldx,oldy,xshift,yshift
    if oldx==None:oldx = event.x  # 第一次
    if oldy==None:oldy = event.y  # 第一次
    dx = event.x - oldx
    dy = event.y - oldy
    oldx = event.x
    oldy = event.y
    xshift += dx
    yshift -= dy

def fov(event):
    global viewfactor
    viewfactor +=  event.delta/60
    
canvas = turtle.getcanvas()
canvas.bind("",shift)
canvas.bind("",fov)

turtle.bgcolor('black')
while True:
    turtle.clear()
    gotoxyz(0,0,0)              # 到圆点
    turtle.pendown()
    turtle.color('red')
    gotoxyz(300,0,0)            # x轴
    turtle.penup()

    gotoxyz(0,0,0)              # 到圆点
    turtle.pendown()
    turtle.color('blue')
    gotoxyz(0,300,0)            # y轴
    turtle.penup()
    
    gotoxyz(0,0,0)              # 到圆点
    turtle.pendown()
    turtle.color('yellow')
    gotoxyz(0,0,300)            # z轴
    turtle.penup()    
    
    turtle.update()
    time.sleep(0.1)
    

本站所有作品,教程等皆为原创,版权所有。只供个人及单位内部研究使用,对外展示或传播必需经本站同意,且注明来自本站。培训机构等用本站资源培训学生,需经本站授权。一旦付款,表示同意本站知识付费原则:数字商品,不支持退款。亦可直接向微信号scratch8付款购买。入住QQ群:225792826 和爱好者共同交流,并且能下载免费提供的Python资源(需提供真实姓名才可入群)
李兴球的博客_Python创意编程技术前沿_pygame » 3D世界坐标轴
scratch

学本领,探索更大的世界!

李兴球博客 风火轮编程主页