Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Graphing calculator
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tubs




PostPosted: 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?



graphing calc.t
 Description:
graphing calc

Download
 Filename:  graphing calc.t
 Filesize:  6.62 KB
 Downloaded:  287 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Mar 17, 2003 12:18 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Tubs




PostPosted: Mon Mar 17, 2003 12:24 pm   Post subject: (No subject)

hahaha you noticed that did you Wink

anyways k i will try that gimme 1 sec
Tubs




PostPosted: Mon Mar 17, 2003 12:27 pm   Post subject: (No 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
Tony




PostPosted: Mon Mar 17, 2003 12:53 pm   Post subject: (No 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Big_Tom




PostPosted: Tue Mar 18, 2003 11:59 am   Post subject: (No 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.
Asok




PostPosted: Tue Mar 18, 2003 12:01 pm   Post subject: (No 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.
Tubs




PostPosted: Tue Mar 18, 2003 12:12 pm   Post subject: (No subject)

actually no, the program has its own coordinate system
Sponsor
Sponsor
Sponsor
sponsor
Asok




PostPosted: Tue Mar 18, 2003 12:18 pm   Post subject: (No subject)

Nevermind what I said then Wink
Tubs




PostPosted: Tue Mar 18, 2003 12:28 pm   Post subject: (No 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]
Big_Tom




PostPosted: Tue Mar 18, 2003 12:56 pm   Post subject: (No 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.
Tubs




PostPosted: Tue Mar 18, 2003 12:59 pm   Post subject: (No 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
Tony




PostPosted: Tue Mar 18, 2003 1:32 pm   Post subject: (No 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Tubs




PostPosted: Wed Mar 19, 2003 12:51 pm   Post subject: (No 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?
Asok




PostPosted: Wed Mar 19, 2003 1:00 pm   Post subject: (No subject)

fontID has not been declared.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: