Biorythmes - Problème pour dessiner une courbe

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
PCPixMusic
Messages : 106
Inscription : ven. 06/janv./2017 9:50

Biorythmes - Problème pour dessiner une courbe

Message par PCPixMusic »

Bonjour :P

Je suis en train de traduire un générateur de biorythmes (ce n'est pas très scientifique, mais c'est marrant) en Turbo Pascal 7
vers PureBasic, malheureusement, ça ne marche absolument pas et je ne comprends pas pourquoi. :cry:

La courbe ne se dessine pas, à la place il y a des formes triangulaires, qui partent toutes du point zéro. 8O

Voici d'abord la partie du code en TP7 vers PureBasic, puis ensuite un troisième copié-coller avec le code intégrale
de ma version PureBasic, pour le moment seul la partie pour la courbe physique est active, afin de mieux voir d'où vient le problème.

Merci beaucoup par avance à celui qui arrivera à résoudre ce problème. :oops: :oops: :oops:

Code d'origine en Turbo Pascal :

Code : Tout sélectionner

SetColor(1);
Phys := Sin(2*PI*NB/23);

 MoveTo(64, 170-Round(Phys*150));

 FOR i := 1 TO 496 DO 
 BEGIN;
 Phys := Sin(2*PI*(NB+i/16)/23);
 LineTo(64+i, 170-Round(Phys*150));
 END;
Code traduit en PureBasic :

