Dark Bit Factory & Gravity
GENERAL => Projects => Topic started by: combatking0 on December 12, 2010
-
I have been developing a graphical function display program. I know there are some out there, and there may even be a few available for free, but I wanted to see if it could be done, and I have found the following to pose quite a challenge - Actionscript 2 has no mathematical evaluation function!
In JavaScript, we have eval() for converting a string containing a mathematical function into a numerical result. In Actionscript, the eval() method is used for converting a string into an object reference.
As such, I have had to build my own mathematical evaluator to make this work. So far, it recognises power (^), multiplication (*), division (/), addition (+) and subtraction (-) symbols, but it does not yet recognise brackets :( I plan to include this functionality soon.
The Y scale is currently manual. I plan to make this automatic by default, with a manual option to allow the user to zoom into view the results.
To use the program, simply run it under Windows 2000, XP, Vista or 7. Other operating systems may also work, if they support Win32 exes.
Next you must set the X and Y limits. By default, these are both set to -10 to 10.
Next you must enter at least 1 function in one of the "Y=" boxes.
For example, 0.9*x+3 would result in a linear graph.
Also, x^2-5 would result in a curved graph.
If you think this sort of thing would be useful to you, please test it out, and let me know what needs to be changed to make it more useful.
So far, I plan to add bracket recognition to the function parser, an automatic Y-Scale option, more lines on the graph output, and to re-arrange the positions of the text inputs and Plot button to make it look better. If I have missed anything, please tell me.
-
Works fine under Wine 1.2.2 on OSX.
Very neat little app. The only things that spring to mind that would be useful you have already mentioned.
Perhaps being able to select a particular colour to bring it to the front?
Oh and y=-x doesn't seem work quite right. I don't get any dots for x < 0.
[edit]
I just noticed that if I resize the app to particular width/height ratios I can see all the un-plotted dots above the app :)
[/edit]
-
Well. that's nice.
Did you know that such app exist in a browser ( http://www.iquilezles.org/apps/graphtoy )
Otherwise, look at my attachment, it looks a bit weird (two points missing) ... but ok ... I have tried a wrong function ;)
Nothing else to say ... good job :)
-
I'll look into those bugs. The missing dots one looks interesting - which function did you use to make that happen?
-
On the picture you can see the function.
But I am aware, that I have just entered something not managed (instead of putting 'x2' I should put x*2) ... with the 'x*2' and some other quick test that I did, it was right ;)
-
I think I know how to fix this. It could take a few hours. :kewl:
-
I have added support for brackets, and for putting a minus (-) symbol at the start of the function, but the "x2" error has still not been fixed. This will come in version 0.91.
-
The x2 problem is now fixed, so I'll next add sine and cosine functionality.
I may have to add a Degree / Radian mode selector.
-
Constructive criticism:
I tried y=8*x and the top and bottom clipping make it look like a curve.
I tried y=x^2, excellent
I tried y=(x^2)^2 doesn't work - do you do parenthesis yet?
same for (x^2)*5
I tried y=x^2^2 that works ok.
Very good looking. Can you take advantage of some flash library that knows how to compute expressions from strings?
Jim
-
I'll see if I can fix the clipping problem by adding more sampling points.
The parenthesis work some times. If you put a positive number in front of the x they work, so I think I know how to fix it.
I have had a look at the work other people have done in trying to get Flash to compute expressions from strings, but for some reason they don't work in my program. But looking at their code, I could see how it would work, so I started to create my own function from scratch to try and copy the functionality.
There isn't a built-in function to do this, so creating one is becoming an interesting challenge.
After checking around the internet for a few weeks, I have found that there have been many attempts at this sort of thing in Flash, each with varying degrees of success. Hopefully this will be one of the more functional ones. I just need to put the effort in.
(edit)
I have attached V0.93. The string interpretter should now be near perfect, though if you can find any bugs I'd be interested. I'll look for some.
Trig functions can be activated by typing s(x) or c(x) for sine and cosine respectively. Clicking on the Trig button will switch between Radian and Degree modes, but you'll need to click on the Plot button after each change to see the difference.
The y=8*x clipping problem hasn't been fixed yet - I'll try to address this in 0.94.
(edit 2) I have found one: -x^2 created an unexpected output, so I'll correct it in the next version.
-
I have increased the number of plot points by 4 times, but the x*8 problem still exists a little bit.
I think I have found another way to fix it. Apart from that, setting the Trig mode to Degrees by default, and moving most of the options behind an options panel, I reckon this program is ready.
-
After much field testing, I'm confident that this is the final version.
Please don't distribute it beyond this forum, but feel free to use it for your own personal graph plotting needs if you want.
The school which employs me plans to distribute this program amongst other schools for a fee - that is it the administrative staff can be bothered, but I would be interested to hear your thoughts about it.
-
What operator is asigned to ^ I was expecting xor but looks like thats not what it is. Also what algorithm are you using for the expression parser? I was working with something similar and found this great tutorial (http://www.strchr.com/expression_evaluator) but eventually decided that Dijkstra's Shunting yard (http://en.wikipedia.org/wiki/Shunting-yard_algorithm) is a better solution.
-
i had a go with it ck,
i must admit im not very good with these sort of tools my graphic calculator used too sit with the huge manuel on top as a door stop, but it seems too work good and it looks really profesional and well polished! so well done i hope you get some decent exposure for your hard work and it get passed around other schools mate.
-
What operator is asigned to ^
Means 'raise to the power'. So 4^2 is 4 to the power 2 is 16.
Jim
-
@ rain_storm: There's a full document explaining how to use the program which will be distributed with the final installer package, but I didn't include it because it was written for the features in V1.04
Because there is no truely mathematical eval() method in AS2, I have had to write my own version. It's messy, but I have attached the main source.
For it to work, the value of X must have already been calculated, as it is not a complete eval() replacement, but it is enough for this program to work.
@ ninogenio: That's a spot-on observation - this is program is targetted at 11-18 year olds, so I have tried to make it as simple to use as possible. Although, with the need to type in such symbols as ^, * and /, it's almost an introduction to coding for some of them, as they'll be used to using different symbols on paper.
I couldn't have made this program as well as it is without the help I've had here and the feedback I've had from various teachers, so it's been a massive collaborative effort. Thank you to everybody who has helped.