setup prettier and make all code better

This commit is contained in:
Anton Lavrenov
2017-02-24 09:15:33 -05:00
parent bfb859cfca
commit 59cc7b99f2
124 changed files with 47390 additions and 41165 deletions

View File

@@ -1,105 +1,102 @@
var stage;
var circlesLayer;
var circles;
var stats;
var width = 500;
var height = 300;
var stage;
var circlesLayer;
var circles;
var stats;
var width = 500;
var height = 300;
var VERSION = Konva.version === 'dev' ? 'new' : 'old';
var VERSION = Konva.version === 'dev' ? 'new' : 'old';
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 30);
};
})();
window.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 30);
};
})();
function fpsCounter() {
//fps stat---------------------------
stats = new Stats();
stats.setMode(0);
stats.domElement.style.position = 'fixed';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
$('html').append( stats.domElement );
function fpsCounter() {
//fps stat---------------------------
stats = new Stats();
stats.setMode(0);
stats.domElement.style.position = 'fixed';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
$('html').append(stats.domElement);
}
$(function() {
fpsCounter();
make_stage();
var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'purple'];
var colorIndex = 0;
circles = [];
for (var n = 0; n < 1500; n++) {
(function() {
var color = colors[colorIndex++];
if (colorIndex >= colors.length) {
colorIndex = 0;
}
$(function() {
fpsCounter();
var shape = make_shape(color);
circlesLayer.add(shape);
circles.push(shape);
})();
}
make_stage();
stage.add(circlesLayer);
animate(new Date().getTime());
});
var colors = ["red", "orange", "yellow", "green", "blue", "cyan", "purple"];
var colorIndex = 0;
function animate(lastTime) {
stats.begin();
// update
var date = new Date();
var time = date.getTime();
var timeDiff = time - lastTime;
var period = timeDiff / 1000; //times per second, our period
circles = [];
for(var n = 0; n < 1500; n++) {( function() {
var color = colors[colorIndex++];
if(colorIndex >= colors.length) {
colorIndex = 0;
}
for (var i = 0; i < circles.length; i++) {
var x = Math.round(Math.random() * width);
var y = Math.round(Math.random() * height);
var shape = make_shape(color);
circlesLayer.add(shape);
circles.push(shape);
}());
}
circles[i].setPosition({ x: x, y: y });
}
lastTime = time;
stage.add(circlesLayer);
animate((new Date()).getTime());
circlesLayer.draw();
stats.end();
requestAnimFrame(function() {
animate(lastTime);
});
}
});
function make_shape(color) {
return new Konva.Rect({
fill: color,
width: 10,
height: 10
});
}
function animate(lastTime){
stats.begin();
// update
var date = new Date();
var time = date.getTime();
var timeDiff = time - lastTime;
var period = timeDiff/1000; //times per second, our period
function make_stage() {
stage = new Konva.Stage({
container: 'container',
width: width,
height: height
});
for (var i = 0; i < circles.length; i++) {
var x = Math.round(Math.random() * width);
var y = Math.round(Math.random() * height);
circles[i].setPosition({x: x, y: y});
}
lastTime = time;
circlesLayer.draw();
stats.end();
requestAnimFrame(function(){
animate(lastTime);
});
}
function make_shape(color) {
return new Konva.Rect({
fill: color,
width: 10,
height: 10
});
}
function make_stage() {
stage = new Konva.Stage({
container: "container",
width: width,
height: height
});
if (VERSION === 'new') {
console.log('create fast layer')
circlesLayer = new Konva.FastLayer();
}
else {
console.log('create normal layer')
circlesLayer = new Konva.Layer();
}
}
if (VERSION === 'new') {
console.log('create fast layer');
circlesLayer = new Konva.FastLayer();
} else {
console.log('create normal layer');
circlesLayer = new Konva.Layer();
}
}