Graphing Dots
Author |
Message |
justin_lim222
|
Posted: Fri Jun 03, 2011 6:34 pm Post subject: Graphing Dots |
|
|
What is it you are trying to achieve?
I need a program in which the user can input coordinates, and the program plots it. I need to be able to clear the graph, and exit the program.
What is the problem you are having?
The program works fine before I use the clear button, once the clear button is clicked, the program will not graph dots anymore
Can you guys please suggest anything that needs to be changed as well? Thanks (:
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
%Justin Lim
%June 2, 2011
%Mr.Hook
%ICS20G
%Summative : A Little Math Project - Part B
import GUI
%Defines common variables
var y1, y2, x1, x2 : int
var font1, font2, font3 : int
var numb : int
var numbstr : string
var xposcord, yposcord, xnegcord, ynegcord : int
var xtextfield, ytextfield : int
var xstr, ystr : string
var xdot, ydot : int
var winID1: int
%Defines fonts
font1 := Font.New ("tahoma:7:bold")
font2 := Font.New ("tahoma:11:bold")
font3 := Font.New ("tahome:6:bold")
%Sets screen size
winID1 := Window.Open ("graphics:870,670,position:middle,center")
setscreen ("graphics:870;670, nobuttonbar")
procedure getvalues
xstr := GUI.GetText (xtextfield )
ystr := GUI.GetText (ytextfield )
if strintok (xstr ) then
xdot := strint (xstr )
else
xdot := 0
end if
if strintok (ystr ) then
ydot := strint (ystr )
else
ydot := 0
end if
end getvalues
procedure graph
getvalues
Draw.FillOval ((xdot * 15) + ((maxx - 200) div 2), (ydot * 15) + (maxy div 2), 3, 3, black)
end graph
%Allows program to get text, but does nothing
procedure Nothing (text : string)
end Nothing
procedure quitting
Window.Close (winID1 )
end quitting
procedure grid
cls
%Starting points for grid lines
y1 := maxy div 2
y2 := maxy div 2
x1 := (maxx - 200) div 2
x2 := (maxx - 200) div 2
%Horizontal grid lines
for i : 1 .. 22
Draw.Line (20, y1, 648, y1, grey)
y1 := y1 + 15
Draw.Line (20, y2, 648, y2, grey)
y2 := y2 - 15
end for
%Vertical grid lines
for i : 1 .. 22
Draw.Line (x1, 20, x1, maxy - 20, grey)
x1 := x1 + 15
Draw.Line (x2, 20, x2, maxy - 20, grey)
x2 := x2 - 15
end for
%Labels and axes
Draw.ThickLine ((maxx - 200) div 2, 22, (maxx - 200) div 2, maxy - 22, 5, black)
Draw.ThickLine (22, maxy div 2, 648, maxy div 2, 5, black)
Font.Draw ("(0,0)", 340, maxy div 2 + 8, font1, black)
Font.Draw ("y", (maxx - 206) div 2, maxy - 10, font2, black)
Font.Draw ("X", 5, maxy div 2 - 5, font2, black)
%Postive x coordinate labels
numb := 1
xposcord := (maxx - 200) div 2 + 13
for i : 1 .. 20
numbstr := intstr (numb )
Font.Draw (numbstr, xposcord, maxy div 2 - 10, font3, black)
xposcord + = 15
numb + = 1
end for
%Negative x coordinate labels
numb := - 1
xnegcord := (maxx - 200) div 2 - 20
for i : 1 .. 20
numbstr := intstr (numb )
Font.Draw (numbstr, xnegcord, maxy div 2 - 10, font3, black)
xnegcord - = 15
numb - = 1
end for
%Postive y coordinate labels
numb := 1
yposcord := maxy div 2 + 13
for i : 1 .. 9
numbstr := intstr (numb )
Font.Draw (numbstr, (maxx - 200) div 2 - 9, yposcord, font3, black)
yposcord + = 15
numb + = 1
end for
%Postive y coordinate labels (To make them aligned)
for i : 10 .. 20
numbstr := intstr (numb )
Font.Draw (numbstr, (maxx - 200) div 2 - 12, yposcord, font3, black)
yposcord + = 15
numb + = 1
end for
%Negative y coordinate labels
numb := - 1
ynegcord := maxy div 2 - 17
for i : 1 .. 9
numbstr := intstr (numb )
Font.Draw (numbstr, (maxx - 200) div 2 - 11, ynegcord, font3, black)
ynegcord - = 15
numb - = 1
end for
%Negative y coordinate labels (To make them aligned)
for i : 10 .. 20
numbstr := intstr (numb )
Font.Draw (numbstr, (maxx - 200) div 2 - 15, ynegcord, font3, black)
ynegcord - = 15
numb - = 1
end for
Font.Draw ("X", maxx - 170, maxy div 2 + 103, font2, black)
xtextfield := GUI.CreateTextFieldFull (maxx - 150, maxy div 2 + 100, 30, "", Nothing, GUI.INDENT, 0, 0)
Font.Draw ("Y", maxx - 95, maxy div 2 + 103, font2, black)
ytextfield := GUI.CreateTextFieldFull (maxx - 75, maxy div 2 + 100, 30, "", Nothing, GUI.INDENT, 0, 0)
var graphbutton := GUI.CreateButton (maxx - 150, maxy div 2 + 50, 100, "GRAPH", graph )
var clearbutton := GUI.CreateButton (maxx - 150, maxy div 2 + 25, 100, "CLEAR", grid )
var quitbutton := GUI.CreateButton (maxx - 150, maxy div 2, 100, "QUIT", quitting )
end grid
grid
loop
exit when GUI.ProcessEvent
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
goroyoshi
|
Posted: Fri Jun 03, 2011 6:50 pm Post subject: RE:Graphing Dots |
|
|
I dont know what is causing this, but your missing GUI.Quit at the end
it should go
Turing: |
Quitbutton := GUI.Createbutton (x,y,w, "text", GUI.Quit)
|
and then put your quit function after the end loop |
|
|
|
|
|
|
|