Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Continuously Moving Curve Display

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin Continuously Moving Curve Display

    ' Here is a small program showing a continuously moving display of curves.
    ' This may be useful for monitoring any real time data.
    '
    ' Rest regards, Erik

    Code:
    ' Here is a small program showing a continuously moving display of curves.
    ' This may be useful for monitoring any real time data.
    '
    ' Rest regards, Erik
    
    #COMPILE EXE
    #DIM ALL
    '
    #INCLUDE ONCE "WIN32API.INC"
    #INCLUDE ONCE "COMMCTRL.INC"
    '
    %IDD_DIALOG1      =  101
    %IDC_GRAPHIC1     = 1001
    %IDC_BUTTON1_EXIT = 1002
    %IDC_BUTTON1_STRT = 1003
    %IDC_BUTTON1_STOP = 1004
    %IDC_TIMER1       = 1005
    '
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        STATIC hTimer, TimerInterval AS LONG
        STATIC i, j, k, WidthVar, HeightVar, Xstep AS LONG
        STATIC StationaryXpos, yPosRed, yPosBlue, yPosGreen AS SINGLE
        STATIC prevYposRed, prevYposBlue, prevYposGreen AS SINGLE
        STATIC xRightSpace AS LONG
    
        SELECT CASE AS LONG CB.MSG
            CASE %WM_INITDIALOG
                ' Initialization handler
                TimerInterval = 20 ' in microseconds - can be changed
                GRAPHIC GET SIZE TO WidthVar, HeightVar
    
                Xstep = 2 ' number of pixels moving to the left per time inteval
                GRAPHIC WIDTH Xstep
    
                xRightSpace = 50 ' blank space on right side of curves in pixels - can be changed
                StationaryXpos = WidthVar - xRightSpace
    
                RANDOMIZE TIMER
                yPosRed = RND(2, HeightVar - 2)
                yPosBlue = RND(2, HeightVar - 2)
                yPosGreen = RND(2, HeightVar - 2)
                prevYposRed = yPosRed
                prevYposBlue = yPosBlue
                prevYposGreen = yPosGreen
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CB.WPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CB.CTL
                    CASE %IDC_BUTTON1_EXIT
                        IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN DIALOG END CB.HNDL
    
                    CASE %IDC_BUTTON1_STRT
                        IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                            hTimer = SetTimer(CB.HNDL, BYVAL %IDC_TIMER1, BYVAL TimerInterval, BYVAL %NULL)
                            RANDOMIZE TIMER
                        END IF
    
                    CASE %IDC_BUTTON1_STOP
                        IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN KillTimer CB.HNDL, %IDC_TIMER1
    
                END SELECT
            CASE %WM_TIMER
                SELECT CASE AS LONG CB.WPARAM
                    CASE %IDC_TIMER1
                        KillTimer CB.HNDL, %IDC_TIMER1
    
                        GRAPHIC COPY CB.HNDL, %IDC_GRAPHIC1, (Xstep + 1, 1)-(WidthVar - xRightSpace, HeightVar) TO (1, 1)
                        GRAPHIC LINE (WidthVar - xRightSpace, 1) - (WidthVar - xRightSpace, HeightVar), %WHITE ' erase previous points
    
                        yPosRed = yPosRed + RND(2,8) * SGN(RND(-yPosRed+2, HeightVar-2-yPosRed)) + 3         ' You can exchange these
                        yPosBlue = yPosBlue + RND(2,8) * SGN(RND(-yPosBlue+2, HeightVar-2-yPosBlue))         ' random functions with
                        yPosGreen = yPosGreen + RND(2,8) * SGN(RND(-yPosGreen+2, HeightVar-2-yPosGreen)) - 3 ' any real time measurements
    
                        GRAPHIC LINE (StationaryXpos - Xstep, prevYposRed) - (StationaryXpos, yPosRed), %RED
                        GRAPHIC LINE (StationaryXpos - Xstep, prevYposBlue) - (StationaryXpos, yPosBlue), %BLUE
                        GRAPHIC LINE (StationaryXpos - Xstep, prevYposGreen) - (StationaryXpos, yPosGreen), %RGB_GREEN
    
                        prevYposRed = yPosRed
                        prevYposBlue = yPosBlue
                        prevYposGreen = yPosGreen
    
                        hTimer = SetTimer(CB.HNDL, BYVAL %IDC_TIMER1, BYVAL TimerInterval, BYVAL %NULL)
                END SELECT
        END SELECT
    END FUNCTION
    '
    FUNCTION PBMAIN()
        LOCAL lRslt AS LONG
        LOCAL hDlg  AS DWORD
    
        DIALOG NEW PIXELS, %HWND_DESKTOP, "Continuously Moving Curve Display", , _
            , 543, 382, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR _
            %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR _
            %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
            %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
            %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1, "", 8, 8, 528, 336, %WS_CHILD _
            OR %WS_VISIBLE, %WS_EX_CLIENTEDGE
        GRAPHIC ATTACH hDlg, %IDC_GRAPHIC1
        GRAPHIC COLOR -1, %WHITE
        GRAPHIC CLEAR
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1_EXIT, "E&xit", 456, 352, 80, 24
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1_STRT, "&Start", 8, 352, 112, 24
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1_STOP, "St&op", 128, 352, 112, 24
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
        FUNCTION = lRslt
    END FUNCTION
    Attached Files

  • #2
    Continuously Moving Curve Display - version 2

    ' Continuously Moving Curve Display - version 2
    '
    ' In this version the canvas - on which the curve is drawn -
    ' moves up and down. The latest point is always at the same screen location.
    ' The plot still moves horizontally at your defined rate.
    '
    ' This version allows even markedly fluctuating curves to be
    ' displayed in real time as the plot always adapts to the
    ' latest point of the curve.
    '
    ' Rest regards, Erik

    Code:
    ' Continuously Moving Curve Display - version 2
    '
    ' In this version the canvas - on which the curve is drawn -
    ' moves up and down. The latest point is always at the same screen location.
    ' The plot still moves horizontally at your defined rate.
    '
    ' This version allows even markedly fluctuating curves to be
    ' displayed in real time as the plot always adapts to the
    ' latest point of the curve.
    '
    ' Rest regards, Erik
    
    #COMPILE EXE
    #DIM ALL
    '
    #INCLUDE ONCE "WIN32API.INC"
    #INCLUDE ONCE "COMMCTRL.INC"
    '
    %IDD_DIALOG1      =  101
    %IDC_GRAPHIC1     = 1001
    %IDC_BUTTON1_EXIT = 1002
    %IDC_BUTTON1_STRT = 1003
    %IDC_BUTTON1_STOP = 1004
    %IDC_TIMER1       = 1005
    %IDC_TEXTBOX1     = 1006
    '
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        STATIC hTimer, TimerInterval AS LONG
        STATIC WidthVar, HeightVar, Xstep AS LONG
        STATIC StationaryXpos, stationaryMiddleYpos, yMove AS SINGLE
        STATIC prevyPos AS SINGLE
        STATIC xRightSpace AS LONG
        STATIC SinStep AS DOUBLE
        STATIC yNewTop, yOldTop AS SINGLE
        STATIC yPrevMove AS SINGLE
        STATIC TotalYvalShift, TotalYgraphShift AS SINGLE
        STATIC TimeElapsed AS SINGLE
    
        SELECT CASE AS LONG CB.MSG
            CASE %WM_INITDIALOG
                ' Initialization handler
                TimerInterval = 20 ' in microseconds - can be changed
                GRAPHIC GET SIZE TO WidthVar, HeightVar
                Xstep = 2 ' number of pixels moving to the left per time inteval
                GRAPHIC WIDTH Xstep
                xRightSpace = 50 ' blank space on right side of curves in pixels - can be changed
                StationaryXpos = WidthVar - xRightSpace
                stationaryMiddleYpos = HeightVar * 0.5 ' the latest y position stays in the middle of the plot
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CB.WPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CB.CTL
                    CASE %IDC_BUTTON1_EXIT
                        IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN : KillTimer CB.HNDL, %IDC_TIMER1 : DIALOG END CB.HNDL
    
                    CASE %IDC_BUTTON1_STRT
                        IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                            hTimer = SetTimer(CB.HNDL, BYVAL %IDC_TIMER1, BYVAL TimerInterval, BYVAL %NULL)
                        END IF
    
                    CASE %IDC_BUTTON1_STOP
                        IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN KillTimer CB.HNDL, %IDC_TIMER1
    
                END SELECT
            CASE %WM_TIMER
                SELECT CASE AS LONG CB.WPARAM
                    CASE %IDC_TIMER1
                        hTimer = SetTimer(CB.HNDL, BYVAL %IDC_TIMER1, BYVAL TimerInterval, BYVAL %NULL)
                        TimeElapsed = TimeElapsed + TimerInterval
                        SinStep = SinStep + 0.003141592653589793 * 4
                        IF SinStep > 3.141592653589793 * 2 THEN SinStep = 0.0 ' 2 PI
                        yMove = ROUND( SIN(SinStep)*80 + SIN(SinStep * 3)*40 + SIN(SinStep * 7)*12 , 0) ' An arbitrary function used for illustration
                                                                                                        ' Can be replaced by nny real time variable
    
                        yMove = -1.0 * yMove ' this CORRECTION OF SIGN is made to make HIGHER Y-values move UPWARDS - for the plot to reflect real life
    
                        IF yMove > yPrevMove THEN          ' Y is increasing (moving DOWN !!) --> previous part of plot should move UP
                            yOldTop = yMove - yPrevMove    ' used in GRAPHIC COPY to move previously produced part of plot UP
                            yNewTop = 0
                            yPrevMove = yMove              ' update to new value
    
                        ELSEIF yMove < yPrevMove THEN      ' Y is decreasing (moving UP !!) --> previous part of plot should move DOWN
                            yNewTop = yPrevMove - yMove    ' used in GRAPHIC COPY to move previously produced part of plot DOWN
                            yOldTop = 0
                            yPrevMove = yMove              ' update to new value
    
                        ELSE
                            yOldTop = 0 : yNewTop = 0      ' no upward or downward movement of plot should be made
                        END IF
    
                        CONTROL SET TEXT CB.HNDL, %IDC_TEXTBOX1, " Seconds = "+FORMAT$((TimeElapsed*0.001),"###.00") +"   Y-value = "+ STR$(-yMove) ' negative sign is used make positive values move upwards
    
                                                            ' upper left corner          lower right corner                     new position of upper left corner
                        GRAPHIC COPY CB.HNDL, %IDC_GRAPHIC1, (Xstep + 1, yOldTop + 1) - (WidthVar - xRightSpace, HeightVar) TO (1, yNewTop + 1)
    
                        IF yOldTop > 0 THEN                 ' upward movement: clear lowest part of plot
                            GRAPHIC BOX (1, HeightVar - yOldTop - 3) - (WidthVar-Xstep, HeightVar), , %WHITE, %WHITE
                            prevyPos = stationaryMiddleYpos - yOldTop
                        ELSEIF yNewTop > 0 THEN             ' downward movement: clear uppermost part of plot
                            GRAPHIC BOX (1, 1) - (WidthVar-Xstep, yNewTop + 1), , %WHITE, %WHITE
                            prevyPos = stationaryMiddleYpos + yNewTop
                        ELSE
                            prevyPos = stationaryMiddleYpos
                        END IF
    
                        GRAPHIC LINE (WidthVar - xRightSpace, 1) - (WidthVar - xRightSpace, HeightVar), %WHITE          ' erase previous latest line piece
                        GRAPHIC LINE (StationaryXpos - Xstep, prevyPos) - (StationaryXpos, stationaryMiddleYpos), %RED  ' draw new latest part of line
    
                END SELECT
        END SELECT
    END FUNCTION
    '
    FUNCTION PBMAIN()
        LOCAL lRslt AS LONG
        LOCAL hDlg  AS DWORD
    
        DIALOG NEW PIXELS, %HWND_DESKTOP, "Continuously Moving Curve Display With Sliding Background in Two Dimensions", , _
            , 543, 382, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR _
            %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR _
            %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
            %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
            %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1, "", 8, 8, 528, 336, %WS_CHILD _
            OR %WS_VISIBLE, %WS_EX_CLIENTEDGE
        GRAPHIC ATTACH hDlg, %IDC_GRAPHIC1
        GRAPHIC COLOR -1, %WHITE
        GRAPHIC CLEAR
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1_EXIT, "E&xit", 456, 352, 80, 24
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1_STRT, "&Start", 8, 352, 112, 24
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1_STOP, "St&op", 128, 352, 112, 24
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "",250, 352, 180, 24
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
        FUNCTION = lRslt
    END FUNCTION
    Attached Files
    Last edited by Erik Christensen; 23 Oct 2014, 10:55 AM.

    Comment


    • #3
      Continuously Moving Curve Display - version 3

      ' Continuously Moving Curve Display - version 3
      '
      ' In this version both the canvas - on which the curve is drawn -
      ' and the latest point can independently move vertically up and
      ' down as the whole plot moves horizontally at your defined rate.
      '
      ' This version allows markedly fluctuating curves to be
      ' displayed to a greater extent in real time as the plot
      ' always adapts to the latest point of the curve.
      '
      ' I think this third version is the best.
      '
      ' Rest regards, Erik
      '
      ' P.S. Inspired by Frank Kestens' comment in the following post
      ' I have improved the code slightly. I hope you like it.

      Code:
      ' Continuously Moving Curve Display - version 3
      '
      ' In this version both the canvas - on which the curve is drawn -
      ' and the latest point can independently move vertically up and
      ' down as the whole plot moves horizontally at your defined rate.
      '
      ' This version allows markedly fluctuating curves to be
      ' displayed to a greater extent in real time as the plot
      ' always adapts to the latest point of the curve.
      '
      ' I think this third version is the best.
      '
      ' Rest regards, Erik
      '
      ' P.S. Inspired by Frank Kestens' comment in the following post
      ' I have improved the code slightly. I hope you like it. :)
      
      #COMPILE EXE
      #DIM ALL
      '
      #INCLUDE ONCE "WIN32API.INC"
      #INCLUDE ONCE "COMMCTRL.INC"
      '
      %IDD_DIALOG1      =  101
      %IDC_GRAPHIC1     = 1001
      %IDC_BUTTON1_EXIT = 1002
      %IDC_BUTTON1_STRT = 1003
      %IDC_BUTTON1_STOP = 1004
      %IDC_TIMER1       = 1005
      %IDC_TEXTBOX1     = 1006
      '
      CALLBACK FUNCTION ShowDIALOG1Proc()
      
          STATIC hTimer, TimerInterval AS LONG
          STATIC WidthVar, HeightVar, Xstep AS LONG
          STATIC StationaryXpos, CurrentScreenYpos AS SINGLE
          STATIC yMove, yPrevMove AS SINGLE
          STATIC prevYpos AS SINGLE
          STATIC xRightSpace AS LONG
          STATIC SinStep AS DOUBLE
          STATIC yNewTop, yOldTop AS SINGLE
          STATIC TimeElapsed AS SINGLE
          STATIC YposUpLimit, YposDownLimit AS SINGLE
          STATIC Ystep AS SINGLE
      
          SELECT CASE AS LONG CB.MSG
              CASE %WM_INITDIALOG
                  ' Initialization handler
                  TimerInterval = 20                                  ' in microseconds - can be changed
                  GRAPHIC GET SIZE TO WidthVar, HeightVar
                  Xstep = 2                                           ' number of pixels moving to the left per time inteval
                  GRAPHIC WIDTH Xstep
                  xRightSpace = 15                                    ' blank space on right side of curves in pixels - can be changed
                  StationaryXpos = WidthVar - xRightSpace
                  CurrentScreenYpos = HeightVar * 0.5                 ' start y position in the middle of the plot
                  prevYpos =  CurrentScreenYpos
                  YposUpLimit = 10 : YposDownLimit = HeightVar - 10   ' upper and lower limit for latest Y-position on the screen - can be changed
      
              CASE %WM_NCACTIVATE
                  STATIC hWndSaveFocus AS DWORD
                  IF ISFALSE CB.WPARAM THEN
                      ' Save control focus
                      hWndSaveFocus = GetFocus()
                  ELSEIF hWndSaveFocus THEN
                      ' Restore control focus
                      SetFocus(hWndSaveFocus)
                      hWndSaveFocus = 0
                  END IF
      
              CASE %WM_COMMAND
                  ' Process control notifications
                  SELECT CASE AS LONG CB.CTL
                      CASE %IDC_BUTTON1_EXIT
                          IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN : KillTimer CB.HNDL, %IDC_TIMER1 : DIALOG END CB.HNDL
      
                      CASE %IDC_BUTTON1_STRT
                          IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                              hTimer = SetTimer(CB.HNDL, BYVAL %IDC_TIMER1, BYVAL TimerInterval, BYVAL %NULL)
                          END IF
      
                      CASE %IDC_BUTTON1_STOP
                          IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN KillTimer CB.HNDL, %IDC_TIMER1
      
                  END SELECT
              CASE %WM_TIMER
                  SELECT CASE AS LONG CB.WPARAM
                      CASE %IDC_TIMER1
                          hTimer = SetTimer(CB.HNDL, BYVAL %IDC_TIMER1, BYVAL TimerInterval, BYVAL %NULL)
                          TimeElapsed = TimeElapsed + TimerInterval
                          SinStep = SinStep + 0.003141592653589793 * 4
                          IF SinStep > 3.141592653589793 * 2 THEN SinStep = 0.0 ' 2 PI
      
                          yMove = ROUND( SIN(SinStep)*160 + SIN(SinStep * 3)*100 + SIN(SinStep * 7)*80 , 0)    ' An arbitrary function used for illustration
                                                                                                               ' Can be replaced by nny real time variable
                          ' yMove = ROUND( SIN(SinStep)*160 + SIN(SinStep * 3)*100 + SIN(SinStep*Sinstep * 9)*80 , 0) ' Frank Kestens' function - see next post
      
                          yMove = -1.0 * yMove ' this CORRECTION OF SIGN is made to make HIGHER Y-values move UPWARDS - for the plot to reflect real life
      
                          IF yMove > yPrevMove THEN                                                        ' Y is increasing (i.e  moving DOWN !!)
      
                              Ystep = yMove - yPrevMove
      
                              IF CurrentScreenYpos + Ystep <= YposDownLimit THEN                           ' The Y screen position can move DOWN - and no scrolling is necessary
                                  yOldTop = 0 : yNewTop = 0
                                  CurrentScreenYpos = CurrentScreenYpos + Ystep
      
                              ELSE                                                                         ' Some scrolling UP is also needed
      
                                  yOldTop = CurrentScreenYpos + Ystep - YposDownLimit : yNewTop = 0        ' used in GRAPHIC COPY to move previously produced part of plot UP
                                  CurrentScreenYpos = YposDownLimit
                              END IF
      
                          ELSEIF yMove < yPrevMove THEN                                                    ' Y is decreasing (i.e. moving UP !!)
      
                              Ystep = yPrevMove - yMove
      
                              IF CurrentScreenYpos - Ystep >= YposUpLimit THEN                             ' The Y screen position can move UP - and no scrolling is necessary
                                  CurrentScreenYpos = CurrentScreenYpos - Ystep
                                  yOldTop = 0 : yNewTop = 0
      
                              ELSE                                                                         ' Some scrolling DOWN is also needed
      
                                  yNewTop = YposUpLimit + Ystep - CurrentScreenYpos : yOldTop = 0          ' used in GRAPHIC COPY to move previously produced part of plot DOWN
                                  CurrentScreenYpos = YposUpLimit
                              END IF
      
                          ELSE
                              yOldTop = 0 : yNewTop = 0                                                    ' no upward or downward movement of plot should be made
                          END IF
      
                          yPrevMove = yMove                                                                ' update to new value
      
                                                              ' upper left corner          lower right corner                     new position of upper left corner
                          GRAPHIC COPY CB.HNDL, %IDC_GRAPHIC1, (Xstep + 1, yOldTop + 1) - (WidthVar - xRightSpace, HeightVar) TO (1, yNewTop + 1)
      
                          GRAPHIC LINE (WidthVar - xRightSpace, 1) - (WidthVar - xRightSpace, HeightVar), %WHITE           ' erase previous latest line piece
      
                          IF yOldTop > 0 THEN                                                                              ' upward movement: clear lowest part of plot
                              GRAPHIC BOX (1, HeightVar - yOldTop - 3) - (WidthVar-Xstep, HeightVar), , %WHITE, %WHITE
                              prevYpos = prevYpos - yOldTop                                                                ' move the previous y position to draw latest part of line correctly
      
                              GRAPHIC LINE (StationaryXpos - Xstep, prevYpos) - (StationaryXpos, CurrentScreenYpos), %RED  ' draw new latest part of line
      
                          ELSEIF yNewTop > 0 THEN                                                                          ' downward movement: clear uppermost part of plot
                              GRAPHIC BOX (1, 1) - (WidthVar-Xstep, yNewTop + 1), , %WHITE, %WHITE
                              prevYpos = prevYpos + yNewTop                                                                ' move the previous y position to draw latest part of line correctly
      
                              GRAPHIC LINE (StationaryXpos - Xstep, prevYpos) - (StationaryXpos, CurrentScreenYpos), %RED  ' draw new latest part of line
      
                          ELSE                                                                                             ' no vertical movement of plot - only latest Y position is moving up or down
                              GRAPHIC LINE (StationaryXpos - Xstep, prevYpos) - (StationaryXpos, CurrentScreenYpos), %RED  ' draw new latest part of line
      
                          END IF
      
                          prevYpos = CurrentScreenYpos                                                                     ' update the previous y position
      
                          CONTROL SET TEXT CB.HNDL, %IDC_TEXTBOX1, " Seconds = "+FORMAT$((TimeElapsed*0.001),"###.00") +"   Y-value = "+ STR$(-yMove) ' negative sign is used make positive values move upwards
      
                  END SELECT
          END SELECT
      END FUNCTION
      '
      FUNCTION PBMAIN()
          LOCAL lRslt AS LONG
          LOCAL hDlg  AS DWORD
      
          DIALOG NEW PIXELS, %HWND_DESKTOP, "Continuously Moving Curve Display With Sliding Background in Two Dimensions", , _
              , 543, 382, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR _
              %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR _
              %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
              %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
              %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
          CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1, "", 8, 8, 528, 336, %WS_CHILD _
              OR %WS_VISIBLE, %WS_EX_CLIENTEDGE
          GRAPHIC ATTACH hDlg, %IDC_GRAPHIC1
          GRAPHIC COLOR -1, %WHITE
          GRAPHIC CLEAR
          CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1_EXIT, "E&xit", 456, 352, 80, 24
          CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1_STRT, "&Start", 8, 352, 112, 24
          CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1_STOP, "St&op", 128, 352, 112, 24
          CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "",250, 352, 180, 24
      
          DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
      
          FUNCTION = lRslt
      END FUNCTION
      Attached Files
      Last edited by Erik Christensen; 25 Oct 2014, 06:35 PM. Reason: Slight improvement

      Comment


      • #4
        Nicely done Erik ,
        The window even keeps up with a "wild" function in sin(step^2) as edited here !

        yMove = ROUND( SIN(SinStep)*160 + SIN(SinStep * 3)*100 + SIN(SinStep*Sinstep * 9)*80 , 0)

        Comment


        • #5
          Frank,

          Thanks for your comment which led to a slight improvement of the code.

          Your wildly fluctuating function shows even better now.

          Comment

          Working...
          X