Atoms <<
Previous Next >> RLearning
Samples
Source Codes:
<div class="glowscript" id="glowscript">
<script type="text/javascript" src="https://s3.amazonaws.com/glowscript/lib/jquery/2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://s3.amazonaws.com/glowscript/lib/jquery/2.1/jquery-ui.custom.min.js"></script>
<script type="text/javascript" src="https://s3.amazonaws.com/glowscript/package/glow.3.0.min.js"></script>
<script type="text/javascript">
// START JAVASCRIPT
;(function() {;
async function __main__() {
"use strict";
var version = ["3.0", "glowscript"];
Array.prototype.toString = function() { return __parsearray(this) };
var scene = canvas();
var vector = vec;
scene.title = "A ball bounces in a box"
var side = 4.0
var thk = 0.3
var s2 = 2["*"](side)["-"](thk)
var s3 = 2["*"](side)["+"](thk)
var wallR = box ( {pos:vec( side, 0, 0), size:vec(thk,s2,s3), color : color.red} )
var wallL = box ( {pos:vec(side["-u"](), 0, 0), size:vec(thk,s2,s3), color : color.red} )
var wallB = box ( {pos:vec(0, side["-u"](), 0), size:vec(s3,thk,s3), color : color.blue} )
var wallT = box ( {pos:vec(0, side, 0), size:vec(s3,thk,s3), color : color.blue} )
var wallBK = box( {pos:vec(0, 0, side["-u"]()), size:vec(s2,s2,thk), color : color.gray(0.7)} )
var ball = sphere ( {color : color.green, size : 0.8["*"](vec(1,1,1))} )
ball.mass = 1.0
ball.p = vec (0.15["-u"](), 0.23["-u"](), 0.27)
attach_trail(ball, {pps:200, retain:100, color:ball.color})
side = side["-"](thk["*"](0.5))["-"](ball.size.x["/"](2))
var dt = 0.3
while ( true) {
// The rate statement tells GlowScript to execute the while statements
// about 200 times per second. The "wait" keyword is necessary to permit
// periodic updates to the window.
await rate(200)
ball.pos = ball.pos["+"](ball.p["/"](ball.mass)["*"](dt))
if (! (side["-u"]()["<"](ball.pos.x) && ball.pos.x["<"](side))) {
ball.p.x = ball.p.x["-u"]()
}
if (! (side["-u"]()["<"](ball.pos.y) && ball.pos.y["<"](side))) {
ball.p.y = ball.p.y["-u"]()
}
if (! (side["-u"]()["<"](ball.pos.z) && ball.pos.z["<"](side))) {
ball.p.z = ball.p.z["-u"]()
}
}
}
;$(function(){ window.__context = { glowscript_container: $("#glowscript").removeAttr("id") }; __main__() })})()
// END JAVASCRIPT
</script>
</div>
Atoms <<
Previous Next >> RLearning