Page 1 sur 1

Code PureBasic v3.94 => 5.62 ?

Publié : mar. 06/mars/2018 23:51
par SPH
Salut,

j'ai essayé un vieux code que j'ai et qui a ete fait sur pb 3.94
Helas, ca ne passe pas (et pourtant, tout semble coller)
Mon ordi commence a deconner. Alors avec tout ca, je ne ssais plus quoi croire...

Quelqu'un pourrait il adapter ce code pour pb 5.62 ?

THXXxx

Code : Tout sélectionner

; Real BSpline code by Crisot / Universe

Dim x.f(200)
Dim y.f(200)

Exemple=1
;Exemple 1: 4 points de base (comme le mec), qui tracent une vrai bspline
;Exemple 2: Pareil que le 1, mais la courbe passe par les points début et fin
;  grace au triplage des points début et fin
;Exemple 3: 4 points en carré, qui tracent un quart de cercle
;Exemple 4: 7 points en carré, qui tracent cercle complet
;Exemple 5: Plein de points au pif
;Exemple 6: Plein de points au pif, courbe qui passe par les points début et fin

;synchro = 1: sert juste aux courbes qui passent par les points début et fin, car
;  pour ces courbes, les points sont répétés 3 fois, et il faut pouvoir déplacer les 3
;  en même temps, sinon ça nique tout :)

If exemple=1
  nombre=4
  x(0)=0 : y(0)=0
  x(1)=1023 : y(1)=0
  x(2)=0 : y(2)=767
  x(3)=1023 : y(3)=767
EndIf

If exemple=2
  nombre=8
  synchro=1   ; Gruge pour déplacer les points 3 par 3, car x0=x1=x2, etc...
  x(0)=0 : y(0)=0
  x(1)=x(0) : y(1)=y(0)
  x(2)=x(0) : y(2)=y(0)
  x(3)=1023 : y(3)=0
  x(4)=0 : y(4)=767
  x(5)=1023 : y(5)=767
  x(6)=x(5) : y(6)=y(5)
  x(7)=x(5) : y(7)=y(5)
EndIf

If exemple=3
  nombre=4
  x(0)=0 : y(0)=0
  x(1)=1023 : y(1)=0
  x(2)=1023 : y(2)=767
  x(3)=0 : y(3)=767
EndIf

If exemple=4
  nombre=7
  x(0)=0 : y(0)=0
  x(1)=1023 : y(1)=0
  x(2)=1023 : y(2)=767
  x(3)=0 : y(3)=767
  x(4)=x(0) : y(4)=y(0)
  x(5)=x(1) : y(5)=y(1)
  x(6)=x(2) : y(6)=y(2)
EndIf

If exemple=5
  nombre=12
  x(0)=0 : y(0)=0
  x(1)=80 : y(1)=100
  x(2)=60 : y(2)=600
  x(3)=800 : y(3)=700
  x(4)=500 : y(4)=0
  x(5)=1000 : y(5)=300
  x(6)=700 : y(6)=100
  x(7)=200 : y(7)=0
  x(8)=0 : y(8)=700
  x(9)=100 : y(9)=0
  x(10)=0 : y(10)=200
  x(11)=300 : y(11)=300
EndIf

If exemple=6
  nombre=12
  synchro=1   ; Gruge pour déplacer les points 3 par 3, car x0=x1=x2, etc...
  x(0)=100 : y(0)=100
  x(1)=x(0) : y(1)=y(0)
  x(2)=x(0) : y(2)=y(0)
  x(3)=300 : y(3)=150
  x(4)=400 : y(4)=350
  x(5)=200 : y(5)=450
  x(6)=500 : y(6)=200
  x(7)=700 : y(7)=700
  x(8)=600 : y(8)=600
  x(9)=1000 : y(9)=550
  x(10)=x(9) : y(10)=y(9)
  x(11)=x(9) : y(11)=y(10)
EndIf


Procedure bspline(x0,y0,x1,y1,x2,y2,x3,y3,color) 

  For i = 0 To 100

    t1.f = i/100
    t2.f = t1*t1
    t3.f = t1*t1*t1

  	k1.f = 1 - 3*t1 + 3*t2 - t3
    k2.f = 4 - 6*t2 + 3*t3
  	k3.f = 1 + 3*t1 + 3*t2 - 3*t3

    xfinal.f = (x0 * k1 + x1 * k2 + x2 * k3 + x3 * t3) / 6
		yfinal.f = (y0 * k1 + y1 * k2 + y2 * k3 + y3 * t3) / 6

    Plot (xfinal,yfinal,color)   

  Next I


EndProcedure 

InitSprite() 
InitKeyboard() 
InitMouse() 

OpenScreen(1280,1024,32,"Bezier") 

cw = RGB(255,255,255) 
cr = RGB(255,0,0) 

Repeat 
  ExamineKeyboard() 
  ExamineMouse() 

  If MouseButton(1) And mousepush=0
    key=key+1 : key=key%nombre
    MouseLocate(x(key),y(key))
  EndIf 
  mousepush=MouseButton(1) 

  x(key)=MouseX() : y(key)=MouseY() ; Déplacement du point

  If synchro=1            ; Juste une gruge pour bouger les points, rien à voir avec la courbe.
    x(1)=x(0) : y(1)=y(0)
    x(2)=x(0) : y(2)=y(0)
    x(nombre-1)=x(nombre-3) : y(nombre-1)=y(nombre-3)
    x(nombre-2)=x(nombre-3) : y(nombre-2)=y(nombre-3)
  EndIf

  StartDrawing(ScreenOutput())
;  DrawingMode(4)
  For n=0 To nombre-1   ; On trace les cercles...
    If n=key : Circle(x(n),y(n),5,cr) : Else : Circle(x(n),y(n),5,cw) : EndIf
  Next
  For n=0 To nombre-4   ; On trace la bspline
    bspline(x(n),y(n),x(n+1),y(n+1),x(n+2),y(n+2),x(n+3),y(n+3),cw)
  Next
  StopDrawing() 

  FlipBuffers() 
  ClearScreen(0) 
Until KeyboardPushed(1)

; ExecutableFormat=Windows
; FirstLine=1
; EOF

; IDE Options = PureBasic v3.94 (Windows - x86) (Demo)
; CursorPosition = 5
; Folding = -

Re: Code PureBasic v3.94 => 5.62 ?

Publié : mer. 07/mars/2018 0:31
par Ar-S
En 5.46 et 5.62 le code marche mais en 5.62 mon affichage écran s'est étrangement éteint au bout de quelques sec.. J'ai pas voulu réessayer.
Mais dans tous les cas le code marche. Et j'ai testé en x64

Re: Code PureBasic v3.94 => 5.62 ?

Publié : mer. 07/mars/2018 16:57
par SPH
moi, ca ne marche pas : pire, le code fait planter l'ordi en refusant de faire CTRL+ALT+SUPP

Quelqu'un d'autre pourrait essayer ?

Merci

Re: Code PureBasic v3.94 => 5.62 ?

Publié : mer. 07/mars/2018 19:22
par SPH
Bon, j'ai reussi a faire ce que je voulais et je partage ce code :

Code : Tout sélectionner

 ;Initialisation des sprites, du clavier et de la souris 
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Erreur", "Impossible d'initialiser l'écran.")
  End
EndIf



Dim x.f(200)
Dim y.f(200)


Exemple=1
;Exemple 1: 4 points de base (comme le mec), qui tracent une vrai bspline
;Exemple 2: Pareil que le 1, mais la courbe passe par les points début et fin
;  grace au triplage des points début et fin
;Exemple 3: 4 points en carré, qui tracent un quart de cercle
;Exemple 4: 7 points en carré, qui tracent cercle complet
;Exemple 5: Plein de points au pif
;Exemple 6: Plein de points au pif, courbe qui passe par les points début et fin

;synchro = 1: sert juste aux courbes qui passent par les points début et fin, car
;  pour ces courbes, les points sont répétés 3 fois, et il faut pouvoir déplacer les 3
;  en même temps, sinon ça nique tout :)

If exemple=1
  nombre=4
  x(0)=0 : y(0)=0
  x(1)=1023 : y(1)=0
  x(2)=0 : y(2)=767
  x(3)=1023 : y(3)=767
EndIf

