Last active
September 29, 2018 20:08
-
-
Save HilmiZul/be86244668ebca57924edc0c038a656e to your computer and use it in GitHub Desktop.
catatan kecil simulasi benda (seolah) jatuh.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* grav.js | |
* 30 September 2018, 3:00 A.M. | |
*/ | |
function grav() { | |
this.g = 0.9; // gravitasi | |
this.vel = 0; // init 0 yang nanti ditambah dengan nilai gravitasi saat benda jatoh. | |
// saat benda jatoh: | |
// kecapatan benda akan terus bertambah dengan tarikan gravitasi? | |
// posisi benda ditambah dengan kecepatan yang terus bertambah selama benda- | |
// belum sampe tanah... | |
this.fall = function() { | |
this.vel += this.g; | |
this.posBenda += this.vel; | |
}; | |
// cek, apakah benda udah jatoh ke tanah? | |
this.check = function() { | |
if (this.posBenda > this.heightBenda - (this.r / 2)) { | |
this.posBenda = this.heightBenda - (this.r / 2)); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment