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 |