Not really as practical as it could be, it was just something I made cuz I was too lazy to do all the physics calculations...
Turing: |
/*
* Kinematics Calculator
* Made by A. Prado
* December 9th 2011
* Made for the SPH3U1 Course
*/
/*
* Import statements
*/
import GUI
/*
* <-- Variable declarations -->
*/
var font : int
var dtime, displacement, finalvelocity, inicialvelocity, acceleration, dtime1, dtime2 : real
var choice, ch : string (1)
var width, size : int
var decimals : nat
var chars : array char of boolean
var failsafe : string
% <-- End of Variable Declarations -->
/*
* <-- Procedure Declarations -->
*/
procedure Title (fnt, fnt2 : string)
cls
GUI.SetBackgroundColour (66)
font := Font.New ("Lucida Calligraphy:" + fnt )
width := Font.Width ("Kinematics Calculator", font )
Font.Draw ("Kinematics Calculator", (maxx div 2) - (width div 2), maxy - 40, font, black)
Font.Free (font )
font := Font.New ("Times New Roman:" + fnt2 )
width := Font.Width ("Copyright" + chr (169) + " Prado 2012", font )
Font.Draw ("Copyright" + chr (169) + " Prado 2012", maxx - (width + 3), 5, font, black)
end Title
% <-- End of Procedure Declarations -->
%----------------------------------------------------------------------------------------------------------------------------------------------------------
/*
* <-- Program -->
*/
View.Set ("graphics:639;399,nobuttonbar")
Title ("20", "8")
colourback (66)
Text.Locate (6, 3)
put chr (149) + " You will be given a choice for which 3 variables you have the value of."
Text.Locate (7, 3)
put chr (149) + " You will also tell the program to how many decimal places you want your answer accurate to"
locate (18, 1)
put "Press any key to continue..." ..
getch (ch )
loop
View.Set ("graphics:639;399,nobuttonbar")
Title ("20", "8")
size := Font.Width ("Acceleration, Displacement, Inicial Velocity", font )
Draw.Box (30, 100, 340, 300, black)
Draw.Line (50, 100, 50, 300, black)
for i : 0 .. 9
Draw.Line (30, 120 + i * 20, 340, 120 + i * 20, black)
Font.Draw (intstr (i ), 40, 285 - i * 20, font, black)
end for
Font.Free (font )
font := Font.New ("Lucida Calligraphy:14")
width := Font.Width ("Variables", font )
Font.Draw ("Variables", 185 - (width div 2), 310, font, black)
Font.Free (font )
font := Font.New ("Times New Roman:12")
width := Font.Width ("Time, Displacement, Inicial Velocity", font )
Font.Draw ("Time, Displacement, Inicial Velocity", 198 - (width div 2), 285, font, black)
width := Font.Width ("Time, Displacement, Final Velocity", font )
Font.Draw ("Time, Displacement, Final Velocity", 198 - (width div 2), 265, font, black)
width := Font.Width ("Time, Displacement, Acceleration", font )
Font.Draw ("Time, Displacement, Acceleration", 198 - (width div 2), 245, font, black)
width := Font.Width ("Time, Inicial Velocity, Final Velocity", font )
Font.Draw ("Time, Inicial Velocity, Final Velocity", 198 - (width div 2), 225, font, black)
width := Font.Width ("Time, Inicial Velocity, Acceleration", font )
Font.Draw ("Time, Inicial Velocity, Acceleration", 198 - (width div 2), 205, font, black)
width := Font.Width ("Time, Final Velocity, Acceleration", font )
Font.Draw ("Time, Final Velocity, Acceleration", 198 - (width div 2), 185, font, black)
width := Font.Width ("Displacement, Inicial Velocity, Final Velocity", font )
Font.Draw ("Displacement, Inicial Velocity, Final Velocity", 198 - (width div 2), 165, font, black)
width := Font.Width ("Displacement, Inicial Velocity, Acceleration", font )
Font.Draw ("Displacement, Inicial Velocity, Acceleration", 198 - (width div 2), 145, font, black)
width := Font.Width ("Displacement, Final Velocity, Acceleration", font )
Font.Draw ("Displacement, Final Velocity, Acceleration", 198 - (width div 2), 125, font, black)
width := Font.Width ("Inicial Velocity, Final Velocity, Acceleration", font )
Font.Draw ("Inicial Velocity, Final Velocity, Acceleration", 198 - (width div 2), 105, font, black)
Font.Draw ("Press the number corresponding to", 380, 285, font, black)
Font.Draw ("the variables you have the value of", 380, 265, font, black)
loop
Input.KeyDown (chars )
exit when chars ('0') or chars ('1') or chars ('2') or chars ('3') or chars ('4') or chars ('5') or chars ('6') or chars ('7') or chars ('8') or chars ('9')
end loop
loop
Title ("20", "8")
Font.Free (font )
font := Font.New ("Times New Roman:12")
width := Font.Width ("How many decimal places will your answer have?", font )
Font.Draw ("How many decimal places will your answer have?", (maxx div 2) - width div 2 - 16, maxy div 2 + 77, font, black)
locatexy ((maxx div 2) + width div 2 + 3, maxy div 2 + 75)
get failsafe
exit when strnatok (failsafe )
end loop
decimals := strnat (failsafe )
View.Set ("graphics:300;200")
colourback (66)
Title ("14", "8")
if chars ('0') then
locate (5, 2)
put "Time: " ..
get dtime
locate (5, 2)
put "Time: ", dtime : 20 : decimals, "s"
locate (6, 2)
put "Displacement: " ..
get displacement
locate (6, 2)
put "Displacement: ", displacement : 12 : decimals, "m"
locate (7, 2)
put "Inicial Velocity: " ..
get inicialvelocity
locate (7, 2)
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
acceleration := round (((2 * (displacement - (inicialvelocity * dtime ))) / (dtime ** 2)) * (10 ** decimals )) / (10 ** decimals )
locate (8, 2)
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
finalvelocity := round (((acceleration * dtime ) + inicialvelocity ) * (10 ** decimals )) / (10 ** decimals )
locate (9, 2)
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
elsif chars ('1') then
locate (5, 2)
put "Time: " ..
get dtime
locate (5, 2)
put "Time: ", dtime : 20 : decimals, "s"
locate (6, 2)
put "Displacement: " ..
get displacement
locate (6, 2)
put "Displacement: ", displacement : 12 : decimals, "m"
locate (7, 2)
put "Final Velocity: " ..
get finalvelocity
locate (7, 2)
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
acceleration := round (((- 2 * (displacement - (finalvelocity * dtime ))) / (dtime ** 2)) * (10 ** decimals )) / (10 ** decimals )
locate (8, 2)
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
inicialvelocity := round ((- 1 * (acceleration * dtime ) + finalvelocity ) * (10 ** decimals )) / (10 ** decimals )
locate (9, 2)
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
elsif chars ('2') then
locate (5, 2)
put "Time: " ..
get dtime
locate (5, 2)
put "Time: ", dtime : 20 : decimals, "s"
locate (6, 2)
put "Displacement: " ..
get displacement
locate (6, 2)
put "Displacement: ", displacement : 12 : decimals, "m"
locate (7, 2)
put "Acceleration: " ..
get acceleration
locate (7, 2)
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
inicialvelocity := round ((((displacement - (0. 5 * acceleration * (dtime ** 2))) / dtime ) * (10 ** decimals ))) / (10 ** decimals )
locate (8, 2)
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
finalvelocity := round ((((displacement + (0. 5 * acceleration * (dtime ** 2))) / dtime ) * (10 ** decimals ))) / (10 ** decimals )
locate (9, 2)
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
elsif chars ('3') then
locate (5, 2)
put "Time: " ..
get dtime
locate (5, 2)
put "Time: ", dtime : 20 : decimals, "s"
locate (6, 2)
put "Inicial Velocity: " ..
get inicialvelocity
locate (6, 2)
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
locate (7, 2)
put "Final Velocity: " ..
get finalvelocity
locate (7, 2)
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
displacement := round ((((finalvelocity + inicialvelocity ) / 2) * dtime ) * (10 ** decimals )) / (10 ** decimals )
locate (8, 2)
put "Displacement: ", displacement : 12 : decimals, "m"
acceleration := round (((finalvelocity - inicialvelocity ) / dtime ) * (10 ** decimals )) / (10 ** decimals )
locate (9, 2)
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
elsif chars ('4') then
locate (5, 2)
put "Time: " ..
get dtime
locate (5, 2)
put "Time: ", dtime : 20 : decimals, "s"
locate (6, 2)
put "Inicial Velocity: " ..
get inicialvelocity
locate (6, 2)
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
locate (7, 2)
put "Acceleration: " ..
get acceleration
locate (7, 2)
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
finalvelocity := round (((acceleration * dtime ) + inicialvelocity ) * (10 ** decimals )) / (10 ** decimals )
locate (8, 2)
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
displacement := round ((0. 5 * (finalvelocity + inicialvelocity ) * dtime ) * (10 ** decimals )) / (10 ** decimals )
locate (9, 2)
put "Displacement: ", displacement : 12 : decimals, "m"
elsif chars ('5') then
locate (5, 2)
put "Time: " ..
get dtime
locate (5, 2)
put "Time: ", dtime : 20 : decimals, "s"
locate (6, 2)
put "Final Velocity: " ..
get finalvelocity
locate (6, 2)
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
locate (7, 2)
put "Acceleration: " ..
get acceleration
locate (7, 2)
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
inicialvelocity := round ((- 1 * (dtime * acceleration - finalvelocity )) * (10 ** decimals )) / (10 ** decimals )
locate (8, 2)
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
displacement := round ((finalvelocity + inicialvelocity ) * 0. 5 * dtime ) * (10 ** decimals ) / (10 ** decimals )
locate (9, 2)
put "Displacement: ", displacement : 12 : decimals, "m"
elsif chars ('6') then
locate (5, 2)
put "Displacement: " ..
get displacement
locate (5, 2)
put "Displacement: ", displacement : 12 : decimals, "m"
locate (6, 2)
put "Inicial Velocity: " ..
get inicialvelocity
locate (6, 2)
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
locate (7, 2)
put "Final Velocity: " ..
get finalvelocity
locate (7, 2)
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
locate (8, 2)
acceleration := round ((((finalvelocity ** 2) - (inicialvelocity ** 2)) / (2 * displacement )) * (10 ** decimals )) / (10 ** decimals )
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
locate (9, 2)
dtime := round ((((finalvelocity ) - (inicialvelocity )) / (acceleration )) * (10 ** decimals )) / (10 ** decimals )
put "Time: ", dtime : 20 : decimals, "s"
elsif chars ('7') then
locate (5, 2)
put "Displacement: " ..
get displacement
locate (5, 2)
put "Displacement: ", displacement : 12 : decimals, "m"
locate (6, 2)
put "Inicial Velocity: " ..
get inicialvelocity
locate (6, 2)
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
locate (7, 2)
put "Acceleration: " ..
get acceleration
locate (7, 2)
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
locate (8, 2)
finalvelocity := round ((sqrt ((inicialvelocity ** 2) + 2 * acceleration * displacement )) * (10 ** decimals )) / (10 ** decimals )
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
locate (9, 18)
put - finalvelocity : 10 : decimals, "m/s"
locate (10, 2)
dtime1 := round (((finalvelocity - inicialvelocity ) / acceleration ))
put "Time: ", dtime1 : 20 : decimals
locate (11, 8)
dtime2 := round (((-finalvelocity - inicialvelocity ) / acceleration ))
put dtime2 : 20 : decimals
elsif chars ('8') then
locate (5, 2)
put "Displacement: " ..
get displacement
locate (5, 2)
put "Displacement: ", displacement : 12 : decimals, "m"
locate (6, 2)
put "Final Velocity: " ..
get finalvelocity
locate (6, 2)
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
locate (7, 2)
put "Acceleration: " ..
get acceleration
locate (7, 2)
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
locate (8, 2)
inicialvelocity := round ((sqrt ((finalvelocity ** 2) - 2 * acceleration * displacement )) * (10 ** decimals )) / (10 ** decimals )
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
locate (9, 20)
put - inicialvelocity : 8 : decimals, "m/s"
locate (10, 2)
dtime1 := round (((finalvelocity - inicialvelocity ) / acceleration ))
put "Time: ", dtime1 : 20 : decimals, "s"
locate (11, 8)
dtime2 := round (((finalvelocity + inicialvelocity ) / acceleration ))
put dtime2 : 20 : decimals
else
locate (5, 2)
put "Inicial Velocity: " ..
get inicialvelocity
locate (5, 2)
put "Inicial Velocity: ", inicialvelocity : 8 : decimals, "m/s"
locate (6, 2)
put "Final Velocity: " ..
get finalvelocity
locate (6, 2)
put "Final Velocity: ", finalvelocity : 10 : decimals, "m/s"
locate (7, 2)
put "Acceleration: " ..
get acceleration
locate (7, 2)
put "Acceleration: ", acceleration : 12 : decimals, "m/s" + chr (170)
locate (8, 2)
dtime := round (((finalvelocity - inicialvelocity ) / acceleration ) * (10 ** decimals )) / (10 ** decimals )
put "Time: ", dtime : 20 : decimals, "s"
locate (9, 2)
displacement := round ((((finalvelocity + inicialvelocity ) / 2) * dtime ) * (10 ** decimals )) / (10 ** decimals )
put "Displacement: ", displacement : 12 : decimals, "m"
end if
locate (12, 1)
put "Press any key to continue..." ..
getch (ch )
Title ("14", "8")
Font.Free (font )
font := Font.New ("Times New Roman:10")
width := Font.Width ("Would you like to use this program again? (Y/N)", font )
Font.Draw ("Would you like to use this program again? (Y/N)", maxx div 2 - width div 2, maxy div 2 - 10, font, black)
loop
Input.KeyDown (chars )
exit when chars ('y') or chars ('n')
end loop
exit when chars ('n')
end loop
|
|