Author Topic: Plotting data  (Read 1037 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Plotting data
« on: November 28, 2018, 11:06:28 PM »


The source (requires the Masm32 SDK plus the MasmBasic library):

  GuiParas equ "Plot sinus & cosinus curves", x600, y100, w600, h500, bRgbCol(192, 255, 255)
  include \masm32\MasmBasic\Res\MbGui.asm
  Dim MySinus() As REAL4                       ; REAL4 precision is enough ...
  Dim MyCosinus() As REAL8                     ; ... but REAL8 is ok, too
  For_ ecx=0 To 359
        SetFloat MySinus(ecx)=Sinus(ecx)       ; fill an array
        SetFloat MyCosinus(ecx)=Cosinus(ecx)   ; you may use ArrayRead for reading data from a file
  Next
  MakeFont hHorzFont, Height:18, Weight:FW_SEMIBOLD, Italic:TRUE
  MakeFont hVertFont, Height:18, Weight:FW_SEMIBOLD, Escapement:900, Italic:FALSE
  MakePen hPenAxis, RgbCol(255, 0, 0)
  MakePen hPenGrid, RgbCol(255, 255, 222), width 2
  SetAxisX "degrees", s 0, d 15.0/3, grid 1, penx hPenAxis, peng hPenGrid, font hHorzFont, format "%i" ; s=start value, d=difference between gridlines
  SetAxisY "sinus & cosinus", s -1, d 0.2/5, grid 2, font hVertFont, format "%2f"
  $Data "Plotting an array of points is very easy: All you need is the array itself, plus a Paint event that draws it."
  $Data "The axes can be set using SetAxisX and SetAxisY, taking arguments as shown in the source. Now resize this window to see how it behaves"
  Read desc$()                          ; read a string array from $Data
  Event Paint
  ArrayPlot MySinus(), RgbCol(255, 222, 160), 2, 00000110h, 0, -1, 1    ; red sinus, 2px wide; use margins left top right bottom, min0, max-1, filled=1
  ArrayPlot MyCosinus(), RgbCol(0, 0, 255)             ; plot the cosinus array in blue, same margins as previous plot
  ArrayPlot exit, 0150006028# "Sinus & Cosinus"        ; finish with a title; optional: xxxxyyyyFF#: x, y pos, font size
  GuiTextBox 12, 100.0-80, 440, 66, Join$(desc$(), " "), bcol RgbCol(192, 255, 192)
  GuiEnd


Project attached. To build it, open the *.asc file in \Masm32\MasmBasic\RichMasm.exe and hit F6.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: Plotting data
« Reply #1 on: April 13, 2019, 10:37:15 PM »
Work in progress on my table/grid/spreadsheet control. Source & exe attached; run the exe and right-click inside the spreadsheet to see the options, in particular "Plot selection" and "Plot clipboard".

From a programmer's viewpoint, the interface is, ehm, rather basic - here, four menu items are being added:

       tcAddMenu "Show selection", ShowMySelection     ; text, name of Proc(args)
       tcAddMenu "Plot selection", PlotSelection
       tcAddMenu "Plot clipboard", PlotClipboard
       tcAddMenu "Show row, col", MySelByRC


...

PlotSelection:
  StringToArray tcSelection$(), plotarray(), staHasText
  GuiRefresh Plot
  ret
PlotClipboard:
  StringToArray Clip$(), plotarray(), staHasText
  GuiRefresh Plot
  ret


I'm afraid you need a recent MasmBasic installation to run it.