Last active
February 12, 2019 19:44
-
-
Save joemfox/d7a6177897d6f634b1e8e9bd177940dc to your computer and use it in GitHub Desktop.
SCRIPT-8
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
| { | |
| "0": { | |
| "0": { | |
| "0": 0 | |
| }, | |
| "1": { | |
| "0": 0, | |
| "1": 1 | |
| }, | |
| "2": { | |
| "0": 0, | |
| "1": 1, | |
| "2": 2 | |
| }, | |
| "3": { | |
| "0": 0, | |
| "1": 1, | |
| "2": 2, | |
| "3": 3 | |
| }, | |
| "4": { | |
| "3": 4 | |
| }, | |
| "5": { | |
| "3": 4 | |
| }, | |
| "6": { | |
| "0": 5, | |
| "3": 4 | |
| }, | |
| "7": { | |
| "0": 5, | |
| "3": 4 | |
| }, | |
| "8": { | |
| "0": 5, | |
| "1": 6, | |
| "3": 4 | |
| }, | |
| "9": { | |
| "0": 5, | |
| "1": 6, | |
| "3": 4 | |
| }, | |
| "10": { | |
| "0": 5, | |
| "3": 4 | |
| }, | |
| "11": { | |
| "0": 5, | |
| "3": 4 | |
| }, | |
| "12": { | |
| "0": 5, | |
| "1": 6, | |
| "3": 4 | |
| }, | |
| "13": { | |
| "0": 5, | |
| "1": 6, | |
| "3": 4 | |
| }, | |
| "14": { | |
| "3": 4 | |
| }, | |
| "15": { | |
| "1": 8, | |
| "2": 7, | |
| "3": 4 | |
| } | |
| } | |
| } |
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
| initialState = { | |
| timeElapsed:0 | |
| } | |
| function distance(p1,p2){ | |
| return Math.abs(Math.hypot(p2.x - p1.x, p2.y - p1.y)) | |
| } | |
| function angle(p1,p2){ | |
| return Math.atan2(p2.y - p1.y, p2.x - p1.x) | |
| } | |
| function sat(){ | |
| this.size = 1 | |
| this.mass = 2 | |
| this.position = { | |
| x:0, | |
| y:Math.random()*10 | |
| } | |
| this.velocity = { | |
| x:Math.random()*15+8, | |
| y:Math.random() * 2 | |
| } | |
| this.active = true | |
| this.color = Math.floor(Math.random()*8) | |
| } | |
| sat.prototype.update = function satUpdate(i,elapsed){ | |
| let gravVector = {x:0,y:0} | |
| range(planets.length).forEach(d => { | |
| let gravForce = (3 * this.mass*planets[d].mass) / Math.pow(distance(this.position,planets[d].position),2) | |
| let gravHeading = angle(this.position,planets[d].position) | |
| gravVector.x += Math.cos(gravHeading) * gravForce | |
| gravVector.y += Math.sin(gravHeading) * gravForce | |
| if(Math.round(this.position.x) === planets[d].position.x && Math.round(this.position.y) === planets[d].position.y){ | |
| this.active = false | |
| } | |
| }) | |
| this.velocity.x += gravVector.x | |
| this.velocity.y += gravVector.y | |
| if(i === 0){ | |
| log(this.velocity) | |
| log(gravVector) | |
| } | |
| this.position.x += this.velocity.x * (elapsed/1000) | |
| this.position.y += this.velocity.y * (elapsed/1000) | |
| if(this.position.x >= 128 || this.position.y >= 128 || this.position.x < -20 || this.position.y < -20){ | |
| this.active = false | |
| } | |
| } | |
| let sats = [new sat()] | |
| let planets = [] | |
| let planet = new sat() | |
| planet.mass = 157 | |
| planet.velocity = 0 | |
| planet.size = 9 | |
| planet.position = {x:80,y:80} | |
| planets.push(planet) | |
| let planet2 = new sat() | |
| planet2.mass = 93 | |
| planet2.velocity = 0 | |
| planet2.size = 3 | |
| planet2.position = {x:60,y:39} | |
| // planets.push(planet2) | |
| update = (state,input,elapsed) => { | |
| state.frameTime = elapsed | |
| state.timeElapsed += elapsed | |
| if(Math.floor(state.timeElapsed)%2 == 0 && sats.length < 4000){ | |
| sats.push(new sat()) | |
| } | |
| sats = sats.filter(d => d.active) | |
| } | |
| draw = (state) => { | |
| clear() | |
| range(sats.length).forEach((d,i) => { | |
| d = sats[d] | |
| d.update(i,state.frameTime,planets[0]) | |
| rectFill(d.position.x,d.position.y, d.size,d.size,d.color) | |
| }) | |
| range(planets.length).forEach(d => { | |
| let p = planets[d] | |
| // circFill(p.position.x, p.position.y, p.size) | |
| }) | |
| } |
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
| [] |
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
| { | |
| "0": [ | |
| "0f37", | |
| "4f#37", | |
| "8e37", | |
| "12f37" | |
| ], | |
| "1": [ | |
| "0f27", | |
| "4f#27", | |
| "8e27", | |
| "12f27" | |
| ], | |
| "2": [ | |
| "0f17", | |
| "4f#17", | |
| "8e17", | |
| "12f17" | |
| ], | |
| "3": [ | |
| "0f07", | |
| "4f#07", | |
| "8e07", | |
| "12f07" | |
| ], | |
| "4": [ | |
| "0f07", | |
| "1f07", | |
| "2f07", | |
| "3f07", | |
| "4f07", | |
| "5f07", | |
| "6f07", | |
| "7f07", | |
| "8f07", | |
| "9f07", | |
| "10f07", | |
| "12f07", | |
| "13f07" | |
| ], | |
| "5": [ | |
| "0c17", | |
| "2g#17", | |
| "4f#17", | |
| "6f17", | |
| "8c17", | |
| "10g#17", | |
| "12f#17", | |
| "14f17" | |
| ], | |
| "6": [ | |
| "0f27", | |
| "2c37", | |
| "4a#27", | |
| "6g#27", | |
| "8f27", | |
| "10c37", | |
| "12a#27", | |
| "14g#27" | |
| ], | |
| "7": [ | |
| "4f12", | |
| "5f12", | |
| "6f12", | |
| "7f12", | |
| "8f12", | |
| "9f12", | |
| "10f12", | |
| "12f22", | |
| "13f22" | |
| ], | |
| "8": [ | |
| "4f22", | |
| "5f22", | |
| "6f21", | |
| "7f21", | |
| "8f21", | |
| "9f22", | |
| "10f22", | |
| "12f32", | |
| "13f32" | |
| ] | |
| } |
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
| { | |
| "0": { | |
| "0": 0 | |
| } | |
| } |
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
| { | |
| "0": [ | |
| " 33 ", | |
| " 1111 ", | |
| " 100001 ", | |
| "31000013", | |
| "31000013", | |
| " 100001 ", | |
| " 1111 ", | |
| " 33 " | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment