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

Username:   Password: 
 RegisterRegister   
 curves
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bored_hacker




PostPosted: Sun May 29, 2005 3:39 pm   Post subject: curves

i'm working on a program that draws sine, cosine, tangent curves, lines and parabolas. it's still in progress but i have made a prototype that draws sine and cosine curves like you would on a graphing calculator. the full version will also have GUI. i'll post it when i'm done, anywy, here's the prototype. It's 95% foolproof. any suggestions would be appreciated.

also, in the parameters u can type in "pi" for 3.141592653...
(it's not case sensetive)

code:
View.Set ("graphics: max, max; nobuttonbar")
const midx := maxx div 2
const midy := maxy div 2
fcn convert (org : string) : real
    if strintok (org) then
        result strint (org)
    elsif Str.Upper (org) = "PI" then
        result Math.PI
    else
        result 0
    end if
end convert
var txt := Font.New ("Times New Roman:8")
var y1, y2, x2 : int
var a, p, tv, th : real
var A, P, TV, TH : string
var pick : string
fcn valid : boolean
    if pick = "SINE" or pick = "COSINE" then
        result true
    else
        result false
    end if
end valid
View.Set ("text")
put "Do you wish to draw a sine or cosine curve?"
get pick
pick := Str.Upper (pick)
if valid then
    put "What's the amplitude?"
    get A
    put "What's the period? (times 2pi)"
    get P
    put "What's the vertical translation?"
    get TV
    put "What's the horizantal translation?"
    get TH
    a := convert (A)
    p := convert (P)
    tv := convert (TV)
    th := convert (TH)
end if
View.Set ("graphics: max, max")
cls
Draw.Line (0, midy, maxx, midy, 7)
Draw.Line (midx, 0, midx, maxy, 7)
Draw.Oval (midx, midy, 5, 5, 7) %The point (0, 0)
for i : 0 .. maxx
    if (i - midx) not= 0 then
        if (i - midx) mod 100 = 0 then
            Draw.Text (intstr (i - midx), i, midy + 5, txt, 7)
        end if
    end if
end for
for i : 0 .. maxy
    if (i - midy) not= 0 then
        if (i - midy) mod 100 = 0 then
            Draw.Text (intstr (i - midy), midx + 5, i, txt, 7)
        end if
    end if
end for
if pick = "SINE" then
    for x1 : -maxx .. maxx - 1
        x2 := x1 + 1
        y1 := round (a * sind ((x1 / p) + th) + tv)
        y2 := round (a * sind ((x2 / p) + th) + tv)
        Draw.Line (x1 + midx, y1 + midy, x2 + midx, y2 + midy, 7)
        delay (1)
    end for
elsif pick = "COSINE" then
    for x1 : -maxx .. maxx - 1
        x2 := x1 + 1
        y1 := round (a * cosd ((x1 / p) - th) + tv)
        y2 := round (a * cosd ((x2 / p) - th) + tv)
        Draw.Line (x1 + midx, y1 + midy, x2 + midx, y2 + midy, 7)
        delay (1)
    end for
else
    cls
    put "Your choice was invalid!!!"
end if
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun May 29, 2005 3:42 pm   Post subject: (No subject)

You should either make the scale of the x and y axes adjustable, or make them auto adjust to fit your sine wave/whatever you're graphing.
bored_hacker




PostPosted: Sun May 29, 2005 3:45 pm   Post subject: (No subject)

Cervantes wrote:
You should either make the scale of the x and y axes adjustable, or make them auto adjust to fit your sine wave/whatever you're graphing.


i originally chose to do that but i changed my mind, good idea though
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: