Computer Science Canada

Graphing calculator

Author:  Tubs [ Mon Mar 17, 2003 11:58 am ]
Post subject:  Graphing calculator

alright this graphing calculator works for declaring a point, it puts it whereever i say. BUT whenever i put a slope it draws multiple dots... (and i know it is possible to work cause my friend got it)

whats wrong?

Author:  Tony [ Mon Mar 17, 2003 12:18 pm ]
Post subject: 

wow dude, your graphing is WAY off... I cant see it actually... here's the correct way of graphing a line:

code:

    Graph

    for I : -midx .. midx
        Y := round (M * I) + midy

        drawfilloval(midx + I, Y, 2,2,white)



    end for


replace your procedure with that. To get the Y value, you just multiply X (which is counter, so its I) by slope (M) and add midy to bring the graph up so it runs through the middle.

instead of drawing a bunch of dots, just draw a small circle. Adding midx to the X value to bring it to the right so it runs through the middle. (You gotta account for those negative areas of the graph)

I'm glad someone found text effects tutorial useful Wink

Author:  Tubs [ Mon Mar 17, 2003 12:24 pm ]
Post subject: 

hahaha you noticed that did you Wink

anyways k i will try that gimme 1 sec

Author:  Tubs [ Mon Mar 17, 2003 12:27 pm ]
Post subject: 

alright it makes the line, but its still all made of dots. how do i make it connected if thats possible? well i know its possible but im really tired lol

AND it messes up my graphing thing. ex, 10 x value and 10 y doesnt go up 1 square

Author:  Tony [ Mon Mar 17, 2003 12:53 pm ]
Post subject: 

to make dots connected, you ether

a) have to draw more dots. Such as instead of looping 1,2,3 try looping 1.5,2,2.5,3, etc.

you can use only integers in forloop, so use a normal loop instead. OR

b) draw your graph using lines. Such as instead of drawing a dot, draw a line from previous dot to current dot. You'd have to keep track of the last dot drawn.

Author:  Big_Tom [ Tue Mar 18, 2003 11:59 am ]
Post subject: 

yes i also need help with this project. I can't get the line to graph correctly i did the same line thing that you told tubs and i still can not get it to work correctly. This slope is correct but the cordinate values are wrong and i dont know how to fix it.

Author:  Asok [ Tue Mar 18, 2003 12:01 pm ]
Post subject: 

this is because turing coordinates work differently then graphing coordinates. in graphing the orgin (0,0) is in the center. in turing the origin is in the bottom left corner. This is probably why your coordinates are off.

Author:  Tubs [ Tue Mar 18, 2003 12:12 pm ]
Post subject: 

actually no, the program has its own coordinate system

Author:  Asok [ Tue Mar 18, 2003 12:18 pm ]
Post subject: 

Nevermind what I said then Wink

Author:  Tubs [ Tue Mar 18, 2003 12:28 pm ]
Post subject: 

its aight, and i got it to work for you who were wondering


code:

Graph

    for I : -midx .. midx
        Z := round (M * (I - X) + Y)

        drawfilloval (midx + I, Z + midy , 2, 2, 12)

    end for
[/code]

Author:  Big_Tom [ Tue Mar 18, 2003 12:56 pm ]
Post subject: 

I want to know how to make the line an actual line not just composed of ovals. It would clean it up a little bit more.

Author:  Tubs [ Tue Mar 18, 2003 12:59 pm ]
Post subject: 

ya that would be nice lol but...

i need to know how to declare an array, then use it in a for statement. its for putting coordinates across the graph. ex, array 1..10 is -50 .. 50 then i use the for statement to put them on the screen by a certain amount

Author:  Tony [ Tue Mar 18, 2003 1:32 pm ]
Post subject: 

to draw a line, you find start point on -midx and end point on midx then you draw a line between them. The only difference is that the line would be 1 pixel wide, not 4.

as for arrays - http://www.compsci.ca/bbs/viewtopic.php?t=366

with explanations and examples.

Author:  Tubs [ Wed Mar 19, 2003 12:51 pm ]
Post subject: 

for I : 0 .. maxx by 10
for J : -50 .. 50 by 10

Draw.Text (J, I, midy, fontID, white)

end for
end for


this is supposed to draw -50 .. 50 at midy, why doesnt it work? all the vars are declared *i think* can you put the vars and the correct draw command please?

Author:  Asok [ Wed Mar 19, 2003 1:00 pm ]
Post subject: 

fontID has not been declared.

Author:  Tony [ Wed Mar 19, 2003 1:05 pm ]
Post subject: 

var fontID:int := Font.New("arial:14:bold")

or something like that... first is font name, then its size then you can add stuff like bold... you dont have to, just put " after the size

Author:  Tubs [ Wed Mar 19, 2003 8:20 pm ]
Post subject: 

ya but i have that declared for the 3d text at the start, will i have to make a new fontID var to do this?

Author:  Asok [ Wed Mar 19, 2003 9:47 pm ]
Post subject: 

fontID1 or if there are alot u can make it an array of int.

Author:  Tony [ Wed Mar 19, 2003 10:26 pm ]
Post subject: 

fonts for 3D text are decleared as an array.

you can use fontID(size) if I remember it correctly and if that particular size was decleared.

Author:  Tank [ Thu Mar 20, 2003 12:07 pm ]
Post subject: 

How do I fix the parabola when the equation is...

for x : -halfx .. halfx
y := round (M * (x - P)**2 + Q)

plz reply with your answer if you know it Smile


: