Graphing Program
Author |
Message |
Omicron91
|
Posted: Mon Apr 18, 2005 6:44 pm Post subject: Graphing Program |
|
|
Hey guys, just thought as my first submission I would put up something I made to do my Math homework, lol.
Just feed it the variables and you can graph some very interesting things. Right now you can only use A((X + B)**C)+D, so parabolas, lines, hyperbolas if you know what you're doing, but it's got a save function and whatnot to so give it a try.
code: |
%Graphing Program
%Steven Aston
%Date: Unknown
%Version 1.0a
var GraphWin : int := Window.Open ("graphics:600;600,nobuttonbar,nocursor,offscreenonly")
var VarWin : int := Window.Open ("graphics:400;640,nobuttonbar,nocursor")
var ShrinkStretch, Y, X, Exponent, Horizontal, Vertical : real
var GraphX, GraphY, count, AGD, PicID : int := 0
var exitnow : boolean := false
Window.SetActive (VarWin)
colorback (7)
color (0)
cls
put " Graphing Calculator"
put " Graph Lines, Parabolas, Hyperbolas and more!"
put " Written By Steven Aston"
put ""
delay (500)
procedure GraphIt
Window.SetActive (GraphWin)
for a : -10000 .. 10000
X := (intreal (a) / 1000) * 2 ** Exponent
Y := (ShrinkStretch * (X + Horizontal) ** round (Exponent) + Vertical) * 2
GraphX := round (X) + 300
GraphY := round (Y) + 300
drawdot (GraphX, GraphY, 7)
count += 1
if count = 25 then
count := 0
View.Update
end if
end for
View.Update
end GraphIt
procedure GetVars
Window.SetActive (VarWin)
put "-------------------------------------------------"
put "Enter the value of the shrink or stretch."
put " (value)(X**2 + H) + V"
get ShrinkStretch
delay (200)
put "Enter the value of the X exponent."
put " 2(X**(value) + H) + V"
get Exponent
delay (200)
put "Enter the value of the horizontal shift."
put "Remember, negative shifts right, "
put "positive shifts left."
put " 2(X**2 + (value)) + V"
get Horizontal
delay (200)
put "Enter the value of the vertical shift."
put " 2(X**2 + H) + (value)"
get Vertical
delay (500)
put "-------------------------------------------------"
GraphIt
end GetVars
procedure DrawGrid
Window.SetActive (GraphWin)
for x : -10 .. 610 by 10
drawline (x, 1, x, 600, 30)
end for
for y : -10 .. 610 by 10
drawline (1, y, 600, y, 30)
end for
drawline (-1, 300, 601, 300, 7)
drawline (300, -1, 300, 601, 7)
end DrawGrid
procedure AfterGraph
Window.SetActive (VarWin)
put "Would you like to..."
put "1. Save Picture."
put "2. Graph another function."
put "3. Clear Screen and Restart."
put "4. Exit"
get AGD
if AGD = 1 then
Pic.ScreenSave (0, 0, 600, 600, "Graph00x.Jpg")
elsif AGD = 2 then
GetVars
elsif AGD = 3 then
Window.SetActive (GraphWin)
cls
elsif AGD = 4 then
exitnow := true
else
end if
end AfterGraph
procedure MainRun
DrawGrid
loop
GetVars
AfterGraph
exit when exitnow = true
end loop
Window.Close (GraphWin)
Window.Close (VarWin)
end MainRun
MainRun
| [/code] |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Mon Apr 18, 2005 8:38 pm Post subject: (No subject) |
|
|
Your program says it can graphs all these things, well when do you chose which one it draws? I rarely get a parabola, because most of the time its a line. It's a good start, don't get me wrong, it's just prone to a lot of erros. Good work though. |
|
|
|
|
![](images/spacer.gif) |
Omicron91
|
Posted: Tue Apr 19, 2005 7:40 am Post subject: (No subject) |
|
|
You have to set the X exponent value to 2 to get a parabola, if you set it to 1 then you get a line. It's basically inputting the formula of a line or parabola and it will only graph what you give it. |
|
|
|
|
![](images/spacer.gif) |
dann_west
![](http://1047-beer-dragon.jpg)
|
Posted: Mon May 02, 2005 2:11 pm Post subject: Re: Graphing Program |
|
|
Pretty good.
Maybe you could make it so you cn make many kins of graphs and charts. |
|
|
|
|
![](images/spacer.gif) |
pro123
|
Posted: Tue May 03, 2005 10:58 am Post subject: (No subject) |
|
|
It is a really good program. But I agree you should make different kinds. I like the grid. |
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Wed May 04, 2005 8:30 pm Post subject: (No subject) |
|
|
A solid start to a graphing programme.
Suggestions:
1)
Set your window positions a little better. Since you're using 2 windows, try keep one left and one right. Use Config.Display (cdScreenWidth) and the same of cdScreenHeight to define their positions on any resolution. (I.e., since you're using the actual resolution settings as markers, you can divide up the screen as you see fit and position the windows accordingly. As long as the monitor is on a high enough resolution, this will neaten things. Lower resolutions will have overlap, so ensure that this setup works on lower resolutions first.)
2)
Check your code for the "Draw another function" part. At times, if I selected that option once, it would not allow me to access the menu after that function was drawn. Instead, it prompted for the creation of a third function.
3)
Check your bounds for function drawing. Some flatter functions (those with small "stretch" values) did not graph across the screen.
Also, expand your formula to this:
f(x) = a ( k (x-p)^exp ) + q
Keep in mind the differing stretches caused by a and k.
4)
As "values" are entered, display them in the equation! Also, check your hardcoded text, you've included a number of 2's in the initial position that shouldn't be there.
5)
Error trap please.
6)
Give the User the option of selecting the name of the picture they wish to save as.
7)
Congradulations on using procedures. Keep up the habit. Also look into functions, you'll be suprised how versitile they are.
+ bits. |
|
|
|
|
![](images/spacer.gif) |
|
|