Elasticity in rope simulation
Author |
Message |
TheOneTrueGod
![](http://www.drmcninja.com/images/mcninjab3.jpg)
|
Posted: Sat Apr 22, 2006 10:23 am Post subject: Elasticity in rope simulation |
|
|
A rope simulator. Simulates very elastic rope. Astonishing . the rope is tied to the mouse and there is a weight on the end. If the weight sinks below the length of the rope, tension pulls it back up, and if its above, gravity pulls it down. Use w/a/s/d to apply a force on the rope.
code: |
const Tension := 1.3
const Length := 50
const maxspeed := 10
const gravity := 0.7
const loss := 1.1
function Angle (x1, y1, x2, y2 : real) : real
var theta : real
if x1 = x2 then
if y2 > y1 then
theta := 90
else
theta := 270
end if
else
theta := arctand ((y1 - y2) / (x1 - x2))
if x2 > x1 then
if y2 > y1 then
else
theta := 360 + theta
end if
else
theta := 180 + theta
end if
end if
result theta
end Angle
function Dist (x1, y1, x2, y2 : real) : real
result sqrt ((x2 - x1) ** 2 + (y2 - y1) ** 2)
end Dist
var mx, my, button : int
var x, y, xs, ys : real := 0
x := 100
y := 100
var keys : array char of boolean
View.Set ('offscreenonly')
loop
mousewhere (mx, my, button)
Input.KeyDown (keys)
x += xs
y += ys
if keys ('d') then
xs += 1
elsif keys ('a') then
xs -= 1
end if
if keys ('s') then
ys -= 1
elsif keys ('w') then
ys += gravity * 0.9
end if
ys -= gravity
drawline (mx, my, round (x), round (y), black)
drawfilloval (round (x), round (y), 5, 5, black)
xs /= loss
ys /= loss
if Dist (x, y, mx, my) > Length then
xs += cosd (Angle (x, y, mx, my)) * Tension * Dist (x, y, mx, my) / Length
ys += sind (Angle (x, y, mx, my)) * Tension * Dist (x, y, mx, my) / Length
end if
View.Update
Time.DelaySinceLast (30)
cls
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Kactus
|
Posted: Sat Apr 22, 2006 2:53 pm Post subject: (No subject) |
|
|
wow this is cool! i played with it for a good 30 mins! lol |
|
|
|
|
![](images/spacer.gif) |
upthescale
|
Posted: Sat Apr 22, 2006 3:44 pm Post subject: (No subject) |
|
|
wow do u have a life man i looked at that code with aw
[mod:0f446bb8df="Cervantes"]
Nice comment. You have been warned a great many times about breaking [the rules]. In this case, you are breaking the flaming rule. In other words, you are flaming. That's not allowed.
As I was saying, you have been warned a great many times. Continue and you will be banned.
Furthermore, what is "aw"?
[/mod:0f446bb8df] |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Sun Apr 23, 2006 10:38 am Post subject: (No subject) |
|
|
I think he forgot an e? but anyways, nice code man, as soon as I finish trig and start grade 11 physcis LOL, I would try to make similar programs, really cool, the concept could be extended for the use of AI and missile tracker? lol ![Laughing Laughing](http://compsci.ca/v3/images/smiles/icon_lol.gif) |
|
|
|
|
![](images/spacer.gif) |
TheOneTrueGod
![](http://www.drmcninja.com/images/mcninjab3.jpg)
|
Posted: Sun Apr 23, 2006 1:54 pm Post subject: (No subject) |
|
|
Thanks for the praise. Yes, the concepts shown here areused in all of my AI / tracking. This specific example, I was planning on using in a spiderman-esque game.
sin(theta) and cos(theta) are really fun concepts (I find), as they can even apply to 3-D systems (As is shown in my RPG Shameless Plug ) |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Mon Apr 24, 2006 6:35 pm Post subject: (No subject) |
|
|
very cool man, i cant wait until i learn the physics and stuff to be able to do that, then ill be able to do stuff like that, very cool, although i think you should be able to like sling the elastic across the screen with w|a|s|d keys, but meh, gj |
|
|
|
|
![](images/spacer.gif) |
rownale
|
|
|
|
![](images/spacer.gif) |
BenLi
![](http://compsci.ca/v3/uploads/user_avatars/17704181124608ffcaeb421.gif)
|
Posted: Sun Apr 30, 2006 4:48 pm Post subject: (No subject) |
|
|
very nice, any games planned form this? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|