Skip to content
Snippets Groups Projects
Commit 13de262b authored by Michael Leuschel's avatar Michael Leuschel
Browse files

add physics example

parent 2f5012a6
No related branches found
No related tags found
No related merge requests found
*.prob
MACHINE MovingParticles
DEFINITIONS
MASS == FLOAT;
POS == FLOAT;
SPEED == FLOAT;
OBJ == 1..n
ABSTRACT_CONSTANTS sum_vec
CONSTANTS mass, n
PROPERTIES
n : 1..10 &
mass : OBJ --> MASS &
sum_vec = %(v1,v2).(v1:OBJ-->REAL & v2:OBJ-->REAL | %i.(i:OBJ| v1(i)+v2(i)))
& n = 3 & mass = [1.0, 100.0, 2.0]
VARIABLES xpos, ypos, xspeed, yspeed
INVARIANT
xpos : OBJ --> POS &
ypos : OBJ --> POS &
xspeed : OBJ --> SPEED &
yspeed : OBJ --> SPEED
INITIALISATION xpos := [ -1.0, 0.0 , 1.0 ] ||
ypos := [ 0.0, 0.0, 0.0 ] ||
xspeed := [ 0.0, 0.0, 0.0 ] ||
yspeed := [ 1.0, 0.0, -1.0 ]
OPERATIONS
Move = BEGIN
xpos := sum_vec(xpos,xspeed) ||
ypos := sum_vec(ypos,yspeed)
END
END
{
"svg": "three_bodies.svg",
"items": [
{
"for": {"from":1, "to":3},
"id": "body%0",
"attr": "cx",
"value" : "10.0*xpos(%0)"
},
{
"for": {"from":1, "to":3},
"id": "body%0",
"attr": "cy",
"value" : "10.0*ypos(%0)"
},
{
"for": {"from":1, "to":3},
"id": "body%0",
"attr": "r",
"value" : "2.0+mass(%0)/10.0"
}
],
"events": [
{
"for": {"from":1, "to":3},
"id": "body%0",
"event": "Move",
"hovers": [{ "attr":"stroke-width", "enter":"6", "leave":"1"},
{ "attr":"opacity", "enter":"0.8", "leave":"1.0"}]
}
]
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns="http://www.w3.org/2000/svg"
height="400" width="400"
viewBox="-100 -100 200 200"
>
<circle id="body1" cx="45" cy="15" r="25"
stroke="black" stroke-width="1" fill="green" />
<circle id="body2" cx="5" cy="15" r="5"
stroke="black" stroke-width="1" fill="red" />
<circle id="body3" cx="35" cy="45" r="20"
stroke="black" stroke-width="1" fill="blue" />
</svg>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment