fillquad.py

Created by gianfranco-oddenino

Created on November 19, 2024

802 Bytes

Utility library for axonometry.py Requires fastgraph.py


from math import *
from kandinsky import *
from fastgraph import *

def vline(x,y1,y2,color):
  if y1<y2:
    fill_rect(x,y1,1,y2-y1,color)
  else:
    fill_rect(x,y2,1,y1-y2,(255-color[0],255-color[1],255-color[2]))

def fill(a,b,c,d,color):
  dy1=(d[1]-a[1])/(d[0]-a[0])
  dy2=(b[1]-a[1])/(b[0]-a[0])
  y1=y2=a[1]
  for x in range(a[0],d[0]):
    vline(x,round(y1),round(y2),color)
    y1+=dy1; y2+=dy2
  dy1=(c[1]-d[1])/(c[0]-d[0])
  for x in range(d[0],b[0]):
    vline(x,round(y1),round(y2),color)
    y1+=dy1; y2+=dy2
  dy2=(c[1]-b[1])/(c[0]-b[0])
  for x in range(b[0],c[0]):
    vline(x,round(y1),round(y2),color)
    y1+=dy1; y2+=dy2
  line(a[0],a[1],b[0],b[1],(0,0,0))
  line(b[0],b[1],c[0],c[1],(0,0,0))
  line(c[0],c[1],d[0],d[1],(0,0,0))
  line(d[0],d[1],a[0],a[1],(0,0,0))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.