Skip to content

Commit

Permalink
[load] options
Browse files Browse the repository at this point in the history
  • Loading branch information
kaliumxyz committed Sep 19, 2017
1 parent c6f783f commit 4b5354f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 15 deletions.
40 changes: 34 additions & 6 deletions load.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"use strict"

const select = selector => document.querySelector(selector)
function select(selector) {
return document.querySelector(selector)
}

const selectAll = selector => document.querySelectorAll(selector)
function selectAll(selector) {
return document.querySelectorAll(selector)
}

const replaceChar = (string, substring, index) => string.substr(0, index - 1) + substring + string.substr(index)
function replaceChar(string, substring, index) {
return string.substr(0, index - 1) + substring + string.substr(index)
}

const loadScript = _ => {
function loadScript() {
let script = document.createElement("script")
script.setAttribute("src", "main.js")
select("head").appendChild(script)
Expand All @@ -17,6 +23,12 @@ const loadScript = _ => {

const canvas = select('canvas')

const config = {
bounds: true,
gravity: "wiggly",
collisions: "care"
}


window.onresize = _ => {
canvas.width = window.innerWidth
Expand Down Expand Up @@ -58,8 +70,24 @@ const term = {Cursor:{
ghost.innerHTML = match
},
enter: ev => {
if(currentPosition>20 && currentPosition<16)
console.log('blah')
if(10 < currentPosition && 14 > currentPosition) {
config.bounds != config.bounds
}
if(23 < currentPosition && 32 > currentPosition) {
config.gravity = "wiggly"
}
if(32 < currentPosition && 46 > currentPosition) {
config.gravity = "wigglyInverse"
}
if(48 < currentPosition && 57 > currentPosition) {
config.gravity = "regular"
}
if(70 < currentPosition && 79 > currentPosition) {
config.collisions = "boring"
}
if(79 < currentPosition && 86 > currentPosition) {
config.collisions = "care"
}
}
},
}
Expand Down
41 changes: 32 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ keys[77] = mouseNext
* - create gravity well.
* - Adding title randomizer.
* - Add angles.
* - Physics engine.
* - engine in webasm.
*/

/* Global variables.
********************/

const settings = {}
const settings = {type: "square"}

let actions = []

Expand All @@ -53,8 +55,13 @@ let paused = false
/* universal functions.
***********************/

function rand(i) {
i = i || 1
/**
* returns a random number
* @param {Int} i
* @return {Int}
*/

function rand(i = 1) {
return i * Math.random()
}

Expand All @@ -69,7 +76,7 @@ const mouse = {
modus: {
emit: ev => {
return _ => {
particleArr.push(particle(mouse.clone.clientX, mouse.clone.clientY))
particleArr.push(new Particle(mouse.clone.clientX, mouse.clone.clientY))
}
},
bow: ev => {
Expand Down Expand Up @@ -105,6 +112,9 @@ const mouse = {
action: '',
}

/**
* Change the mousemode to the next in the list.
*/

function mouseNext() {
let flag
Expand All @@ -118,8 +128,12 @@ for (let mode in mouse.modus) {

mouse.action = mouse.modus.emit

/**
* Scroll event handler.
* @param {scrollEvent} ev
*/

function scroll(ev) {
function onScroll(ev) {
console.log(ev)
mouseNext()
//scroller(ev.clientX,ev.clientY)
Expand Down Expand Up @@ -217,7 +231,7 @@ class Particle {
}

// location to store the refrences to the particles
const particleArr = []
let particleArr = []

// Overly big render object, might be smarter to do this as a function instead.
const render = {
Expand All @@ -243,7 +257,7 @@ const render = {
gravity.wiggly(particle)
move(particle)
collisions.care(particle)
render.square(particle)
render[settings.type](particle)
})

}
Expand All @@ -255,15 +269,24 @@ const render = {

const gravity = {
boring: entity => {
particleArr.map(particle => {
if (particle !== entity) {
let x = particle.coords.x - entity.coords.x
let y = particle.coords.y - entity.coords.y
force *= entity.mass
particle.acc.x -= force / x
particle.acc.y -= force / y
}

})
},
wigglyRepell: entity => {
const force = 1
particleArr.forEach(particle => {
if (particle !== entity) {
let xDistance = particle.coords.x - entity.coords.x
let yDistance = particle.coords.y - entity.coords.y
force * entity.mass
force *= entity.mass
particle.acc.x += force / xDistance
particle.acc.y += force / yDistance
}
Expand Down Expand Up @@ -351,7 +374,7 @@ function start() {

while (i--)
particleArr.push(new Particle())
console.log(particleArr)
// console.log(particleArr)
}

function main() {
Expand Down

0 comments on commit 4b5354f

Please sign in to comment.