Page 1 sur 1
Erreur sur une procédure
Publié : mar. 12/avr./2005 17:19
par flaith
Bonjour à tous, je suis nouveau sur le forum ainsi qu'avec PureBASIC, acheté depuis peu, je le test et voici mon soucis :
Qd je lance le petit prog, j'ai ce message d'erreur : "Line 8 - DoLine() is not a function, an array, or a linked list"
Code : Tout sélectionner
OpenScreen(640, 480, 32, "DoLine")
;- Boucle
Repeat
ClearScreen(0, 0, 0)
For i.w = 0 To 359
DoLine (120,120,500*Sin(i),450*Cos(i),Random(255),Random(255),Random(255))
Next i
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
End
;************************************************************************
Procedure DoLine(XStart.w,YStart.w,xend.w,YEnd.w,CoulR.w,CoulG.w,CoulB.w)
XDifference.w = xend - XStart
YDifference.w = YEnd - YStart
y.w = YStart
YError.w = 0
FrontColor(CoulR,CoulG,CoulB)
For x.w = XStart To xend
Plot(x,y) ';Plot(X-1,Y-1);Plot(X+1,Y+1);Plot(X-1,Y+1);Plot(X+1,Y-1)
YError = YError + YDifference
If YError >= XDifference Then
y = y + 1
YError = YError - XDifference
EndIf
Next
EndProcedure
Publié : mar. 12/avr./2005 17:35
par comtois
Tu as deux solutions :
- soit tu places la procédure avant son appel
- soit tu la déclares au début du code
et j'ai ajouté les bricoles qui manquaient pour pouvoir afficher quelque chose.
Code : Tout sélectionner
Declare DoLine(XStart.w,YStart.w,xend.w,YEnd.w,CoulR.w,CoulG.w,CoulB.w)
InitSprite()
InitKeyboard()
OpenScreen(640, 480, 32, "DoLine")
;- Boucle
Repeat
ClearScreen(0, 0, 0)
For i.w = 0 To 359
DoLine (120,120,500*Sin(i),450*Cos(i),Random(255),Random(255),Random(255))
Next i
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End
;************************************************************************
Procedure DoLine(XStart.w,YStart.w,xend.w,YEnd.w,CoulR.w,CoulG.w,CoulB.w)
XDifference.w = xend - XStart
YDifference.w = YEnd - YStart
y.w = YStart
YError.w = 0
StartDrawing(ScreenOutput())
FrontColor(CoulR,CoulG,CoulB)
For x.w = XStart To xend
Plot(x,y) ;Plot(X-1,Y-1);Plot(X+1,Y+1);Plot(X-1,Y+1);Plot(X+1,Y-1)
YError = YError + YDifference
If YError >= XDifference
y = y + 1
YError = YError - XDifference
EndIf
Next
StopDrawing()
EndProcedure
Publié : mar. 12/avr./2005 17:51
par flaith
Merci beaucoup
Comme je suis entrain de le tester par rapport à BMax, çà m'a bien aidé

Publié : mar. 12/avr./2005 19:21
par flaith

je comprends pas la différence :
BMAX

PureBASIC

Publié : mer. 13/avr./2005 6:36
par dlolo
Le problème vient du cosinus et sinus. L'angle pour les fonctions trigo. en Purebasic sont en 'radians' et en Blitz en 'degrés'.
Degrés : 0 à 359
Radians : 0 à 2Pi
Publié : mer. 13/avr./2005 11:24
par Le Soldat Inconnu
il n'y pas que ça, cet algo fonctionne à moitié.
ta procedure pour tracer des droites ne marche que pour des droites comprises entre 0° et 45°
pourquoi tu n'utilises pas Line() pour tracer ta droite
Publié : mer. 13/avr./2005 12:01
par cha0s
flaith a écrit :
je comprends pas la différence
20$ environ....
bon ok je sort

Publié : mer. 13/avr./2005 12:07
par flaith
Le Soldat Inconnu a écrit :il n'y pas que ça, cet algo fonctionne à moitié.
ta procedure pour tracer des droites ne marche que pour des droites comprises entre 0° et 45°
pourquoi tu n'utilises pas Line() pour tracer ta droite
juste un test !!
Merci à tous pour vos infos !
Publié : mer. 13/avr./2005 18:16
par comtois
Dans ce code , il ne se passe rien
Code : Tout sélectionner
XStart.w = 200
XEnd.w = 100
For x=XStart To XEnd
Debug x ; Il ne se passe rien
Next x
C'est à toi de préciser la valeur de l'incrément de l'instruction
For x=xx to xx, PureBasic ne le détermine pas seul.C'est ce qui arrive quand tu as une valeur de cos() négative ,tu peux te retrouver avec un Xend < Xstart
Exemple
Code : Tout sélectionner
XStart.w = 200
XEnd.w = 100
For x=XStart To XEnd Step -1
Debug x ;Ici ça décrémente bien
Next x
Autre solution , tu intervertis les valeurs
Code : Tout sélectionner
Structure MyWord
w.w
EndStructure
Procedure Swap(*A.MyWord,*B.MyWord)
If *A\w > *B\w
Temp = *A\w
*A\w = *B\w
*B\w = Temp
EndIf
EndProcedure
XStart.w = 200
XEnd.w = 100
Swap(@XStart,@XEnd)
For x=XStart To XEnd
Debug x
Next x
Pour tracer une ligne , c'est pas important de savoir que l'on va de 100 à 200 , ou de 200 à 100 , par contre cette solution peut poser des problèmes dans d'autres situations .
En fait la deuxième solution , c'était juste pour faire joujou avec les pointeurs

Publié : mer. 13/avr./2005 20:00
par comtois
Un exemple avec LineXY()
Code : Tout sélectionner
InitSprite()
InitKeyboard()
OpenScreen(640, 480, 32, "DoLine")
;- Boucle
Rayon = 240
Repeat
ClearScreen(0, 0, 0)
StartDrawing(ScreenOutput())
For i.w = 0 To 359
LineXY(320,240, 320 + Rayon * Cos(i * 0.0174533), 240 + Rayon * Sin(i* 0.0174533),RGB(Random(255),Random(255),Random(255)))
Next i
StopDrawing()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End
Et le même avec Line()
Code : Tout sélectionner
InitSprite()
InitKeyboard()
OpenScreen(640, 480, 32, "DoLine")
;- Boucle
Rayon = 240
Repeat
ClearScreen(0, 0, 0)
StartDrawing(ScreenOutput())
For i.w = 0 To 359
Line(320,240, Rayon * Cos(i * 0.0174533), Rayon * Sin(i* 0.0174533),RGB(Random(255),Random(255),Random(255)))
Next i
StopDrawing()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End
Publié : mer. 13/avr./2005 20:42
par flaith
Merci beaucoup pour ces éclaircissements !
Publié : jeu. 14/avr./2005 21:59
par comtois
Tiens , une version complète du tracé de lignes avec l'algo de Bresenham
Code : Tout sélectionner
void ligne(int xi,int yi,int xf,int yf) {
int dx,dy,i,xinc,yinc,cumul,x,y ;
x = xi ;
y = yi ;
dx = xf - xi ;
dy = yf - yi ;
xinc = ( dx > 0 ) ? 1 : -1 ;
yinc = ( dy > 0 ) ? 1 : -1 ;
dx = abs(dx) ;
dy = abs(dy) ;
allume_pixel(x,y) ;
if ( dx > dy ) {
cumul = dx / 2 ;
for ( i = 1 ; i <= dx ; i++ ) {
x += xinc ;
cumul += dy ;
if (cumul >= dx) {
cumul -= dx ;
y += yinc ; }
allume_pixel(x,y) ; } }
else {
cumul = dy / 2 ;
for ( i = 1 ; i <= dy ; i++ ) {
y += yinc ;
cumul += dx ;
if ( cumul >= dy ) {
cumul -= dy ;
x += xinc ; }
allume_pixel(x,y) ; } }
}
Je n'ai pas pris le temps de le convertir en purebasic, à l'occasion peut-être

Publié : jeu. 14/avr./2005 22:13
par comtois
Bon finalement , je viens de le faire .
Code : Tout sélectionner
Declare DoLine(XStart,YStart,xend,YEnd,CoulR,CoulG,CoulB)
InitSprite()
InitKeyboard()
OpenScreen(640, 480, 32, "DoLine")
;- Boucle
rayon=200
Repeat
ClearScreen(0, 0, 0)
For i.w = 0 To 359 Step 6
DoLine(320,240, 320 + rayon * Cos(i * 0.0174533), 240 + rayon * Sin(i* 0.0174533),Random(255),Random(255),Random(255))
Next i
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End
Procedure PlotN(x,y)
Plot(x,y)
Plot(x-1,y-1)
Plot(x+1,y+1)
Plot(x-1,y+1)
Plot(x+1,y-1)
EndProcedure
Procedure DoLine(xi,yi,xf,yf,CoulR,CoulG,CoulB)
StartDrawing(ScreenOutput())
FrontColor(CoulR,CoulG,CoulB)
x = xi
y = yi
dx = xf - xi
dy = yf - yi
If dx > 0
xinc = 1
Else
xinc = -1
EndIf
If dy > 0
yinc = 1
Else
yinc = -1
EndIf
dx = Abs(dx)
dy = Abs(dy)
PlotN(x,y)
If dx > dy
cumul = dx / 2
For i = 1 To dx
x + xinc
cumul + dy
If (cumul >= dx)
cumul - dx
y + yinc
EndIf
PlotN(x,y)
Next
Else
cumul = dy / 2
For i = 1 To dy
y + yinc
cumul + dx
If cumul >= dy
cumul - dy
x + xinc
EndIf
PlotN(x,y)
Next
EndIf
StopDrawing()
EndProcedure
Publié : jeu. 14/avr./2005 23:15
par flaith
MA..GNI..FI...QUE... merci
