Author Topic: Plotting data  (Read 417 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9278
  • 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: 9278
  • Assembler is fun ;-)
    • MasmBasic
Plotting random data using a probability table
« Reply #1 on: February 11, 2019, 04:09:17 PM »
include \masm32\MasmBasic\Res\MbGui.asm
MakeFont hFont, Height:20, Weight:FW_SEMIBOLD, "Times New Roman"

ArraySet probTable() As DWORD=0, 1, 3, 6, 10, 15, 19, 22, 23, 23, 23, 22, 20, 19, 18, 18, 19, 20, 21, 22, 22, 23, 24, 25, 26
Rand(pt:probTable())            ; tell Rand() to use the probability table

Event Size
  Dim values() As DWORD         ; create an array of 32-bit integers
  For_ ct=1 To 1000000
        inc values(Rand(pt))    ; Rand(pt) returns range 0 ... len(pt)-1
  Next

Event Paint
  ArrayPlot values(), RgbCol(0, 0, 255), lines=5        ; plot the numbers in blue
  ArrayPlot exit, "Random values based on a probability table"
  GuiTextBox 99.9-180, 99.9-90, 170, 80, "Size the window to see how the randomly generated numbers change", bcol RgbCol(255, 255, 0), font hFont
  xor ecx, ecx
  For_ ct=1 To probTable(?)-1   ; optional: display the numbers
        add ecx, 20
        GuiText 9, ecx, Str$(values(ct))
  Next
GuiEnd


Building this example requires MasmBasic version 11 February 2019

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9278
  • Assembler is fun ;-)
    • MasmBasic
Re: Plotting data
« Reply #2 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.