Draw_poly and fill_poly functions (slow!)

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Draw_poly and fill_poly functions (slow!)

Post by Henko »

option base 1
dim x(10),y(10)
for i=1 to 5
  read x(i),y(i)
  next i
data 220,600, 240,260, 500,220, 600,500, 350,700
graphics
graphics clear .8,.8,.8
fill_poly(5,x,y,0.2,0.8,0.5,1)
draw_poly(5,x,y,1,0,0,3)
end

def draw_poly(n,x(),y(),r,g,b,thick)
draw color r,g,b ! draw size thick
n=n+1 ! x(n)=x(1) ! y(n)=y(1)
for i=2 to n ! draw line x(i-1),y(i-1) to x(i),y(i) ! next i
end def

def fill_poly(n,x(),y(),r,g,b,transp)
draw color r,g,b ! draw alpha transp
xs=x(1) ! ys=y(1)
for i=3 to n
  xc=x(i)-x(i-1) ! yc=y(i)-y(i-1)
  delta=0.5/sqrt(xc*xc+yc*yc)
  for lab=0 to 1 step delta
    xe=x(i-1)+lab*xc ! ye=y(i-1)+lab*yc
    draw line xs,ys to xe,ye
    next lab
  next i
end def

Post Reply