Hi again hard working ppl,
Anyone have expierence drawing graphs inside normal resource (win API) environment?
(Thought I remember seeing jj2007 do something like what I'am looking for in a project of his)
I'am looking to draw sinoide graphs for my Fourier series / Fourier transform app. A sample
with recommendations would be appreciated. Possibly listing pitfalls to look out for? Oh yes
and quick redraw is essential as live streaming data needs to be visualized.
Thanks in advance
Raistlin
the attachment to the linked post is a Bezier Spline example program
it uses data from a file to draw the splines
http://masm32.com/board/index.php?topic=1969.msg20895#msg20895 (http://masm32.com/board/index.php?topic=1969.msg20895#msg20895)
of course, you don't have to use PolyBezier to draw sine waves
you can also plot points and use MoveToEx and LineTo to draw lines
or - you could create a DIB section and "draw" directly to the bitmap
Hi Raistlin,
Attached three samples. PlotSinus2 is the simplest:
CASE WM_PAINT ; in the PAINT handler, we plot it onto the client area
ArrayPlot hWnd, RgbCol(200, 255, 240) ; init with window handle and background colour
ArrayPlot Sinus()
ArrayPlot exit, "Sinus" ; finish with a title
You need one or more arrays. Preferably, they can be loaded in the WM_CREATE handler with ArrayRead (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1179):
Dim rc4() As REAL4
ArrayRead rc4(), "MyReal4.dat"
Format can be REAL4, REAL8, DWORD, ...
How do you store your values? Can you post sample data?
If your data is in text format, Recall and MovVal can help (see attached Dax.zip):
include \masm32\MasmBasic\Res\MbGui.asm
Event Create
MakeFont hLegendFont, Height:20, Weight:FW_SEMIBOLD, "Times New Roman"
Dim bmw() As REAL4 ; single precision is good enough
Dim daimler() As REAL4
Dim vw() As REAL4
Recall "Dax.tab", dax$(), tab ; get the database
For_ ecx=0 To eax-2 ; convert tabbed text to REAL4
MovVal bmw(ecx), dax$(ecx+1, 2)
MovVal daimler(ecx), dax$(ecx+1, 3)
MovVal vw(ecx), dax$(ecx+1, 4)
Next
Event Paint
ArrayPlot hWnd, RgbCol(144, 240, 255) ; init with window handle and background colour
ArrayPlot bmw(), RgbCol(255, 0, 0), lines=2, 7 ; plot the arrays
ArrayPlot daimler(), RgbCol(0, 0, 255), lines=2, 7
ArrayPlot vw(), 0, lines=2, 7
ArrayPlot exit, "Car manufacturers in the DAX" ; finish with a title
GuiText 3, 20, "VW", fcol 0, font hLegendFont ; set a bold font
GuiText 3, 50, "Daimer", fcol RgbCol(0, 0, 255)
GuiText 3, 80, "BMW", fcol RgbCol(255, 0, 0)
GuiEnd
another interesting forum thread...
http://masm32.com/board/index.php?topic=3099.msg32134#msg32134 (http://masm32.com/board/index.php?topic=3099.msg32134#msg32134)
Hi & thanks guys - exactly what I was looking for
Looks easier than anticipated.
PS: JJ2007 - the Dax example has a corrupt zip - but the plots example is ultra cool for a tut.
again I would like to extend my appreciation dedndave and jj.
Hi Raistlin,
Quote from: Raistlin on July 22, 2015, 08:34:54 PM
PS: JJ2007 - the Dax example has a corrupt zip - but the plots example is ultra cool for a tut.
no it hasn't. It's not a real zip file, but the image. You can view it with an image tool like Iranview and the like. It has to do with some limitations of the forum. You can't attach images, only zip files.
Gunther
Quote from: Raistlin on July 22, 2015, 08:34:54 PMPS: JJ2007 - the Dax example has a corrupt zip - but the plots example is ultra cool for a tut.
As Gunther already wrote, it's a trick to convince the forum software to display attached images.
Again, which format are you using? Binary or text file? Both are possible, see below, but it would be nice to see an example of your data.
Dim rc4() As REAL4
if 1 ; either get your data as text from some buffer, e.g. from a text file...
StringToArray "1.0 1.5 1.8 1.75 1.72 1.75 1.8 1.5 1.0", rc4()
else ; ... or get it directly in 4-byte binary format from a file
ArrayRead rc4(), "MyReal4.dat"
endif
Hi jj,
The data will be converted to internal real4 or 8
from dynamic sources and normalized for diffrenciation
and reporting purposes. This at the core of the idea
that the functionality be data independant but not blatently
Object orientated [sorry biteridder].
Hope this helps
R
Quote from: Raistlin on July 23, 2015, 12:24:56 AMThe data will be converted to internal real4 or 8 from dynamic sources and normalized
Check the sox & crime example (http://masm32.com/board/index.php?topic=94.msg43281#msg43281). If you have a dataset online, we could give it a try. ArrayPlot (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1182) does normalisation btw, if you throw more than one array into the WM_PAINT handler. There are some undocumented features like the lines=n one, let me know if you want to go that road.
when you convert the data - convert to integer as soon as is practical
pixel plots are eventually integer locations, anyways :P
in the PolyBezier example, i have a couple routines that use the FPU to calculate control points
if you are doing all sine waves, you could probably eliminate that step
the control points for PolyBezier sine waves are very simple to derive