Un petit programme qui ne sert à rien mais qui peut aider les débutants en pure.

Il est assez facile à comprendre et en plus il est très court. Mais le résultat est assez bon, bien que je n'arrive pas a éviter le scintillement de l'écran lorsqu'on bouge les curseurs. Bon c'est peut-être mal programmé ou quelque chose m'échappe.

Le scintillement est encore plus visible si l'on met le font de l'affichage de l'oscilloscope en noir.
J'avais vu ce programme écrit en RealBasic et je me suis amusé à le transcrire en PureBasic. Rien de tel pour apprendre.

Code : Tout sélectionner
;/ Created with PureVisionXP v2.13
;/ Sun, 28 Aug 2005 21:09:01
;/ Adaptation d'un programme en RealBasic by Good07
;-Global Variables and Constants
Global BubbleTipStyle.l:BubbleTipStyle=0
Global width,height,Grille_Flag.b
;-Window Constants
Enumeration 1
#Window_Form1
EndEnumeration
#WindowIndex=#PB_Compiler_EnumerationValue
;-Gadget Constants
Enumeration 1
;Window_Form1
#Gadget_Form1_Image4
#Gadget_Form1_Amplitude
#Gadget_Form1_HoriOffset
#Gadget_Form1_VertOffset
#Gadget_Form1_Frequence
#Gadget_Form1_Grille
#Gadget_Form1_UseGrid
#Gadget_Form1_Reset
#Gadget_Form1_Frame3D10
#Gadget_Form1_Text11
#Gadget_Form1_Text12
#Gadget_Form1_Text13
#Gadget_Form1_Text14
#Gadget_Form1_Text15
#Ecran
EndEnumeration
#GadgetIndex=#PB_Compiler_EnumerationValue
Grille_Flag=1
CreateImage(#Ecran,550,300)
Procedure.l Window_Form1()
If OpenWindow(#Window_Form1,274,161,590,460,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible,"Oscilloscope")
If CreateGadgetList(WindowID(#Window_Form1))
ImageGadget(#Gadget_Form1_Image4,20,10,550,300,0)
TrackBarGadget(#Gadget_Form1_Amplitude,185,365,194,16,0,390)
SetGadgetState(#Gadget_Form1_Amplitude,100)
TrackBarGadget(#Gadget_Form1_HoriOffset,397,365,151,16,0,300)
SetGadgetState(#Gadget_Form1_HoriOffset,0)
TrackBarGadget(#Gadget_Form1_VertOffset,397,405,151,16,0,300)
SetGadgetState(#Gadget_Form1_VertOffset,150)
TrackBarGadget(#Gadget_Form1_Frequence,185,405,194,16,0,300)
SetGadgetState(#Gadget_Form1_Frequence,50)
TrackBarGadget(#Gadget_Form1_Grille,27,405,150,20,10,50)
SetGadgetState(#Gadget_Form1_Grille,20)
CheckBoxGadget(#Gadget_Form1_UseGrid,90,375,80,20,"Grille")
SetGadgetState(#Gadget_Form1_UseGrid,1)
ButtonGadget(#Gadget_Form1_Reset,30,345,135,20,"Reset Valeurs")
Frame3DGadget(#Gadget_Form1_Frame3D10,20,320,555,114,"Controles")
TextGadget(#Gadget_Form1_Text11,185,350,71,12,"Amplitude")
TextGadget(#Gadget_Form1_Text12,397,350,116,12,"Horizontal Offset")
TextGadget(#Gadget_Form1_Text13,397,390,114,12,"Vertical Offset")
TextGadget(#Gadget_Form1_Text14,185,390,89,12,"Fréquence")
TextGadget(#Gadget_Form1_Text15,27,390,60,12,"Dim Grille")
HideWindow(#Window_Form1,0)
ProcedureReturn WindowID()
EndIf
EndIf
EndProcedure
Procedure DrawGrille()
StartDrawing(ImageOutput())
If Grille_Flag=0
Box(0,0,width,height,RGB(255,255,255))
Else
widthSquares =GetGadgetState(#Gadget_Form1_Grille)
xvalue=0
yvalue=height/2
Box(0,0,width,height,RGB(255,255,255))
LineXY(xvalue,yvalue,width,yvalue,RGB(0,0,255))
While yvalue > 0
yvalue = yvalue - widthSquares
LineXY(xvalue,yvalue, width, yvalue,RGB(255,0,0))
Wend
yvalue=height/2
While yvalue < height
yvalue = yvalue + widthSquares
LineXY(xvalue,yvalue, width, yvalue,RGB(255,0,0))
Wend
yvalue = 0
xvalue = 0
While xvalue < width
LineXY(xvalue, yvalue, xvalue, height,RGB(255,0,0))
xvalue = xvalue + widthSquares
Wend
EndIf
StopDrawing()
EndProcedure
Procedure DrawSinusWave()
StartDrawing(ImageOutput())
#PI = 3.141592
#D2R = 0.01745329
amp.f =GetGadgetState(#Gadget_Form1_Amplitude)
freq.f = GetGadgetState(#Gadget_Form1_Frequence) * #D2R/10
hor = GetGadgetState(#Gadget_Form1_HoriOffset)
ver = GetGadgetState(#Gadget_Form1_VertOffset)
lastY.f = 0
For x = 0 To width
y.f = -amp * (Sin((x - hor) * freq)) + ver
LineXY( x - 1, lastY.f, x, y,RGB(0,0,0))
lastY.f = y
Next
StopDrawing()
EndProcedure
;-Main Loop
If Window_Form1()
quitForm1=0
width=550
height=300
quitForm1=0
DrawGrille()
DrawSinusWave()
;drawSquare()
ImageGadget(#Gadget_Form1_Image4,20,10,550,300,UseImage(#Ecran),#PB_Image_Border)
Repeat
EventID =WaitWindowEvent()
MenuID =EventMenuID()
GadgetID =EventGadgetID()
WindowID =EventWindowID()
Select EventID
Case #PB_Event_CloseWindow
If WindowID=#Window_Form1
quitForm1=1
EndIf
Case #PB_Event_Gadget
Select GadgetID
Case #Gadget_Form1_Image4
Select EventType()
Case #PB_EventType_LeftDoubleClick
Case #PB_EventType_RightDoubleClick
Case #PB_EventType_RightClick
Default
EndSelect
Case #Gadget_Form1_Amplitude
DrawGrille()
DrawSinusWave()
ImageGadget(#Gadget_Form1_Image4,20,10,550,300,UseImage(#Ecran),#PB_Image_Border)
Case #Gadget_Form1_HoriOffset
DrawGrille()
DrawSinusWave()
ImageGadget(#Gadget_Form1_Image4,20,10,550,300,UseImage(#Ecran),#PB_Image_Border)
Case #Gadget_Form1_VertOffset
DrawGrille()
DrawSinusWave()
ImageGadget(#Gadget_Form1_Image4,20,10,550,300,UseImage(#Ecran),#PB_Image_Border)
Case #Gadget_Form1_Frequence
DrawGrille()
DrawSinusWave()
ImageGadget(#Gadget_Form1_Image4,20,10,550,300,UseImage(#Ecran),#PB_Image_Border)
Case #Gadget_Form1_Grille
DrawGrille()
DrawSinusWave()
ImageGadget(#Gadget_Form1_Image4,20,10,550,300,UseImage(#Ecran),#PB_Image_Border)
Case #Gadget_Form1_UseGrid
Grille_Flag=GetGadgetState(#Gadget_Form1_UseGrid)
DrawGrille()
DrawSinusWave()
ImageGadget(#Gadget_Form1_Image4,20,10,550,300,UseImage(#Ecran),#PB_Image_Border)
Case #Gadget_Form1_Reset
SetGadgetState(#Gadget_Form1_Amplitude,100)
SetGadgetState(#Gadget_Form1_HoriOffset,0)
SetGadgetState(#Gadget_Form1_VertOffset,150)
SetGadgetState(#Gadget_Form1_Frequence,50)
SetGadgetState(#Gadget_Form1_Grille,20)
DrawGrille()
DrawSinusWave()
ImageGadget(#Gadget_Form1_Image4,20,10,550,300,UseImage(#Ecran),#PB_Image_Border)
EndSelect
EndSelect
Until quitForm1
CloseWindow(#Window_Form1)
EndIf
End
Bonjour chez vous.
André.
