Page 2 sur 2
Publié : ven. 30/juin/2006 17:26
par Backup
hou le vilain serpent !!
Code : Tout sélectionner
; Codé par SPH(2006) sur PB4
InitSprite()
InitMouse()
InitKeyboard()
Procedure Ligne(x1.f,y1.f,x2.f,y2.f,Couleur.l)
Shared dx.f,dy.f,xincr.l,yincr.l,x.l,y.l,erreur.f
If x1<>0 And y1<>0 And x2<>0 And y2<>0
;/* On initialise nos variables */
dx = Abs(x2-x1)
dy = Abs(y2-y1)
If x1<x2
xincr = 1
Else
xincr = -1
EndIf
If y1<y2
yincr = 1
Else
yincr = -1
EndIf
;/* Trace de ligne */
x = x1
y = y1
If dx>dy
erreur = dx/2 ; /* c'est plus esthetique comme ca */
For i= 0 To dx
x = x+xincr;
erreur = erreur+dy
If erreur > dx
erreur = erreur - dx
y = y+yincr
EndIf
If x>0 And x<DesktopWidth(0) -1 And y>0 And y<DesktopHeight(0) -1
Plot(x,y,Couleur)
EndIf
Next i
Else
erreur = dy/2; /* c'est plus esthetique comme ca */
For i=0 To dy
y = y + yincr
erreur = erreur + dx
If erreur>dy
erreur = erreur - dy
x = x + xincr
EndIf
If x>0 And x<DesktopWidth(0) -1 And y>0 And y<DesktopHeight(0)-1
Plot(x,y,Couleur)
EndIf
Next i
EndIf
EndIf
EndProcedure
SetPriorityClass_ ( GetCurrentProcess_ (), #IDLE_PRIORITY_CLASS )
If ExamineDesktops()
dw.w=DesktopWidth(0)
dh.w=DesktopHeight(0)
Else
dw.w=1024
dh.w=768
EndIf
OpenScreen(dw,dh,32,"")
dw2.w=dw/2
dh2.w=dh/2
dkx.f=0
ff.f=0
ffm.f=ff.f
t0.f=Random(400)/10
tt0.f=0.001+Random(400)/1000000
t1.f=Random(400)/10
tt1.f=0.001+Random(400)/1000000
t2.f=Random(400)/10
tt2.f=0.001+Random(400)/1000000
t3.f=Random(400)/10
tt3.f=0.001+Random(400)/1000000
ra0=dw2/4
ra1=dh2/4
t01.f=t0.f
t11.f=t1.f
t21.f=t2.f
t31.f=t3.f
Repeat
ExamineMouse()
xmouse2=MouseDeltaX()/25
ymouse2=MouseDeltaY()/25
;******************************************************* affichage
ClearScreen(0)
StartDrawing(ScreenOutput())
x1=dw2
y1=dh2
r.f=70
rr.f=0.000002
cmb=500
For i=1 To 255
rvb=RGB(i+i,i/2,i)
For u=0 To cmb
x2=dw2+Cos(t0)*ra0+Cos(t2)*ra0+Cos(ff)*r
y2=dh2+Sin(t1)*ra1+Sin(t3)*ra1+Sin(ff)*r
Ligne(x1,y1,x2,y2,rvb)
;LineXY(x1,y1,x2,y2,rvb)
;Line(x1,y1,1,1,rvb)
ff+0.91
rr*1.000001
r+rr
t0+tt0
t1+tt1
t2+tt2
t3+tt3
x1=dw2+Cos(t0)*ra0+Cos(t2)*ra0+Cos(ff)*r
y1=dh2+Sin(t1)*ra1+Sin(t3)*ra1+Sin(ff)*r
;LineXY(x1,y1,x2,y2,rvb)
ff+0.1
rr*1.001
r+rr
t0+tt0
t1+tt1
t2+tt2
t3+tt3
Next
If cmb>10
cmb-26
EndIf
Next
StopDrawing()
FlipBuffers(1)
;******************************************************* fin affichage
ff=ffm+1
ffm+0.03
t01+0.03
t11+0.04
t21+0.023
t31+0.032
t0=t01
t1=t11
t2=t21
t3=t31
ExamineKeyboard()
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All)
End
Publié : ven. 30/juin/2006 17:30
par Backup
j'ai ajouté la couleur !

Publié : ven. 30/juin/2006 21:09
par djes
Très joli

pleeeeeeeeeeeeeeease !!
Publié : sam. 01/juil./2006 13:45
par SPH
Je sais que certains d'entre vous ont des codes directX interessants. Quelqu'un pourrait il me donner le code dirextX d'une simple ligne pour que je l'essaye dans mon tunnel ?????
Publié : sam. 01/juil./2006 16:45
par SPH
Je souhaitais afficher tous les plots a l'ecran sans tester si ils depassait l'ecran, et si une erreur se produisait, je voulais rediriger le programme sur un restant d'affichage mais avec un test de depassement. Hors, a la base, le "OnErrorGoto" ne fonctionne pas ici !! PKOI ??? DUG de PB ????
Code : Tout sélectionner
; Codé par SPH(2006) sur PB4
InitSprite()
InitMouse()
InitKeyboard()
SetPriorityClass_ ( GetCurrentProcess_ (), #IDLE_PRIORITY_CLASS )
If ExamineDesktops()
dw.w=DesktopWidth(0)
dh.w=DesktopHeight(0)
Else
dw.w=1024
dh.w=768
EndIf
OpenScreen(dw,dh,32,"")
dw2.w=dw/2
dh2.w=dh/2
dkx.f=0
ff.f=0
ffm.f=ff.f
t0.f=Random(400)/10
tt0.f=0.001+Random(400)/1000000
t1.f=Random(400)/10
tt1.f=0.001+Random(400)/1000000
t2.f=Random(400)/10
tt2.f=0.001+Random(400)/1000000
t3.f=Random(400)/10
tt3.f=0.001+Random(400)/1000000
ra0=dw2/4
ra1=dh2/4
t01.f=t0.f
t11.f=t1.f
t21.f=t2.f
t31.f=t3.f
Repeat
ExamineMouse()
xmouse2=MouseDeltaX()/25
ymouse2=MouseDeltaY()/25
;******************************************************* affichage
ClearScreen(0)
StartDrawing(ScreenOutput())
x1=dw2
y1=dh2
r.f=70
rr.f=0.000002
cmb=500
OnErrorGoto(erreur)
For i=1 To 255
rvb=RGB(i,i,i)
For u=0 To cmb
x1=dw2+Cos(t0)*ra0+Cos(t2)*ra0+Cos(ff)*r
y1=dh2+Sin(t1)*ra1+Sin(t3)*ra1+Sin(ff)*r
;If x1>0 And x1<DesktopWidth(0) -1 And y1>0 And y1<DesktopHeight(0) -1
Plot(x1,y1,rvb) ; EN CAS D'ERREUR, J'ARRETE LES PLOTS POUR CETTE SEQUENCE
;EndIf
ff+0.2
rr*1.0021
r+rr
t0+tt0
t1+tt1
t2+tt2
t3+tt3
Next
If cmb>10
cmb-26
EndIf
Next
erreur:
StopDrawing()
FlipBuffers(1)
;******************************************************* fin affichage
ff=ffm+1
ffm+0.03
t01+0.03
t11+0.04
t21+0.023
t31+0.032
t0=t01
t1=t11
t2=t21
t3=t31
ExamineKeyboard()
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All)
End
Voici ce que j'ai trouvé pour faire au plus rapide : un code sans test de depassement dont je suis sûr, puis le reste du code avec test de depassement... Mais quel dommage d'en arriver la !!! :
Code : Tout sélectionner
; Codé par SPH(2006) sur PB4
InitSprite()
InitMouse()
InitKeyboard()
SetPriorityClass_ ( GetCurrentProcess_ (), #IDLE_PRIORITY_CLASS )
If ExamineDesktops()
dw.w=DesktopWidth(0)
dh.w=DesktopHeight(0)
Else
dw.w=1024
dh.w=768
EndIf
OpenScreen(dw,dh,32,"")
dw2.w=dw/2
dh2.w=dh/2
dkx.f=0
ff.f=0
ffm.f=ff.f
t0.f=Random(400)/10
tt0.f=0.001+Random(400)/1000000
t1.f=Random(400)/10
tt1.f=0.001+Random(400)/1000000
t2.f=Random(400)/10
tt2.f=0.001+Random(400)/1000000
t3.f=Random(400)/10
tt3.f=0.001+Random(400)/1000000
ra0=dw2/4
ra1=dh2/4
t01.f=t0.f
t11.f=t1.f
t21.f=t2.f
t31.f=t3.f
Repeat
ExamineMouse()
xmouse2=MouseDeltaX()/25
ymouse2=MouseDeltaY()/25
;******************************************************* affichage
ClearScreen(0)
StartDrawing(ScreenOutput())
x1=dw2
y1=dh2
r.f=70
rr.f=0.000002
cmb=500
For i=1 To 100
rvb=RGB(i,i,i)
For u=0 To cmb
x1=dw2+Cos(t0)*ra0+Cos(t2)*ra0+Cos(ff)*r
y1=dh2+Sin(t1)*ra1+Sin(t3)*ra1+Sin(ff)*r
Plot(x1,y1,rvb)
ff+0.2
rr*1.0021
r+rr
t0+tt0
t1+tt1
t2+tt2
t3+tt3
Next
If cmb>10
cmb-26
EndIf
Next
;******************** suite avec test
For i=101 To 255
rvb=RGB(i,i,i)
For u=0 To cmb
x1=dw2+Cos(t0)*ra0+Cos(t2)*ra0+Cos(ff)*r
y1=dh2+Sin(t1)*ra1+Sin(t3)*ra1+Sin(ff)*r
If x1>0 And x1<DesktopWidth(0) -1 And y1>0 And y1<DesktopHeight(0) -1
Plot(x1,y1,rvb)
EndIf
ff+0.2
rr*1.0021
r+rr
t0+tt0
t1+tt1
t2+tt2
t3+tt3
Next
If cmb>10
cmb-26
EndIf
Next
StopDrawing()
FlipBuffers(1)
;******************************************************* fin affichage
ff=ffm+1
ffm+0.04
t01+0.05
t11+0.04
t21+0.023
t31+0.032
t0=t01
t1=t11
t2=t21
t3=t31
ExamineKeyboard()
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All)
End
Publié : dim. 02/juil./2006 11:17
par Anonyme
- je n'ai pas trop compris ton problème, mais le fait de faire un test pour savoir si le plot est a l'écran, ne bouffe pas plus de temps CPU.
- je ne pense pas que tu puisse déssiner un simple plot() via DirectX, en tout ca je ne sais pas le faire, en revanche regarde du coté de DrawingBuffer(), mais bon, le gain de temps pour plot est médiocre, plot() est optimisé.
@++
Publié : dim. 02/juil./2006 11:23
par Flype
Publié : dim. 02/juil./2006 11:44
par SPH
Waouw, j'ai matté les exemples et ca a l'air d'etre geant. Mais je n'ai absolument pas compris le principe !!!

Publié : dim. 02/juil./2006 11:55
par Backup
j'aimerai bien que POINT() soit acceleré en purebasic !!
parceque c'est cette fonction qui est lente !!

Publié : dim. 02/juil./2006 13:22
par SPH
Dobro a écrit :j'aimerai bien que POINT() soit acceleré en purebasic !!
parceque c'est cette fonction qui est lente !!

Oui, elle est lente. Mais point ne me sert plus du tout depuis que l'on peux passer un tableau en memoire video.
Publié : dim. 02/juil./2006 14:51
par Thyphoon
J'ai fait plein de test pour point....Et le plus rapide c'est de faire un Poke c'est même plus rapide qu'un pointeur (40fois plus rapide qu'un point).
la methode est simple
Code : Tout sélectionner
StartDrawing(Spriteoutput(0)) ; ça marche aussi avec screenoutput()
Address=DrawingBuffer()
Pitch=DrawingBufferPitch()
PixelFormat=DrawingBufferPixelFormat()
Width=SpriteWidth(0)
Height=SpriteWidth(0)
StopDrawing()
;et apres il suffit de faire un
PokeL(Address+x*4+Pitch*y,col) ; le 4 c'est part ce que je suis en 32 bit
vitesse garantie ...
Publié : dim. 02/juil./2006 15:10
par djes
Tu fais un poke pour point, toi! Tu es sûr de ton coup???

Publié : dim. 02/juil./2006 16:27
par Thyphoon
djes a écrit :Tu fais un poke pour point, toi! Tu es sûr de ton coup???

Oui regarde ça ...
Code : Tout sélectionner
; Codé par SPH(2006) sur PB4
InitSprite()
InitMouse()
InitKeyboard()
SetPriorityClass_ ( GetCurrentProcess_ (), #IDLE_PRIORITY_CLASS )
Global Address.l,Pitch.l
If ExamineDesktops()
dw.w=DesktopWidth(0)
dh.w=DesktopHeight(0)
Else
dw.w=800
dh.w=600
EndIf
If OpenScreen(dw,dh,32,"")
StartDrawing(ScreenOutput())
Address=DrawingBuffer()
Pitch=DrawingBufferPitch()
StopDrawing()
dw2.w=dw/2
dh2.w=dh/2
dkx.f=0
ff.f=0
ffm.f=ff.f
t0.f=Random(400)/10
tt0.f=0.001+Random(400)/1000000
t1.f=Random(400)/10
tt1.f=0.001+Random(400)/1000000
t2.f=Random(400)/10
tt2.f=0.001+Random(400)/1000000
t3.f=Random(400)/10
tt3.f=0.001+Random(400)/1000000
ra0=dw2/4
ra1=dh2/4
t01.f=t0.f
t11.f=t1.f
t21.f=t2.f
t31.f=t3.f
Repeat
ExamineMouse()
xmouse2=MouseDeltaX()/25
ymouse2=MouseDeltaY()/25
;******************************************************* affichage
ClearScreen(0)
x1=dw2
y1=dh2
r.f=70
rr.f=0.000002
cmb=500
For i=1 To 100
rvb=RGB(i,i,i)
For u=0 To cmb
x1=dw2+Cos(t0)*ra0+Cos(t2)*ra0+Cos(ff)*r
y1=dh2+Sin(t1)*ra1+Sin(t3)*ra1+Sin(ff)*r
PokeL(Address+x1*4+Pitch*y1,rvb)
ff+0.2
rr*1.0021
r+rr
t0+tt0
t1+tt1
t2+tt2
t3+tt3
Next
If cmb>10
cmb-26
EndIf
Next
;******************** suite avec test
For i=101 To 255
rvb=RGB(i,i,i)
For u=0 To cmb
x1=dw2+Cos(t0)*ra0+Cos(t2)*ra0+Cos(ff)*r
y1=dh2+Sin(t1)*ra1+Sin(t3)*ra1+Sin(ff)*r
If x1>0 And x1<DesktopWidth(0) -1 And y1>0 And y1<DesktopHeight(0) -1
PokeL(Address+x1*4+Pitch*y1,rvb)
EndIf
ff+0.2
rr*1.0021
r+rr
t0+tt0
t1+tt1
t2+tt2
t3+tt3
Next
If cmb>10
cmb-26
EndIf
Next
FlipBuffers(1)
;******************************************************* fin affichage
ff=ffm+1
ffm+0.04
t01+0.05
t11+0.04
t21+0.023
t31+0.032
t0=t01
t1=t11
t2=t21
t3=t31
ExamineKeyboard()
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All)
EndIf
End
Et on pourrait encore augmenté legerement la rapidité en utilisant des tableaux pour les cos/sin etc...
Publié : dim. 02/juil./2006 17:10
par Backup
pour les durs de la feuille la fonction
point() (qui est tres lente)
SERT A LIRE UN POINT A l'ECRAN !!!
Couleur = Point(x, y)
Description
Renvoie dans la variable 'Couleur' la couleur affichée à la position x,y de la surface de dessin en cours. La valeur retournée dans Couleur est un nombre codé sur 24 bits qui contient la combinaison des trois couleurs de base (Rouge, Vert, Bleu) codées chacune sur 8 bits (valeur 0 à 255).
La couleur peut être facilement décomposée en valeur RVB à l'aide des commandes Red(), Green() et Blue().
effectivement tu doit avoir du mal a lire avec un POKE !!
(encore que ceux qui ont connu le port cartouche des ATARI ST savent que c'es possible

)
la preuve ça va aussi vite avec plot !! que ton astuce !
Code : Tout sélectionner
; Codé par SPH(2006) sur PB4
InitSprite()
InitMouse()
InitKeyboard()
SetPriorityClass_ ( GetCurrentProcess_ (), #IDLE_PRIORITY_CLASS )
Global Address.l,Pitch.l
If ExamineDesktops()
dw.w=DesktopWidth(0)
dh.w=DesktopHeight(0)
Else
dw.w=800
dh.w=600
EndIf
If OpenScreen(dw,dh,32,"")
;StartDrawing(ScreenOutput())
; Address=DrawingBuffer()
; Pitch=DrawingBufferPitch()
; StopDrawing()
dw2.w=dw/2
dh2.w=dh/2
dkx.f=0
ff.f=0
ffm.f=ff.f
t0.f=Random(400)/10
tt0.f=0.001+Random(400)/1000000
t1.f=Random(400)/10
tt1.f=0.001+Random(400)/1000000
t2.f=Random(400)/10
tt2.f=0.001+Random(400)/1000000
t3.f=Random(400)/10
tt3.f=0.001+Random(400)/1000000
ra0=dw2/4
ra1=dh2/4
t01.f=t0.f
t11.f=t1.f
t21.f=t2.f
t31.f=t3.f
Repeat
ExamineMouse()
xmouse2=MouseDeltaX()/25
ymouse2=MouseDeltaY()/25
;******************************************************* affichage
ClearScreen(0)
x1=dw2
y1=dh2
r.f=70
rr.f=0.000002
cmb=500
StartDrawing(ScreenOutput() )
For i=1 To 100
rvb=RGB(i,i,i)
For u=0 To cmb
x1=dw2+Cos(t0)*ra0+Cos(t2)*ra0+Cos(ff)*r
y1=dh2+Sin(t1)*ra1+Sin(t3)*ra1+Sin(ff)*r
; PokeL(Address+x1*4+Pitch*y1,rvb)
Plot(x1,y1,RGB(255,255,255))
ff+0.2
rr*1.0021
r+rr
t0+tt0
t1+tt1
t2+tt2
t3+tt3
Next
If cmb>10
cmb-26
EndIf
Next
;******************** suite avec test
For i=101 To 255
rvb=RGB(i,i,i)
For u=0 To cmb
x1=dw2+Cos(t0)*ra0+Cos(t2)*ra0+Cos(ff)*r
y1=dh2+Sin(t1)*ra1+Sin(t3)*ra1+Sin(ff)*r
If x1>0 And x1<DesktopWidth(0) -1 And y1>0 And y1<DesktopHeight(0) -1
; PokeL(Address+x1*4+Pitch*y1,rvb)
Plot(x1,y1,RGB(255,255,255))
EndIf
ff+0.2
rr*1.0021
r+rr
t0+tt0
t1+tt1
t2+tt2
t3+tt3
Next
If cmb>10
cmb-26
EndIf
Next
StopDrawing()
FlipBuffers(1)
;******************************************************* fin affichage
ff=ffm+1
ffm+0.04
t01+0.05
t11+0.04
t21+0.023
t31+0.032
t0=t01
t1=t11
t2=t21
t3=t31
ExamineKeyboard()
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All)
EndIf
End
par contre ton astuce doit alle plus vite avec PEEK que le point()
Publié : dim. 02/juil./2006 17:22
par Thyphoon
lollllllll je comprends ce que vous voulez ...
Moi j'entendais Point comme un "point" pas comme la fonction point
donc pour préciser ce que je disais...
moi j'utilise
Peekl() a la place de Point()
et
Pokel() a la place de Plot()
voilà
et Peek est plus rapide que POint et Poke plus rapide que plot
c'est tout ce que je voulais dire