Code : Tout sélectionner

 Phys = Sin(2*PI*NB/23)           
 For i = 1 To Long_Date_Graph
 Phys = Sin(2*PI*(NB+i/16)/23)
   LineXY(60,309,60+i,309-Round(Phys*150 ,#PB_Round_Down),#Blue)
 Next
Code de la version entier PureBasic

Code : Tout sélectionner

EnableExplicit

;PROGRAM RiteMe;

;-Contantes

Enumeration
  
#Fenetre_1
#Fenetre_2
#Fenetre_3
#Fenetre_4

#Close_Fenetre_1
#Close_Fenetre_2
#Close_Fenetre_3
#Close_Fenetre_4

#Bouton_OK

#Bouton_Nouvelle_Date_De_Naissance
#Bouton_Nouvelle_Date_Examen

#Nombres_Jours_1
#Nombres_Jours_2

#Font_Courier
#Font_Arial
#Font_Segoe_UI

#Jour1
#Mois1
#Annee1
#Jour2
#Mois2
#Annee2
#Age
#Bissextile
#Fcteur1
#Fcteur2
#Date1
#Date2

#Date_De_Naissance
#Date_Examen

#Text_1
#Text_2
#Text_3
#Text_4
#Text_5
#Text_6
#Text_7
#Text_8
#Text_9
#Text_10
#Text_11
#Text_12
#Text_13
#Text_14
#Text_15
#Text_16
#Text_17
#Text_18
#Text_19
#Text_20

#TextAPropos1
#TextAPropos2
#TextAPropos3

#A_Porpos
#Close_A_Porpos
#Fenetre_a_propos

#ID_Son_1

EndEnumeration

;-Variables

Global Age.i,Bissextile.i
Global PI.l,NB.l,Facteur_De_Naissance.l,Facteur_Examen.l,S.s,T.S
Global Date1.s,Date2.s,AgeStr.s,Annee2Str.s,Str.s,Facteur_ExamenStr.s,Clavier.s
Global glEvent.l, glGadget.l, glType.l
Global Date_De_Naissance.i,Date_Examen.i

Global i.i,j.i,Long.i
Global S.s,iColor.i
Global R.b,Phys.b,Emot.b,Intel.b,Spirit.b,Crea.b,Esthe.b,Intui.b 

Global Jour1Str.s, Mois1Str.s, Annee1Str.s, Annee2Str.s,Date_De_NaissanceStr.s,Date_ExamenStr.s
Global Jour_De_Naissance.s,Mois_De_Naissance.s,Annee_De_Naissance.s,Nombre_De_JourStr.s
Global  Jour_Examen.s,Mois_Examen.s,Annee_Examen.s,Date_De_NaissanceStr.s,Date_ExamenStr.s

;-Déclaration de Procedures

Declare DateNaissance()
Declare DateExamen()
Declare.l Calcul_Facteur_Examen(Jour.i,Mois.i,Annee.i)
Declare.s ConversionDate(Jour.i,Mois.i,Annee.i)
Declare.s Semaine(Facteur_Examen.l)
Declare.s NumStr(n.w,d.b)
Declare Examine_Graphic_Dates(Index.i)
Declare Jour_Du_Mois(Longeur_mois.i)
Declare Visualisation()
Declare Presentation()

UseOGGSoundDecoder()  ; Utilisation des fichiers Ogg
UseFLACSoundDecoder() ; Utilisation des fichiers Flac
UseJPEG2000ImageDecoder()
UseJPEG2000ImageEncoder()
UseJPEGImageDecoder()
UseJPEGImageEncoder()
UsePNGImageDecoder()
UsePNGImageEncoder()
UseFLACSoundDecoder()
UseOGGSoundDecoder()

InitSound()
InitSprite()
InitMovie()
InitMouse()
InitKeyboard()

LoadFont(#Font_Courier, "Courier", 15)
LoadFont(#Font_Arial, "Arial", 24)
LoadFont(#Font_Segoe_UI, "Segoe UI", 12)

Presentation()
;DateNaissance()
;DateExamen()
 
Procedure DateNaissance()    
  Date_De_NaissanceStr = GetGadgetText(#Date_De_Naissance)
  
  Jour_De_Naissance  = Mid(Date_De_NaissanceStr,1,2)  
  Mois_De_Naissance  = Mid(Date_De_NaissanceStr,4,2)
  Annee_De_Naissance = Mid(Date_De_NaissanceStr,7,4)

EndProcedure

Procedure DateExamen()  
  Date_ExamenStr  = GetGadgetText(#Date_Examen) 
  
  Jour_Examen  = Mid(Date_ExamenStr, 1, 2)  
  Mois_Examen  = Mid(Date_ExamenStr, 4, 2)  
  Annee_Examen = Mid(Date_ExamenStr, 7, 4)
EndProcedure;

Procedure.l Calcul_Facteur_Examen(Jour.i,Mois.i,Annee.i)
  Protected  R.l
  
  R = 0
  
 Select Mois
      
  Case 1,2
     R = 365*Annee + 31*(Mois-1) + Jour + (Annee-1) / 4 - 3*((Annee-1)/ 100 + 1) / 4
     
   Case 3,4,5,6,7,8,9,10,11,12 
     R = 365*Annee + Jour + 31*(Mois-1) - (4*Mois+23) / 10 + Annee / 4 - 3*(Annee / 100 + 1) / 4
         
EndSelect

ProcedureReturn R

EndProcedure;

Procedure.s ConversionDate(Jour.i,Mois.i,Annee.i)
  Protected J.s,M.s,A.s
  
  J = ""
  M = ""
  A = ""
  
  J = Str(Jour)
  A  = Str(Annee)
  
  Select Mois      
    Case 1 : M = "Janvier"
    Case 2 : M = "Février"
    Case 3 : M = "Mars"
    Case 4:  M = "Avril"
    Case 5 : M = "Mai"
    Case 6 : M = "Juin"
    Case 7 : M = "Juillet"
    Case 8 : M = "Août"
    Case 9 : M = "Septembre"
    Case 10: M = "Octobre"
    Case 11: M = "Novembre"
    Case 12: M = "Décembre"
EndSelect

  ProcedureReturn J + " " + M +" "+ A
EndProcedure

Procedure.s Semaine(Facteur_Examen.l)

J = Facteur_Examen + (-Facteur_Examen / 7)*7

Select Abs(J)  
    Case 0: S = "Dimanche"
    Case 1: S = "Lundi"
    Case 2: S = "Mardi"
    Case 3: S = "Mercredi"
    Case 4: S = "Jeudi"
    Case 5: S = "Vendredi"
    Case 6: S = "Samedi"
  EndSelect
  
  ProcedureReturn S
  
EndProcedure

Procedure.s NumStr(n.w,d.b)
  
  ProcedureReturn Chr(d)
  
  While d>0     
      ProcedureReturn Chr(Mod(n,10)+Asc("0"))
      n = n / 10
      ;Dec(D)      
   Wend      
      
 EndProcedure

 Procedure Examine_Graphic_Dates(Index.i)      
 Protected Long_Date.i
 
 If Index = 28 : Long_Date = 905 : EndIf
 If Index = 29 : Long_Date = 935 : EndIf
 If Index = 30 : Long_Date = 965 : EndIf
 If Index = 31 : Long_Date = 995 : EndIf
 
;Lignes Horizontales
LineXY(59,309,Long_Date,309,#Black) 
LineXY(59,310,Long_Date,310,#Black) 
LineXY(59,311,Long_Date,311,#Black)

;Lignes Verticales
LineXY(Long_Date,  290,Long_Date,327,#Black)
LineXY(Long_Date+1,290,Long_Date+1,327,#Black)
LineXY(Long_Date+2,290,Long_Date+2,327,#Black)
EndProcedure
  
Procedure Jour_Du_Mois(Longeur_mois.i) 
  
Box(0,0,1200,700,RGB(150, 150, 150))

;Lignes Verticales
LineXY(58,02,58,618,#Black)
LineXY(59,02,59,618,#Black)
LineXY(60,02,60,618,#Black)

DrawText(20, 02,"+1.0",#Black,RGB(150,150,150))
DrawText(20, 32,"+0.9",#Black,RGB(150,150,150))
DrawText(20, 62,"+0.8",#Black,RGB(150,150,150))
DrawText(20, 92,"+0.7",#Black,RGB(150,150,150))
DrawText(20,122,"+0.6",#Black,RGB(150,150,150))
DrawText(20,152,"+0.5",#Black,RGB(150,150,150))
DrawText(20,182,"+0 4",#Black,RGB(150,150,150))
DrawText(20,212,"+0.3",#Black,RGB(150,150,150))
DrawText(20,242,"+0.2",#Black,RGB(150,150,150))
DrawText(20,272,"+0.1",#Black,RGB(150,150,150))

DrawText(24,302,"0",#Black,RGB(150,150,150))

DrawText(20,332,"-0.1",#Black,RGB(150,150,150))
DrawText(20,362,"-0.2",#Black,RGB(150,150,150))
DrawText(20,392,"-0.3",#Black,RGB(150,150,150))
DrawText(20,422,"-0.4",#Black,RGB(150,150,150))
DrawText(20,452,"-0.5",#Black,RGB(150,150,150))
DrawText(20,482,"-0.6",#Black,RGB(150,150,150))
DrawText(20,512,"-0.7",#Black,RGB(150,150,150))
DrawText(20,542,"-0.8",#Black,RGB(150,150,150))
DrawText(20,572,"-0.9",#Black,RGB(150,150,150))
DrawText(20,602,"-1.0",#Black,RGB(150,150,150))
  
DrawText(70, 312," 1",#Black,RGB(150,150,150))
DrawText(100,312," 2",#Black,RGB(150,150,150))
DrawText(130,312," 3",#Black,RGB(150,150,150))
DrawText(160,312," 4",#Black,RGB(150,150,150))
DrawText(190,312," 5",#Black,RGB(150,150,150))
DrawText(220,312," 6",#Black,RGB(150,150,150))
DrawText(250,312," 7",#Black,RGB(150,150,150))
DrawText(280,312," 8",#Black,RGB(150,150,150))
DrawText(310,312," 9",#Black,RGB(150,150,150))

DrawText(340,312,"10",#Black,RGB(150,150,150))
DrawText(370,312,"11",#Black,RGB(150,150,150))
DrawText(400,312,"12",#Black,RGB(150,150,150))
DrawText(430,312,"13",#Black,RGB(150,150,150))
DrawText(460,312,"14",#Black,RGB(150,150,150))
DrawText(490,312,"15",#Black,RGB(150,150,150))
DrawText(520,312,"16",#Black,RGB(150,150,150))
DrawText(550,312,"17",#Black,RGB(150,150,150))
DrawText(580,312,"18",#Black,RGB(150,150,150))
DrawText(610,312,"19",#Black,RGB(150,150,150))

DrawText(640,312,"20",#Black,RGB(150,150,150))
DrawText(670,312,"21",#Black,RGB(150,150,150))
DrawText(700,312,"22",#Black,RGB(150,150,150))
DrawText(730,312,"23",#Black,RGB(150,150,150))
DrawText(760,312,"24",#Black,RGB(150,150,150))
DrawText(790,312,"25",#Black,RGB(150,150,150))
DrawText(820,312,"26",#Black,RGB(150,150,150))
DrawText(850,312,"27",#Black,RGB(150,150,150))

    If Longeur_mois = 28 : DrawText(880,312,"28",#Black,RGB(150,150,150)) : Examine_Graphic_Dates(28)
ElseIf Longeur_mois = 29 : DrawText(880,312,"28",#Black,RGB(150,150,150)) : DrawText(910,312,"29",#Black,RGB(150,150,150)) : Examine_Graphic_Dates(29)
ElseIf Longeur_mois = 30 : DrawText(880,312,"28",#Black,RGB(150,150,150)) : DrawText(910,312,"29",#Black,RGB(150,150,150)) : DrawText(940,312,"30",#Black,RGB(150,150,150)) : Examine_Graphic_Dates(30)
ElseIf Longeur_mois = 31 : DrawText(880,312,"28",#Black,RGB(150,150,150)) : DrawText(910,312,"29",#Black,RGB(150,150,150)) : DrawText(940,312,"30",#Black,RGB(150,150,150)) : DrawText(970,312,"31",#Black,RGB(150,150,150)) : Examine_Graphic_Dates(31): EndIf

EndProcedure

Procedure Visualisation()
  Protected Long_Date_Graph.i,SinX1.i,SinY1.i,SinX2.i,SinY2.i,SinX3.i,SinY3.i
  
Select Val(Mois_Examen)
  Case 1, 3, 5, 7, 8, 10, 12 : Long = 31
  Case 4, 6, 9, 11: Long = 30
    
  Case 2    
  If Bissextile : Long = 29 : Else : Long = 28 : EndIf
  If  Mod(Val(Annee_Examen),4) = 0 : Bissextile = #True : Else : Bissextile = #False : EndIf  
EndSelect

  Date_De_NaissanceStr = ConversionDate(Val(Jour_De_Naissance),Val(Mois_De_Naissance),Val(Annee_De_Naissance))
  Date_ExamenStr       = ConversionDate(Val(Jour_Examen),Val(Mois_Examen), Val(Annee_Examen))
  
  Facteur_De_Naissance = Calcul_Facteur_Examen(Val(Jour_De_Naissance)-1,Val(Mois_De_Naissance),Val(Annee_De_Naissance))  
  Facteur_Examen = Calcul_Facteur_Examen(Val(Jour_Examen)-1, Val(Mois_Examen), Val(Annee_Examen))
  
  NB = Facteur_Examen - Facteur_De_Naissance ; Trunc
  Nombre_De_JourStr = Str(NB)

  Age = Val(Annee_De_Naissance) - Val(Annee_Examen)

      AgeStr = Str(Age)
Annee_Examen = Annee_Examen

Str = Str(Facteur_De_Naissance)
Facteur_ExamenStr = Str(Facteur_Examen)

StartDrawing(CanvasOutput(#Fenetre_1))       


TextGadget(#Text_10,260,50,600,20,"Le nombre de jours entre le " + Semaine(Facteur_De_Naissance) + " " +Date_De_NaissanceStr+ " Et le "+ Semaine(Facteur_Examen) + " " + Date_ExamenStr + " " + "est de : " + Nombre_De_JourStr +  " Jours à " +  Str(Abs(Age)) + " Ans en " + Annee_Examen)

Jour_Du_Mois(Long)

;***************************************{**************************Cycle Primaire*************************************************************************}
   PI = 3.14159265359

   ;{Cycle Primaire - Physique}   
   
   
    If Long = 28 : Long_Date_Graph = 844 : EndIf
    If Long = 29 : Long_Date_Graph = 874 : EndIf
    If Long = 30 : Long_Date_Graph = 904: EndIf
    If Long = 31 : Long_Date_Graph = 934 : EndIf 
    
    Phys = Sin(2*PI*NB/23)           
    For i = 1 To Long_Date_Graph
     Phys = Sin(2*PI*(NB+i/16)/23)
     LineXY(60,309,60+i,309-Round(Phys*150 ,#PB_Round_Down),#Blue)
    
    Next      
    

 ;{Cycle Primaire - Emotionnel}

 ;Emot = Sin(2*PI*NB/28) 
 ;For i = 1 To 124 
 ;   Emot = Sin(2*PI*(NB+i/4)/28)    
 ;   LineXY(64,170-Round(Emot*150,#PB_Round_Down),64+i*4, 170-Round(Emot*150,#PB_Round_Down),RGB(212, 115, 212))
 ; Next
  
 
 ;{Cycle Primaire - Intellectuel}
  
;Intel = Sin(2*PI*NB/33)
  
; For i = 1 To 62
;   Intel = Sin(2*PI*(NB+i/2)/33)
;   LineXY(64, 170-Round(Intel*150,#PB_Round_Down),64+i*8, 170-Round(Intel*150,#PB_Round_Down),#Cyan)
; Next

;{**************************Cycle Secondaire********************************}

 ;{Cycle Secondaire - Intuition}

 ;Intui = Sin(2*PI*NB/38);
 
 ;For i = 1 To 62 
 ;Intui = Sin(2*PI*(NB+i/2)/38)
 ;LineXY(64, 170-Round(Intui*150,#PB_Round_Down),64+i*8, 170-Round(Intui*150,#PB_Round_Down),RGB(150, 131, 236));Couleur Lavande
 ;Next
  
 ;{Cycle Secondaire - Spirituel}
 
 ;Spirit = Sin(2*PI*NB/52)         
 ;For i = 1 To 496
 ;  Spirit = Sin(2*PI*(NB+i/16)/52);
 ;  LineXY(20,400,64+i,170-Round(Spirit*150,#PB_Round_Down),RGB(115, 8, 0))
 ;  Next

 ;{Cycle Secondaire - Conscience}
   
  ; Crea = Sin(2*PI*NB/48);   
      
  ; For i = 1 To 124
  ;   Crea = Sin(2*PI*(NB+i/4)/48)     
  ;   LineXY(64, 170-Round(Crea*150,#PB_Round_Down),64+i*4, 170-Round(Crea*150,#PB_Round_Down),RGB(255, 0, 0))
  ; Next
   
 ;{Cycle Secondaire - Esthétique}   
 
 ; Esthe = Sin(2*PI*NB/43)
 
 ; For i = 1 To 62
 ; Esthe = Sin(2*PI*(NB+i/2)/43)   
 ; LineXY(64, 170-Round(Esthe*150,#PB_Round_Down),64+i*8, 170-Round(Esthe*150,#PB_Round_Down),RGB(0, 255, 0))   
 ; Next 
 
 StopDrawing()
 
EndProcedure

Procedure Presentation()  
  Protected iColor.i,iColor2.i
  
  OpenWindow(#Fenetre_1,100,0,1200,700,"Notysoft Riteme - Générateur de BIORYTHMES - 2017 - v1.00", #PB_Window_SystemMenu);| #PB_Window_ScreenCentered)  
  ;SetWindowColor(#Fenetre_1, RGB(220,220,220))                    
  
  CanvasGadget(#Fenetre_1,0,70,1200,700)   
  
  TextGadget(#Text_1,10,13,150,20,"Votre date de naissance (/) : ")
  TextGadget(#Text_2,10,33,150,20,"Votre date d''examen      (/) : ")      
  
  ;Légende
;Cycle Primaire

TextGadget(#Text_3,260,10,200,20,"Cycle Physique")
SetGadgetColor(#Text_3,#PB_Gadget_FrontColor,#Blue)

TextGadget(#Text_4,360,10,200,20,"Cycle Emotionnel") 
SetGadgetColor(#Text_4,#PB_Gadget_FrontColor,RGB(212, 115, 212))

TextGadget(#Text_5,472,10,200,20,"Cycle Intellectuel") 
SetGadgetColor(#Text_5,#PB_Gadget_FrontColor,#Cyan)

;Cycle Secondaire

TextGadget(#Text_6,580,10,200,20,"Cycle Intuition")
SetGadgetColor(#Text_6,#PB_Gadget_FrontColor,RGB(150, 131, 236))

TextGadget(#Text_7,260,30,200,20,"Cycle Spirituel")
SetGadgetColor(#Text_7,#PB_Gadget_FrontColor,RGB(115, 8, 0))

TextGadget(#Text_8,360,30,200,20,"Cycle Conscience")   
SetGadgetColor(#Text_8,#PB_Gadget_FrontColor,RGB(255, 0, 0))

TextGadget(#Text_9,472,30,200,20,"Cycle Esthétique")
SetGadgetColor(#Text_9,#PB_Gadget_FrontColor,RGB(0, 255, 0))

  StringGadget(#Date_De_Naissance,150,10,100,20,"")
  StringGadget(#Date_Examen      ,150,30,100,20,"")
  
For iColor = #Text_1 To #Text_2
  ;SetGadgetColor(iColor,#PB_Gadget_BackColor, RGB(220,220,220))        
  SetGadgetColor(iColor,#PB_Gadget_FrontColor,#Black)
Next

;For iColor2 = #Text_4 To #Text_10
;  SetGadgetColor(iColor2,#PB_Gadget_BackColor, RGB(220,220,220))        
;Next
  
SetGadgetColor(#Date_De_Naissance,#PB_Gadget_BackColor,RGB(245,222,179))
SetGadgetColor(#Date_Examen,#PB_Gadget_BackColor, RGB(245, 222, 179))


ButtonGadget(#A_Porpos,  10,50,102,20,"A Propos")   
ButtonGadget(#Bouton_OK,149,50,102,20,"GO !")   

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

StartDrawing(CanvasOutput(#Fenetre_1))    
Box(0,0,1200,700,RGB(150, 150, 150))

Jour_Du_Mois(30)

StopDrawing()
   
EndProcedure  

Procedure Open_A_Propos()
  Protected Gadget, iColorText.I 
 
  If OpenWindow(#Fenetre_a_propos,153,40,260,135, "Aide - A Propos", #PB_Window_TitleBar | #PB_Window_BorderLess | #PB_Window_ScreenCentered, WindowID(#Fenetre_1))           
    SetWindowColor(#Fenetre_a_propos, RGB(150,150,150))
   
    ButtonGadget(#Close_A_Porpos,105,90,50,30, "Ok") 
   
    TextGadget(#TextAPropos1,0, 10, 259, 29,"Notysoft Riteme - 2017 - v1.00",#PB_Text_Center)   
    TextGadget(#TextAPropos2,0, 30, 259, 29,"Générateur de BIORYTHMES ",#PB_Text_Center)
    TextGadget(#TextAPropos3,0, 50, 259, 29,"Écrit par Frédéric CHERPE - 2016 - 2017",#PB_Text_Center)
       
    For Gadget = #TextAPropos1 To #TextAPropos3
      SetGadgetColor(Gadget, #PB_Gadget_BackColor, RGB(150,150,150))       
      SetGadgetColor(Gadget, #PB_Gadget_FrontColor, RGB(255,255,255))
    Next   
    
    If LoadSound(#ID_Son_1,"Sons\back.wav")     
     PlaySound(#ID_Son_1)   
    EndIf  
    
  EndIf
EndProcedure
  
Repeat                   
    
  ;Visualisation(Ch)
  DateNaissance()
  DateExamen()
    
  glEvent = WaitWindowEvent()
  glGadget= EventGadget()
  glType = EventType()
 
   
If glEvent = #PB_Event_Gadget ; Événements des  Gadgets
  Select EventGadget()             

    Case #Bouton_OK
      DateNaissance()
      DateExamen()
      Visualisation()    
      
    Case #A_Porpos
      Open_A_Propos()
      
    Case #Close_A_Porpos
     CloseWindow(#Fenetre_a_propos)
  
EndSelect
  EndIf
    
Until glEvent = #PB_Event_CloseWindow
 
End
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Biorythmes - Problème pour dessiner une courbe

Message par falsam »

En lisant en diagonale il y a pas mal d'incohérence. Tu as un souci avec les définitions de variables.

■ Extrait de ton code

Code : Tout sélectionner

Global ... PI.l, NB.l
Global ... Phys.b 
...
PI = 3.14159265359
...

Phys = Sin(2*PI*NB/23)           
  For i = 1 To Long_Date_Graph
    Phys = Sin(2*PI*(NB+i/16)/23)
    LineXY(60,309,60+i,309-Round(Phys*150 ,#PB_Round_Down),#Blue)
    
  Next
...
PI NB et Phys ne seront jamais des variables décimanes.

Avec quelques debug tu aurais pu t'en rendre compte. Exemple avec ce code

Code : Tout sélectionner

PI.l = 3.14159265359
Debug PI
Il en est de même pour Phys et NB.

Ensuite j’espère que tu as compris que Repeat ..... Until glEvent = #PB_Event_CloseWindow est une boucle événementielle.

■ Dans cet extrait de code

Code : Tout sélectionner

Repeat                   
    
  ;Visualisation(Ch)
  DateNaissance()
  DateExamen()
    
Les procédures DateNaissance() et DateExamen() sont appelées en continue.

Avant de t'engager dans un tel code je pense qu'une reprise et un entrainement sur les bases de PureBasic serait un plus.

■ A mon avis tu n'as pas testé ce code

Code : Tout sélectionner

Phys = Sin(2*PI*NB/23)           
For i = 1 To Long_Date_Graph
Phys = Sin(2*PI*(NB+i/16)/23)
   LineXY(60,309,60+i,309-Round(Phys*150 ,#PB_Round_Down),#Blue)
Next
Tu te serais aperçu que la varuiable Phys est toujours égale à 0 et que LineXY ne traduit pas du tout l'instruction LineTo du langage Pascal.

:idea: LineTo dessine une ligne à partir de la position actuelle du pointeur vers un nouveau point (DX, DY).

Ce n'est pas ce que tu fais dans ton code.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Biorythmes - Problème pour dessiner une courbe

Message par falsam »

Au fait tu peux supprimer ta variable pi au profit de #PI :wink:
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Biorythmes - Problème pour dessiner une courbe

Message par falsam »

Je me suis lancé dans la traduction de ton code Pascal en PureBasic

Code : Tout sélectionner

;Phys := Sin(2*PI*NB/23);

;MoveTo(64, 170-Round(Phys*150));

;For i := 1 To 496 DO 
;BEGIN;
;Phys := Sin(2*PI*(NB+i/16)/23);
;LineTo(64+i, 170-Round(Phys*150));
;End;
Comme je te l'ai expliqué précédemment, l'instruction LineTo dessine une ligne à partir de la position actuelle du pointeur vers un nouveau point (DX, DY).

En PureBasic tu auras donc besoin de connaitre la position x & y de départ et la position x & y d'arrivée.

A chaque itération dans ta boucle For ... next, le point d'arrivée deviendra la position de départ et tu calculeras le nouveau point d'arrivée.

■ Le code

Code : Tout sélectionner

EnableExplicit 

Declare Start()
Declare Exit()

Start()

Procedure Start()
  Protected Phys.f, NB.f, i ;Note bien la déclaration des variable (f : Float)
  Static x1, y1 ;Point de départ
  Static x2, y2 ;Point d'arrivée
  
  OpenWindow(0, 0, 0, 800, 600, "Courbe sinusoidale", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 800, 600)    
  
  NB = 200
  
  ;Pascal
  ;Phys := Sin(2*PI*NB/23);
  Phys = Sin(2*#PI * NB/23) 
  
  ;Pascal 
  ;MoveTo(64, 170-Round(Phys*150));
  x1 = 64
  y1 = 170-Round(Phys * 150 ,#PB_Round_Down)
  
  StartDrawing(CanvasOutput(0))
  
  ;Pascal
  ;For i := 1 To 496 DO 
  ;BEGIN;
  ;Phys := Sin(2*PI*(NB+i/16)/23);
  ;LineTo(64+i, 170-Round(Phys*150));
  ;End;
  
  For i = 1 To 496
    Phys = Sin(2*#PI * (NB+i/16)/23)
    Debug Phys
    
    ;Calcul du point d'arrivée 
    x2 = 64 + i
    y2 = 170-Round(Phys * 150 ,#PB_Round_Down)
    
    ;Dessin de la ligne
    LineXY(x1, y1, x2, y2, #Blue)
    
    ;Permutation des données
    ;Le point de d'arrivée calculé précédement devient le point de départ
    ;X0 et y0 sont remplacés par x1 et y1
    x1 = x2
    y1 = y2
  Next
  StopDrawing()
  
  ;Triggers
  BindEvent(#PB_Event_CloseWindow, @Exit())
  
  Repeat : WaitWindowEvent() : ForEver
EndProcedure

Procedure Exit()  
  End
EndProcedure
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
PCPixMusic
Messages : 106
Inscription : ven. 06/janv./2017 9:50

Re: Biorythmes - Problème pour dessiner une courbe

Message par PCPixMusic »

Merci beaucoup.

Pour PI, Phys et NB, c'est en Real en Pascal, mais je ne savais pas pour .f Float
Ensuite j’espère que tu as compris que Repeat ..... Until glEvent = #PB_Event_CloseWindow est une boucle événementielle.
Les procédures DateNaissance() et DateExamen() sont appelées en continue.
Bien sûr, ce là fait six mois que je m'en sers, mais je me suis en effet trompé en copiant le code d'origine.
LineTo dessine une ligne à partir de la position actuelle du pointeur vers un nouveau point (DX, DY).
Ce n'est pas ce que tu fais dans ton code
Je n'arrivais pas à trouver d'équivalent, j'ai fait au mieux en attendant. :oops:
Au fait tu peux supprimer ta variable pi au profit de #PI :wink:
Merci, je ne savais pas que c'était possible en PureBasic pour la constante #Pi

Tu as codé de façon tellement simple, ce que j'avais pensé trop compliquer. :mrgreen:
Répondre