Vous vous douter que ça ne fonctionne pas
Voici le code d'origine
Code : Tout sélectionner
// public-domain code by Darel Rex Finley, 2007
int nodes, nodeX[MAX_POLY_CORNERS], pixelX, pixelY, i, j, swap ;
// Loop through the rows of the image.
for (pixelY=IMAGE_TOP; pixelY<IMAGE_BOT; pixelY++) {
// Build a list of nodes.
nodes=0; j=polyCorners-1;
for (i=0; i<polyCorners; i++) {
if (polyY[i]<(double) pixelY && polyY[j]>=(double) pixelY
|| polyY[j]<(double) pixelY && polyY[i]>=(double) pixelY) {
nodeX[nodes++]=(int) (polyX[i]+(pixelY-polyY[i])/(polyY[j]-polyY[i])
*(polyX[j]-polyX[i])); }
j=i; }
// Sort the nodes, via a simple “Bubble” sort.
i=0;
while (i<nodes-1) {
if (nodeX[i]>nodeX[i+1]) {
swap=nodeX[i]; nodeX[i]=nodeX[i+1]; nodeX[i+1]=swap; if (i) i--; }
else {
i++; }}
// Fill the pixels between node pairs.
for (i=0; i<nodes; i+=2) {
if (nodeX[i ]>=IMAGE_RIGHT) break;
if (nodeX[i+1]> IMAGE_LEFT ) {
if (nodeX[i ]< IMAGE_LEFT ) nodeX[i ]=IMAGE_LEFT ;
if (nodeX[i+1]> IMAGE_RIGHT) nodeX[i+1]=IMAGE_RIGHT;
for (pixelX=nodeX[i]; pixelX<nodeX[i+1]; pixelX++) fillPixel(pixelX,pixelY); }}}
Mais j'ai du faire des erreurs... je n'ai fait que peu de C dans ma vie .. et je suis pas certain d'avoir fait comme il fallait
si il y a quelqu'un qui maîtrise suffisamment le C a le temps de jeter un oeil pour m'indiquer ou chercher l'erreur ?
Code : Tout sélectionner
NewList V.point()
ClearList(V())
AddElement(V()):V()\x=300:V()\y=250:n+1
AddElement(V()):V()\x=350:V()\y=250:n+1
AddElement(V()):V()\x=80:V()\y=10:n+1
AddElement(V()):V()\x=450:V()\y=250:n+1
AddElement(V()):V()\x=400:V()\y=300:n+1
AddElement(V()):V()\x=450:V()\y=280:n+1
AddElement(V()):V()\x=280:V()\y=400:n+1
AddElement(V()):V()\x=340:V()\y=280:n+1
;-Pour tracer le contour du Polygone
Procedure drawPoly(List polylist.point())
Protected pa.point
Protected pb.point
Protected dist.l
Protected baryCenter.point
For i=0 To ListSize(polylist())-1
SelectElement(polylist(),i)
pa\x=polylist()\x
pa\y=polylist()\y
;si on arrive a la fin de la liste on prend comme point i+1 le premier point
If i=ListSize(polylist())-1
SelectElement(polylist(),0)
Else
SelectElement(polylist(),i+1)
EndIf
pb\x=polylist()\x
pb\y=polylist()\y
color=#Green
LineXY(pa\x,pa\y,pb\x,pb\y,color)
Circle(pa\x,pa\y,5,#Red)
DrawText(pa\x+10,pa\y+10,Str(i))
Next
EndProcedure
;tracer un Polygone plein
Procedure drawPolyFull(List polylist.point())
;http://alienryderflex.com/polygon_fill/
Protected.l nodes,pixelX,pixelY,i,j,Swp
Protected Dim _nodeX.l(ListSize(polylist()))
Protected Dim polyX.l(ListSize(polylist()))
Protected Dim polyY.l(ListSize(polylist()))
;Found Image_Top
Protected IMAGE_BOP=1080
Protected IMAGE_BOT=0
Protected IMAGE_LEFT=1920
Protected IMAGE_RIGHT=0
ForEach polylist()
If polylist()\y<IMAGE_BOP
IMAGE_BOP=polylist()\y
EndIf
If polylist()\y>IMAGE_TOP
IMAGE_TOP=polylist()\y
EndIf
If polylist()\x<IMAGE_LEFT
IMAGE_LEFT=polylist()\x
EndIf
If polylist()\x>IMAGE_RIGHT
IMAGE_RIGHT=polylist()\x
EndIf
polyX(ListIndex(polylist()))=polylist()\x
polyY(ListIndex(polylist()))=polylist()\y
Next
Debug ElapsedMilliseconds()
Debug "IMAGE_BOP:"+Str(IMAGE_BOP)
Debug "IMAGE_TOP:"+Str(IMAGE_TOP)
Debug "IMAGE_LEFT:"+Str(IMAGE_LEFT)
Debug "IMAGE_RIGHT:"+Str(IMAGE_RIGHT)
; Loop through the rows of the image.
For pixelY=IMAGE_BOP To IMAGE_TOP
; Build a list of nodes.
polycorners=ListSize(polylist())
nodes=0
j=polyCorners-1
For i=0 To polyCorners-1
If (polyY(i)<pixelY And polyY(j)>=pixelY Or polyY(j)<pixelY And polyY(i)>=pixelY)
_nodeX(nodes)=(polyX(i)+(pixelY-polyY(i))/(polyY(j)-polyY(i))*(polyX(j)-polyX(i)))
Debug "nodeX("+Str(nodes)+")="+Str(_nodeX(nodes))
nodes=nodes+1
EndIf
j=i;
Next i
; Sort the nodes, via a simple “Bubble” sort.
i=0;
While (i<nodes-1)
If (_nodeX(i)>_nodeX(i+1))
Swp=_nodeX(i)
_nodeX(i)=_nodeX(i+1)
_nodeX(i+1)=Swp
If (i)
i=i-1;
EndIf
Else
i=i+1;
EndIf
Wend
; Fill the pixels between node pairs.
Debug nodes
For i=0 To nodes-1 Step 2; i<nodes; i+=2) <<<<<<<<<<<<<<<Pas sur d'avoir fait ce qu'il faut
If (_nodeX(i )>=IMAGE_RIGHT)
Break;
EndIf
If (_nodeX(i+1)> IMAGE_LEFT )
If (_nodeX(i )< IMAGE_LEFT )
_nodeX(i )=IMAGE_LEFT ;
EndIf
If (_nodeX(i+1)> IMAGE_RIGHT)
_nodeX(i+1)=IMAGE_RIGHT;
EndIf
For pixelX=_nodeX(i) To _nodeX(i+1) ;<<<<<< TO DO remplacer cette boucle une simple commande LINE
Debug Str(pixelX)+","+Str(pixelY)
Plot(pixelX,pixelY,RGB(255,0,0))
Next PixelX
EndIf
Next i
Next pixelY
EndProcedure
If InitSprite()
If InitKeyboard() And InitMouse()
winMain = OpenWindow(#PB_Any,0,0,800,600,"Press [Esc] to close",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(winMain), 0, 0,800,600, 1, 0, 0)
SetFrameRate(60)
EndIf
Else
MessageRequester("","Unable to initsprite") :
EndIf
Repeat
Delay(1)
EventID = WindowEvent()
ExamineKeyboard()
ExamineMouse()
ClearScreen(col)
StartDrawing(ScreenOutput())
drawPoly(V())
drawPolyFull(V())
Circle(MouseX(),MouseY(),5,#Blue)
StopDrawing()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape) Or EventID = #PB_Event_CloseWindow