Skip to content

Commit

Permalink
add png compress version
Browse files Browse the repository at this point in the history
  • Loading branch information
lo-th committed Mar 27, 2014
1 parent 1a92f23 commit aa29a6d
Show file tree
Hide file tree
Showing 9 changed files with 526 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ It's a full javascript conversion of [OimoPhysics](https://github.com/saharan/Oi
created by [Saharan](https://el-ement.com/blog/) on ActionScript 3.0.<br>


Demo with three.js and worker:
Home Demo with three.js and worker:

[oimo.js dev](https://lo-th.github.io/Oimo.js/index.html)

Expand All @@ -22,4 +22,8 @@ Basic demo no worker

Basic demo worker transferrable

[worker test](https://lo-th.github.io/Oimo.js/test_worker.html)
[worker test](https://lo-th.github.io/Oimo.js/test_worker.html)

Basic demo from png compression (dev:31kb rev:29kb)

[png test](https://lo-th.github.io/Oimo.js/test_basic_png.html)
1 change: 0 additions & 1 deletion build/Oimo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion build/Oimo.rev.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added images/oimo.dev.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/oimo.rev.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions js/PngSourceLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

var PngSourceLoader = function (file, end) {
var xhr = new XMLHttpRequest();
xhr.open( 'GET', file, true );
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.readyState == 4 ) {
var blob = this.response;
var img = document.createElement('img');
img.onload = function(e) {
var c=document.createElement("canvas"), pix, i, string = "";
c.width = this.width;
c.height = this.height;
c.getContext('2d').drawImage(this, 0, 0);
var d = c.getContext('2d').getImageData(0, 0, c.width, c.height).data;
for ( i = 0, l=d.length; i<l; i+=4){
pix = d[i];
if( pix<96 ) string += String.fromCharCode(pix+32);
}

var nn = string.indexOf("var");
var pn = string.indexOf("=");
var name = string.substring(nn+4,pn);
var sc = document.createElement("script");
sc.type = "text/javascript";
sc.id = name;
sc.charset = "utf-8";
sc.async = true;
sc.textContent = string;
document.getElementsByTagName('head')[0].appendChild(sc);

end();

window.URL.revokeObjectURL(img.src); // Clean up after yourself.
}
img.src = window.URL.createObjectURL(blob);
}
}
xhr.send( null );
}
Loading

0 comments on commit aa29a6d

Please sign in to comment.