Page 1 sur 2

Un Tunnel

Publié : ven. 30/juin/2006 9:03
par SPH
Un nouveau code prometteur :wink: :

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 255
rvb=RGB(i,i,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
LineXY(x1,y1,x2,y2,rvb)
;Line(x1,y1,1,1,rvb)
ff+0.1
rr*1.001
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 10:18
par Flype
bravo SPH, le rendu est excellent.

Publié : ven. 30/juin/2006 10:44
par Dräc
C'est à gerber :D (L’effet est excellent, sa donne le tournique)
Question, il y a quel monde au bout du vortex ?

Publié : ven. 30/juin/2006 10:46
par Thyphoon
Exelent ! Mais j'ai rencontré un vieux bug de Purebasic que j'avais déjà dans la version 3. Si tu laisse longtemps tourné ton code, au bout d'un certain temps j'ai un plantage
Ligne 50: The specified output is NULL(0 value)

ça arrive de temps en temps ...Est ce que d'autre on eu le même problème ?

Publié : ven. 30/juin/2006 10:58
par Frenchy Pilou
Un vortex :)

Publié : ven. 30/juin/2006 10:59
par Dräc
Na! Combeint de temps avant ton erreur?

Publié : ven. 30/juin/2006 10:59
par Thyphoon
Dräc a écrit :Na! Combeint de temps avant ton erreur?
3 minutes...mais c'est alléatoire ... A la limite laisse le tourner pendant que tu vas manger tu verra. :wink:

Publié : ven. 30/juin/2006 11:17
par Anonyme
un brin d'optimisation : :D

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) 
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.1 
rr*1.001 
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 11:46
par SPH
@captain bator : chez moi, ton code est beaucoup plus lent que le mien !!

Publié : ven. 30/juin/2006 12:04
par Dräc
Thyphoon a écrit :
Dräc a écrit :Na! Combeint de temps avant ton erreur?
3 minutes...mais c'est alléatoire ... A la limite laisse le tourner pendant que tu vas manger tu verra. :wink:
Tourjours rien et en regardant rapidement le code, je n'ai pas vu de risque de fuite mémoire ni de division par 0...

Publié : ven. 30/juin/2006 12:06
par Anonyme
SPH a écrit :@captain bator : chez moi, ton code est beaucoup plus lent que le mien !!
:?

tu as enlever le débugger ??

Chez moi c'est au moins 10x plus rapide , quelqu'un peut confirmer ?

Publié : ven. 30/juin/2006 12:12
par Sehka
Salut à tous,
Je ne dirais pas 10 X mais bien 6 X :wink:
Quoiqu'il en soit c'est sympa comme Tournicotti 0X

Publié : ven. 30/juin/2006 12:26
par SPH
Ha oui, une fois compilé, ca va tres tres vite en effet !
Bravo pour ton optimisation, je ne sais pas trop ce que tu as fait mais ca boost. Ca veux aussi dire que tu es bon en code car pour lire le code des autres, ce n'est jamais facile...

:wink:

Publié : ven. 30/juin/2006 15:36
par Anonyme
je ne suis pas spécialement bon en quoi que ce soit, j'ai juste changer LineXY() par une fonction perso. :wink:

Publié : ven. 30/juin/2006 15:49
par Flype
ligne 116: commenter ClearScreen(0)
ligne 126: changer par rvb=RGB(0,0,i)

je pourrais regarder pdt des heures...