Some Math
Author |
Message |
Nick
|
Posted: Thu Apr 24, 2008 2:42 am Post subject: Some Math |
|
|
I got bored so here's three math programs
1. Line Mouse Follower:
code: | View.Set ("offscreenonly")
var mx, my, mb : int
loop
cls
Mouse.Where (mx, my, mb)
if mx ~= 0 then
drawline (0, 0, maxx, round ((my / mx) * maxx), black)
if my ~= 0 then
drawline (0, maxy, maxx, round (((my - maxy) / mx) * maxx) + maxy, black)
end if
end if
View.Update
end loop
|
2. Parabola:
code: | const SPACE : int := 1
const A := 0.5
const P := 10
const Q := 50
const RANGE := 50
for x : -RANGE .. RANGE by SPACE
drawline (x + RANGE, round (A * ((x - P) ** 2) + Q), x + RANGE + SPACE, round (A * ((x - P + SPACE) ** 2) + Q), black)
end for
|
3. Sinusoidal:
code: | const A := 1
const C := 90
const D := 0
const MULTIPLIER := 45
const SPACE := 1
for x : 0 .. maxx by 45
for y : 0 .. maxy by 45
drawline (x, y, x + 45, y, black)
drawline (x, y, x, y + 45, black)
end for
end for
Font.Draw ("(0,-1)", 5, 35, Font.New ("arial:10"), black)
Font.Draw ("(0,0)", 5, 80, Font.New ("arial:10"), black)
Font.Draw ("(0,1)", 5, 125, Font.New ("arial:10"), black)
Font.Draw ("(PI,0)", 185, 80, Font.New ("arial:10"), black)
for x : 0 .. 360 by SPACE
drawline (x, round (MULTIPLIER * A * sind (x - D) + C),
x + SPACE, round (MULTIPLIER * A * sind (x + SPACE - D) + C), black)
end for
|
feel free to change the constant values for 2 and 3 to see what happens
EDIT: added in grid and fixed the spacing in 3 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
repsoccer16
|
Posted: Thu Apr 24, 2008 7:17 am Post subject: RE:Some Math |
|
|
good job all good programs for math use |
|
|
|
|
|
petree08
|
Posted: Thu Apr 24, 2008 9:52 am Post subject: RE:Some Math |
|
|
your sine function program was very functional,
I like!
we serously need more math/physics/system opertation. programs on this site |
|
|
|
|
|
Mackie
|
Posted: Thu Apr 24, 2008 8:33 pm Post subject: RE:Some Math |
|
|
I like it, first one was very slow for me though, and i have a faster computer than you!... I was going to make a parabola program though.... Thief! |
|
|
|
|
|
CodeMonkey2000
|
Posted: Thu Apr 24, 2008 8:39 pm Post subject: RE:Some Math |
|
|
What? This is very basic and uninteresting math. |
|
|
|
|
|
syntax_error
|
Posted: Thu Apr 24, 2008 9:47 pm Post subject: RE:Some Math |
|
|
meh, there isnt much of it, so its not that bad, for such a comment.
meliked. |
|
|
|
|
|
Nick
|
Posted: Thu Apr 24, 2008 10:09 pm Post subject: RE:Some Math |
|
|
thank you for the comments, I just did this bored one night, who cares if it's simple, the sine/cosine waves give cool effects plus the line mouse follower can be useful for some people (for shooters) |
|
|
|
|
|
Michael516
|
Posted: Wed Apr 30, 2008 7:52 am Post subject: RE:Some Math |
|
|
i like how in the first one the lines would follow the mouse, that was neat. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Nick
|
Posted: Sat May 17, 2008 3:50 am Post subject: RE:Some Math |
|
|
when I first did this Saad told me to make a procedure that takes in a function as an argument so I would have a single procedure to draw an function, I told him later.
I finally got around to doing it, however with this being Turing and all some functions are a litlle glitchy, anyways here's the code:
code: | fcn sinWave (x, a, b, c, d : real) : int
result round (a * sind (b * x - d) + c)
end sinWave
fcn para (x, a, b, c, d : real) : int
result round (a * ((b * x - d) ** 2) + c)
end para
fcn xSqrt (x, a, b, c, d : real) : int
if x < 0 then
result - 1
end if
result round (a * sqrt (b * x - d) + c)
end xSqrt
fcn line (x, a, b, c, d : real) : int
result round (a * (b * x - d) + c)
end line
proc drawFunction (a, b, c, d : real, range : int, funct : fcn funct (x, a, b, c, d : real) : int, inverse : boolean, color : int)
for x : 0 .. range
if inverse then
drawline (funct (x, a, b, c, d), x, funct (x + 1, a, b, c, d), x, color)
else
drawline (x, funct (x, a, b, c, d), x, funct (x + 1, a, b, c, d), color)
end if
end for
end drawFunction
drawFunction (50, 1, 100, 0, maxx, sinWave, false, black)
drawFunction (1 / 2, 1, 10, 50, 100, para, false, black)
drawFunction (2, 3, 50, 0, maxx, xSqrt, false, black)
drawFunction (1, 1, 0, 0, maxx, line, false, black)
drawFunction (50, 1, 100, 0, maxx, sinWave, true, black)
drawFunction (1 / 2, 1, 10, 50, 100, para, true, black)
drawFunction (2, 3, 50, 0, maxx, xSqrt, true, black)
drawFunction (1, 1, 0, 0, maxx, line, true, black)
|
try messing around with it a little bit |
|
|
|
|
|
|
|