div {
position: absolute;
margin: 120px;
width: 120px;
height: 120px;
-webkit-animation: infinite rotate-block 2s;
-moz-animation: infinite rotate-block 2s;
-o-animation: infinite rotate-block 2s;
animation: infinite rotate-block 2s;
border-left:10px solid #f15466;
border-radius: 50%
}
@-webkit-keyframes rotate-block {
0% {-webkit-transform: rotate(0deg);}
100% {-webkit-transform: rotate(360deg);}
}
@-moz-keyframes rotate-block {
0% {-moz-transform: rotate(0deg);}
100% {-moz-transform: rotate(360deg);}
}
@-o-keyframes rotate-block {
0% {-o-transform: rotate(0deg);}
100% {-o-transform: rotate(360deg);}
}
@keyframes rotate-block {
0% {transform: rotate(0deg);}
100% {transform: rotate(360deg);}
}
var Human = function (coords) {
this.top = coords.top || 0;
this.left = coords.left || 0;
};
Human.prototype = {
go: function (coords) {
this.top += coords.top || 0;
this.left += coords.left || 0;
return this;
},
goUp: function () {
return this.go({top: -1});
},
goDown: function () {
return this.go({top: 1});
},
goLeft: function () {
return this.go({left: -1});
},
goRight: function () {
return this.go({left: 1});
}
};
var vagabond = new Human({
top: 2,
left: 2
});
vagabond.goUp().goLeft().goDown().goDown().goRight();
vagabond.go({
top: 0,
left: 0
});
function Human(x, y) {
this.x = x;
this.y = y;
}
Human.prototype = {
goUp: function () {
this.y++;
return this;
}
goDown: function () {
this.y--;
return this;
}
// ...
}
function coordsChangerFactory(prop, direction) {
return function () {
// тут можно добавить валидацию, мол что бы не вылазить за пределы поля
this[prop] += direction;
return this;
}
}
function Human(x, y) {
this.x = x;
this.y = y;
}
Human.prototype = {
goUp: coordsChangerFactory('y', +1),
goDown: coordsChangerFactory('y', -1),
goLeft: coordsChangerFactory('x', -1),
goRight: coordsChangerFactory('x', +1)
}
var man = new Human(4, 4);
man.goDown().goRight();
console.log('Coords is %dx%d', man.x, man.y); // Coords is 5x3
class BrightControl
public void setDefaultBright(Object obj){
obj.setBright(10);
}
}