I know that it's a very common algorithm, and that it's very common... but I couldn't find one lying around, and I didn't really want to code one (finding which side to linear interpolate is a bit meh), so I converted a good-looking one i found from c++
Reason for this post: No one should have to code their own triangle fill algorithm from scratch for an actual project! it's like coding their own min or max function. Should be more of a copy-and-paste, dont really think about it, sort of thing.
ink rgb(255,0,0),rgb(255,0,0)
trifill(100,100,500,100,350,500,1)
ink rgb(255,255,0),rgb(255,255,0)
trifill(100,100,500,100,350,500,0)
wait key
end
function trifill(x1,y1,x2,y2,x3,y3, fillornot as boolean)
if fillornot
dx1 as float
dx2 as float
dx3 as float
sy as float
sx as float
ey as float
ex as float
if y2-y1 > 0
dx1=(x2-x1)*1.0/(y2-y1)
else
dx1=0
endif
if y3-y1 > 0
dx2=(x3-x1)*1.0/(y3-y1)
else
dx2=0;
endif
if y3-y2 > 0
dx3=(x3-x2)*1.0/(y3-y2)
else
dx3=0;
endif
S=E=A;
sy=y1
sx=x1
ey=y1
ex=x1
if dx1 > dx2
while sy<=y2
line sx,sy,ex,sy
inc sy,1
inc ey,1
sx=sx+dx2
ex=ex+dx1
endwhile
ey=y2
ex=x2
while sy<=y3
line sx,sy,ex,sy
inc sy,1
inc ey,1
sx=sx+dx2
ex=ex+dx3
endwhile
else
while sy<=y2
line sx,sy,ex,sy
inc sy,1
inc ey,1
sx=sx+dx1
ex=ex+dx2
endwhile
sy=y2
sx=x2
while sy<=y3
line sx,sy,ex,sy
inc sy,1
inc ey,1
sx=sx+dx3
ex=ex+dx2
endwhile
endif
else
line x1,y1,x2,y2
line x2,y2,x3,y3
line x3,y3,x1,y1
endif
endfunction