If exemple=2
  nombre=8
  synchro=1   ; Gruge pour déplacer les points 3 par 3, car x0=x1=x2, etc...
  x(0)=0 : y(0)=0
  x(1)=x(0) : y(1)=y(0)
  x(2)=x(0) : y(2)=y(0)
  x(3)=1023 : y(3)=0
  x(4)=0 : y(4)=767
  x(5)=1023 : y(5)=767
  x(6)=x(5) : y(6)=y(5)
  x(7)=x(5) : y(7)=y(5)
EndIf

If exemple=3
  nombre=4
  x(0)=0 : y(0)=0
  x(1)=1023 : y(1)=0
  x(2)=1023 : y(2)=767
  x(3)=0 : y(3)=767
EndIf

If exemple=4
  nombre=7
  x(0)=0 : y(0)=0
  x(1)=1023 : y(1)=0
  x(2)=1023 : y(2)=767
  x(3)=0 : y(3)=767
  x(4)=x(0) : y(4)=y(0)
  x(5)=x(1) : y(5)=y(1)
  x(6)=x(2) : y(6)=y(2)
EndIf

If exemple=5
  nombre=12
  x(0)=0 : y(0)=0
  x(1)=80 : y(1)=100
  x(2)=60 : y(2)=600
  x(3)=800 : y(3)=700
  x(4)=500 : y(4)=0
  x(5)=1000 : y(5)=300
  x(6)=700 : y(6)=100
  x(7)=200 : y(7)=0
  x(8)=0 : y(8)=700
  x(9)=100 : y(9)=0
  x(10)=0 : y(10)=200
  x(11)=300 : y(11)=300
EndIf

If exemple=6
  nombre=12
  synchro=1   ; Gruge pour déplacer les points 3 par 3, car x0=x1=x2, etc...
  x(0)=100 : y(0)=100
  x(1)=x(0) : y(1)=y(0)
  x(2)=x(0) : y(2)=y(0)
  x(3)=300 : y(3)=150
  x(4)=400 : y(4)=350
  x(5)=200 : y(5)=450
  x(6)=500 : y(6)=200
  x(7)=700 : y(7)=700
  x(8)=600 : y(8)=600
  x(9)=1000 : y(9)=550
  x(10)=x(9) : y(10)=y(9)
  x(11)=x(9) : y(11)=y(10)
EndIf


Procedure bspline(x0,y0,x1,y1,x2,y2,x3,y3,color) 

  For i = 0 To 100

    t1.f = i/100
    t2.f = t1*t1
    t3.f = t1*t1*t1

     k1.f = 1 - 3*t1 + 3*t2 - t3
    k2.f = 4 - 6*t2 + 3*t3
     k3.f = 1 + 3*t1 + 3*t2 - 3*t3

    xfinal.f = (x0 * k1 + x1 * k2 + x2 * k3 + x3 * t3) / 6
      yfinal.f = (y0 * k1 + y1 * k2 + y2 * k3 + y3 * t3) / 6

    Plot (xfinal,yfinal,color)   

  Next I


EndProcedure 

  
  
  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

OpenScreen(1024,768,32,"")

cw = RGB(255,255,255) 
cr = RGB(255,0,0) 


 ;Boucle principale
Repeat
  
  ExamineMouse() 

  If MouseButton(1) And mousepush=0
    key=key+1 : key=key%nombre
    MouseLocate(x(key),y(key))
  EndIf 
  mousepush=MouseButton(1) 

  x(key)=MouseX() : y(key)=MouseY() ; Déplacement du point

  If synchro=1            ; Juste une gruge pour bouger les points, rien à voir avec la courbe.
    x(1)=x(0) : y(1)=y(0)
    x(2)=x(0) : y(2)=y(0)
    x(nombre-1)=x(nombre-3) : y(nombre-1)=y(nombre-3)
    x(nombre-2)=x(nombre-3) : y(nombre-2)=y(nombre-3)
  EndIf
  
  ClearScreen(0)
  
  StartDrawing(ScreenOutput())
  DrawingMode(4)
  For n=0 To nombre-1   ; On trace les cercles...
    If n=key : Circle(x(n),y(n),5,cr) : Else : Circle(x(n),y(n),5,cw) : EndIf
  Next
  For n=0 To nombre-4   ; On trace la bspline
    bspline(x(n),y(n),x(n+1),y(n+1),x(n+2),y(n+2),x(n+3),y(n+3),cw)
  Next
  StopDrawing() 

  
  

ExamineKeyboard()

FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)