Skip to content

Commit

Permalink
Adding what I'll call... giggle gravity
Browse files Browse the repository at this point in the history
  • Loading branch information
kaliumxyz committed Apr 20, 2017
1 parent 7872402 commit 2af081c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<html>
<head>
<title>ASAP</title>
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
<link href='style.css' rel='stylesheet'>
</head>
<body>
<canvas width="1000" height="1000">If you can read this, your browser does not support HTML5 canvas.</canvas>
<h1>press space</h1>
<canvas width="1000" height="1000">If you can read this, your browser does not support HTML5 canvas.</canvas>
</body>
<script src='load.js'></script>
</html>
2 changes: 2 additions & 0 deletions load.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const loadScript = _ => {
let script = document.createElement("script")
script.setAttribute("src","main.js")
select("head").appendChild(script)
select('h1').innerText = "A Simple Aestetic Particle engine"
}

const canvas = select('canvas')


window.onresize = _ => {
canvas.width = window.innerWidth
canvas.height = window.innerHeight
Expand Down
38 changes: 28 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ window.onkeydown = e => e.keyCode===32?start():e


const mouse = {
emit : ev => particleArr.push(particle(ev.clientX,ev.clientY)),
pew : ev => {
let i = 10
emit : ev => {
let i = 1
while (i--){
particleArr.push(particle(ev.clientX,ev.clientY))
}},
pew : ev => {
let i = 1000
while (i--){
particleArr[i] = (particle(ev.clientX,ev.clientY))
}
},
}

window.onclick = mouse.pew
window.onclick = mouse.emit

const rand = i => {
i = i || 1
Expand Down Expand Up @@ -87,20 +91,32 @@ const render = {

// Moving stuff here.

const gravity = (particle, entity) => {
const gravity = entity => {
const force = 9.81
const distance = {
x: particle.coords.x - entity.coords.x,
y: particle.coords.y - entity.coords.y,
}
// logic here :p.
particleArr.forEach(particle => {

let x = particle.coords.x - entity.coords.x
let y = particle.coords.y - entity.coords.y

if (particle !== entity){
particle.acc.x += 1 / x
particle.acc.y += 1 / y
}
// actually implement gravity pl0x
})
}

const move = particle => {
particle.coords.x += particle.acc.x
particle.coords.y += particle.acc.y
}

// collision stuff here.

const checkWithinBounds = entity => {

}

const collide = entity => {
particleArr.forEach(particle => entity.coords == particle.coords ? particle.color = "": "" )
}
Expand Down Expand Up @@ -130,7 +146,9 @@ const main = _ => {
context.fillStyle='#FFF'
context.fillRect(0,0,canvas.width,canvas.height)
particleArr.forEach( particle => {
gravity(particle)
move(particle)
checkWithinBounds(particle)
render.square(particle)
})
}
Expand Down
7 changes: 7 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ html, body, canvas {
margin: 0;
padding: 0;
overflow: hidden;
font-family: 'Roboto Mono', monospace;
}
h1 {
width: 100%;
top: 80px;
position: fixed;
text-align: center;
}

0 comments on commit 2af081c

Please sign in to comment.