axonometry.py

Created by gianfranco-oddenino

Created on November 20, 2019

537 Bytes

The script draws a surface z=f(x,y) in axonometry with removal of hidden lines. Requires fillquad.py and fastgraph.py


from math import *
from kandinsky import *
from fillquad import *

def f(x,y):
  return (y**2-x**2)/10

def xg(x,y,z):
  return round(160+x*8+y*4)

def yg(x,y,z):
  return round(111+x*2-y*4-z*8)

for y in range(10,-10,-1):
  for x in range(-10,10):
    z=f(x,y)
    dx=xg(x,y,z); dy=yg(x,y,z)
    z=f(x+1,y)
    cx=xg(x+1,y,z); cy=yg(x+1,y,z)
    z=f(x+1,y-1)
    bx=xg(x+1,y-1,z); by=yg(x+1,y-1,z)
    z=f(x,y-1)
    ax=xg(x,y-1,z); ay=yg(x,y-1,z)
    fill((ax,ay),(bx,by),(cx,cy),(dx,dy),color(100+x*10,100+x*10,200))