Publié : dim. 12/mars/2006 12:48
Voici ma solution
Un code plutot longuet, mais rapide a l'execution !
[ edit ; ce code fonctionne avec des points et serait plus rapide avec des lignes, mais cependant pour des besoins personnels, il m'était necessaire d''utiliser la commande Plot(x,y) ]

Code : Tout sélectionner
Procedure Triangle(ax1,ay1,ax2,ay2,ax3,ay3,r,g,b)
If ax1 =< ax2 And ax1 =< ax3
x1 = ax1
y1 = ay1
If ax2 =< ax3
x2 = ax2 : y2 = ay2
x3 = ax3 : y3 = ay3
Else
x2 = ax3 : y2 = ay3
x3 = ax2 : y3 = ay2
EndIf
EndIf
If ax2 =< ax1 And ax2 =< ax3
x1 = ax2
y1 = ay2
If ax1 =< ax3
x2 = ax1 : y2 = ay1
x3 = ax3 : y3 = ay3
Else
x2 = ax3 : y2 = ay3
x3 = ax1 : y3 = ay1
EndIf
EndIf
If ax3 =< ax1 And ax3 =< ax2
x1 = ax3
y1 = ay3
If ax2 =< ax1
x2 = ax2 : y2 = ay2
x3 = ax1 : y3 = ay1
Else
x2 = ax1 : y2 = ay1
x3 = ax2 : y3 = ay2
EndIf
EndIf
xdepart.f = x1
ydepart.f = y1
yfin.f = y1
Coeff_A.f = ( y2-y1 ) / (x2-x1 )
Coeff_B.f = ( y3-y1 ) / (x3-x1 )
If x2 < x3
Pt_Ct = x2 : fin = x3 : fin2 = y3
Coeff_C.f = -1*( y3-y2 ) / (x3-x2 )
Coeff_D.f = -1*Coeff_B.f
Else
Pt_Ct = x3 : fin = x2 : fin2 = y2
Coeff_C.f = -1*( y2-y3 ) / (x2-x3 )
Coeff_D.f = -1*Coeff_A.f
EndIf
If Coeff_A.f < Coeff_B.f
Coeff_Down.f = Coeff_A.f
Coeff_Up.f = Coeff_B.f
Else
Coeff_Down.f = Coeff_B.f
Coeff_Up.f = Coeff_A.f
EndIf
For x = xdepart.f To Pt_Ct Step 1
y = ydepart.f
Repeat
y = y+1
Plot( x,y,RGB(r,g,b) )
Until y >= yfin.f
ydepart.f = ydepart.f+Coeff_Down.f
yfin.f = yfin.f+Coeff_Up.f
Next x
;*********************************************************************
If Coeff_C.f < Coeff_D.f
Coeff_Down.f = Coeff_C.f
Coeff_Up.f = Coeff_D.f
Else
Coeff_Down.f = Coeff_D.f
Coeff_Up.f = Coeff_C.f
EndIf
ydepart.f = fin2
yfin.f = fin2
For x = fin To Pt_Ct Step -1
y = ydepart.f
Repeat
y = y+1
Plot( x,y,RGB(r,g,b))
Until y >= yfin.f
ydepart.f = ydepart.f+Coeff_Down.f
yfin.f = yfin.f+Coeff_Up.f
Next x
EndProcedure
[ edit ; ce code fonctionne avec des points et serait plus rapide avec des lignes, mais cependant pour des besoins personnels, il m'était necessaire d''utiliser la commande Plot(x,y) ]