Python海龟画图3D立方体演示

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

李兴球Python海龟3D立方体演示
李兴球Python海龟3D立方体演示
"""
   Python海龟画图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.color('blue')
turtle.pensize(2)
turtle.speed(0)
turtle.delay(0)
turtle.penup()
turtle.ht()
turtle.title('Python海龟画图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)

while True:
    turtle.clear()
    gotoxyz(50,50,0)
    turtle.pendown()
    gotoxyz(50,-50,0)
    gotoxyz(-50,-50,0)
    gotoxyz(-50,50,0)
    gotoxyz(50,50,0)
    turtle.penup()
    gotoxyz(50,50,50)
    turtle.pendown()
    gotoxyz(50,-50,50)
    gotoxyz(-50,-50,50)
    gotoxyz(-50,50,50)
    gotoxyz(50,50,50)
    turtle.penup()
    gotoxyz(50,50,50)
    turtle.pendown()
    gotoxyz(50,50,0)
    turtle.penup()
    gotoxyz(50,-50,50)
    turtle.pendown()
    gotoxyz(50,-50,0)    
    turtle.penup()
    gotoxyz(-50,-50,50)    
    turtle.pendown()
    gotoxyz(-50,-50,0)    
    turtle.penup()
    gotoxyz(-50,50,50)
    turtle.pendown()
    gotoxyz(-50,50,0)
    turtle.penup()
    turtle.update()
    time.sleep(0.1)
 
    

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

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

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