diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13abef4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +node_modules/* +npm_debug.log diff --git a/index.html b/index.html new file mode 100644 index 0000000..41ce8c8 --- /dev/null +++ b/index.html @@ -0,0 +1,145 @@ + + + + + + + + + + \ No newline at end of file diff --git a/lib/vector.js b/lib/vector.js new file mode 100644 index 0000000..97e109a --- /dev/null +++ b/lib/vector.js @@ -0,0 +1,112 @@ + +function v(x, y) { + return new Vector(x, y) +} + +Vector.a2v = function (a) { return new Vector(Math.cos(a), Math.sin(a)) } +function r() { + return Math.random()*2 - 1 +} +Vector.random = function (x,y) { + return new Vector(r()*x, r()*y) +} +Vector.center = function () { + var c = new Vector(0,0) + for (var i = 0; i < arguments.length; i ++) { + c.iadd(arguments[i]) + } + return c.idiv(arguments.length) +} + +function Vector (x, y) { + if('object' === typeof x && x) { + this.x = x.x || 0; + this.y = x.y || 0; + } else { + this.x = x || 0; + this.y = y || 0; + } +} + +Vector.prototype = { + dot: function (v) { + return this.x * v.x + this.y * v.y + }, + length: function () { + return Math.sqrt(this.x*this.x + this.y*this.y) + }, + iadd: function (v) { + this.x += v.x; + this.y += v.y; + return this; + }, + isub: function (v) { + this.x -= v.x; + this.y -= v.y; + return this; + }, + imul: function (scalar) { + this.x *= scalar; + this.y *= scalar; + return this; + }, + idiv: function (scalar) { + this.x /= scalar; + this.y /= scalar; + return this; + }, + izero: function () { + this.x = 0; + this.y = 0; + return this; + }, + inor: function () { + var l = this.length(); + this.x /= l; + this.y /= l; + return this; + }, + iabs: function () { + this.x = Math.abs(this.x) + this.y = Math.abs(this.y) + return this + }, + add: function (v) { + return new Vector(this).iadd(v); + }, + sub: function (v) { + return new Vector(this).isub(v); + }, + mul: function (v) { + return new Vector(this).imul(v); + }, + div: function (v) { + return new Vector(this).idiv(v); + }, + nor: function () { + return new Vector(this).inor(); + }, + abs: function () { + return new Vector(this).iabs(); + }, + //always positive + diff: function (v) { + return new Vector( + Math.abs(this.x - v.x), + Math.abs(this.y - v.y) + ) + }, + //distance between this and the other point. + dist: function (v) { + return this.diff(v).length() + }, + angle: function () { + return Math.atan(this.x/this.y) * (this.x > 0 ? 1 : -1 ) + }, + clone: function () { + return new Vector(this) + }, + toString: function () { + return '('+this.x+','+this.y+')' + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..63d0bbb --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ "name": "phyxel" +, "version": "0.0.0" +, "description": "" +, "homepage": "http://github.com/dominictarr/phyxel" +, "repository": + { "type": "git" + , "url": "https://github.com/dominictarr/phyxel.git" } +, "dependencies": {} +, "devDependencies": {} +, "author": "Dominic Tarr (http://bit.ly/dominictarr)" +, "scripts": { "test": "meta-test test/*.js" } } \ No newline at end of file diff --git a/readme.markdown b/readme.markdown new file mode 100644 index 0000000..8d60f0a --- /dev/null +++ b/readme.markdown @@ -0,0 +1,37 @@ +# Phyxel + +experimental voxel based 2d physics. + + +THIS IS JUST A ORBIT SIMULATOR, FOR NOW + + +CRAZY IDEA + +fluids: + + gas light, non dense, possibly moving partices, not sticky. + + liquids: denser, sticky, surface tension. + +solids: + + solid: dense, stiffly stuck to other solid things, but can be flexible or brittle. + connections can have a direction, so a chain can have stiffness, and brittleness. + +advantages: + + simpler simulation, + each phyxel has a few simple properties, that my affect neibouring phyxels. (say, 6) + instead of having alot of complicated rules and checks. just make every thing a circle. + +ideas: + + would be cool to be able to freeze or melt parts of a game level, + freeze to make it brittle, then smash it. melt through things, + float on water or fly in the air maybe? + + maybe it'll be better to make the phyxels "large"... and lift wont work right. + that is okay, also, the entities in the game might be werid. walking and stuff... + maybe should just have them roll sideways, hover, or allow a few 'magical' forces. +