View Full Version : Super Function Plotter: Inspired from pages 41 - 64
Super Function Plotter Updated. Buttons now do a lot of the equations as presets in this section.
Just run the program, a default plot appears. Click the Clear B button for example to see how it changes the plot.
The program does 2 types of plots. I named them simple and complex. If both x and y are assigned formulas, this is considered complex. In this case t is assigned the range values. Follow the instructions below and then press the other function buttons. The numbers in some of the button match which exercise problem. I made the changes Petr recommended. Now lines does line strip. New updates attached to this message.
If only y has a formula and x is empty, then it plots the simple. In this case, the range is assigned to x.
It is all interactive and dynamic, so you will get the idea right away. Now you can just type in values for many of the equations on pages 41-64 and see the results.
Perhaps someone would like to carry on assign some of the named equations to the clear buttons. I started to do it, but decided it is a task for someone else to carry on.
If you want the x or y axis not showing, just assign it the same color as the background.
The default starts up with exercise 1 from page 53, you will see why I chose this one, it makes a cool big S.
Petr Schreiber
28-02-2010, 10:32
Kent,
this is great!
I like how dynamic you made it, you type formula and it is immediately represented.
Very good job!,
Petr
Petr Schreiber
28-02-2010, 11:17
Little hint: to render the function smooth using lines, do not use %GL_LINES, as they take each 2 vertices as definition for single line. Use %GL_LINE_STRIP instead in PlotFunc and PlotFunc2, and you will see it will look much better.
Petr
ErosOlmi
28-02-2010, 13:39
Kent,
great great job: an on the fly calculator using Eval module.
Thanks a lot for this example, it can become a great thinBasic flagship.
Eros
PS, Little speed improvement: it is not necessary to call more than once setEvals... functions (where you call Eval_SetNumber in order link internal Eval module variable to script variable) unless you change to script variable associated to Eval counterparts. Once script variables are linked, they will remain linked unless you have to change some links.
This would give a little more speed in execution.
Eros not sure I understand how to do what you said, but will study later today. And I will add changes you recommend and Petr's too-- later. Then it is ready to be added to by the next coder. Perhaps Stan can tinker with it, a good way to get his hands into thinBasic quickly with this skeleton in place.
Glad you guys liked it, thanks for the feedback. Also of course Petr helped a lot as mentioned in the comments, but wanted to say thanks here too.
the ultimate beauty, thanks kent.
can we call thinbasic a GymnasticsBasic in which the hard to achieve is possible!.
also big thanks to stan for his very fine book. and for stirring such an interest in math and opengl.
ErosOlmi
28-02-2010, 19:51
Eros not sure I understand how to do what you said, but will study later today.
Sorry, my mistake. Non need to do anything.
I was thinking you was linking using Eval_LinkExt method.
Forget my suggestion.
Eros
the ultimate beauty, thanks kent.
can we call thinbasic a GymnasticsBasic in which the hard to achieve is possible!.
also big thanks to stan for his very fine book. and for stirring such an interest in math and opengl.
Thanks Zak. Stan's book brings the beauty in math to the nonMath people like me who are interested, but had no clue. And I had no idea that openGL could do 2D to that extent even though I played with it for some time now. I always thought you had to use GDI or GDI+ routines. So for me, two major light bulbs went off with Stan's book.
Also the fact that others got into it so much too and did so many conversions is really exciting.
Kent:
The Super Function Plotter is a beautiful piece of work, illustrating the power and facility of thinBasic, and is a very useful application. Many thanks for sharing you'r work.
Don
Kent!!
What a fantastic piece of programming! This is great and I'm having a lot fun playing with functions.
Great work... just great!
Stan
The code is updated in the first post.
Thanks Stan. I got more steam today to get it to a point I like now. Back and forth with Petr helped solve a tough problem I had yesterday. Glad you are enjoying it. It is even more fun now.
Yes! That's great... and I like "Miller's Madness" in the thumbnail as well!
This is very cool and I'll share it with my students tomorrow (today is a holiday in Illinois). They'll have fun "playing." You'd be surprised how much math they learn when they don't think about learning math :D
Good work, Kent... nicely done!
Stan
The code is updated in the first post.
Thanks Stan. I got more steam today to get it to a point I like now. Back and forth with Petr helped solve a tough problem I had yesterday. Glad you are enjoying it. It is even more fun now.
Thanks Stan, I am glad you like it. In reviewing and trying to do some more of the equations from your book, I came up with some more ideas for the plotter.
Since this current version is functional and adequate for a lot of them, we can call this version 1.
Version 2 will be a different enough to being its own new function plotter model, so there will be 2 models of the plotter, and I am sure as we go on there will be more models in the future :)
Charles Pegge
02-03-2010, 20:54
Hi Kent,
Looking at your plotter code, I notice you refresh the plot using the WM_TIMER signal. You could improve the CPU work load by refreshing whenever a control button is pressed instead. All you need is to set a Global refresh flag variable which can be cleared after a refresh.
For very demanding functions Oxgen will certainly help. The best way to do it is set up a source string containing all the parameters and code necessary to calculate the entire plot and fill thinBasic arrays with the results. Then TBGL can process these results separately - either using direct vertex commands or using the forthcoming vertex array processing.
Does that make sense? :)
Charles
I sort of understand what you are saying. I am writing the new version all from scratch, when I get to a point where I get it working I will work on bringing oxygen in. I will study all the examples and when I get stuck on specifics I will ask for help. Thanks for helping already and the new samples.
A previous version was updating all the time, but Petr recommended using the timer to take the load off of the cpu. That Miller's madness equation is a good one to test with as anything below 0.1 steps it slows down quite a bit. We can use that when the new version is ready to optimize.
Here is the next generation. Unfortunately I spent twice as many days as I planned on it and could not implement lesson saving and loading. It can be a good test app for ideas on making ones own or adding to this version. But it has more things to play with and get cool looking graphics via math. Enjoy!
Petr Schreiber
06-03-2010, 13:47
Hi Kent,
nice example, and pretty wild function plot, I can tell you!
There is one aesthetical detail - the graphics are drawn over the status bar, making the image flicker.
So better to create statusbar first, use control get size to retrieve its true height, and then subtract it from the canvas height.
Maybe also good to incorporate the idea of redrawing image only on change, as Charles suggested.
Once changed, you can cache it to display list or gbuffer, and then you just redraw using single command when necessary.
I am sorry to lead you off the path with the timer approach, it works well for animated scene, but for static one the Charles way is better.
Regarding storing/saving ... I think INI file could serve well here.
I liked the layout too.
Petr
ErosOlmi
06-03-2010, 20:30
Great layout.
Only problem: big CPU load. Almost all CPU is consumed by redrawing
I was using the status bar for development. I guess it will be easier to just remove it. I don't want to put anymore time into it. I will fix the cpu load by not making it dynamic. It will be the easiest way.
I will upload the changes soon. Thanks for comments and feedback.
I commented out the status bar lines. If anyone else wants to use it for debugging, just uncomment the lines.
The cpu usage. I just upped the timer trigger from .2 seconds to 2 seconds. This way the dynamic update is in place and the cpu is not working
full time.
The updated file is attached to the original post for super function plotter2 or just click on the link below to get the file attachment directly from the post.
http://community.thinbasic.com/index.php?action=dlattach;topic=3261.0;attach=6724
ErosOlmi
07-03-2010, 20:55
Kent,
if it can help, you can get \SampleScripts\Tutorial\ script and use a skeleton for this application.
Tutorial script is very adaptable to many kind of situations.
It is also heavily based on INI file and left menu is automatically build from what is found on disk so adding new functions is easy
Also the right part can be used/substituted by a TBGL canvas.
Just an idea.
Ciao
Eros
Thanks Eros, that is something I never thought about. That would have been a very powerful base to build from. Perhaps later or someone else wanting or needing it can definitely try it out.