Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
var rect = rat.rect([10, 10, 200, 200], {
fillStyle: 'red'
});
Rat.Rect = function(opt, style, context){
Rat.init(this, arguments);
};
Rat.Rect.prototype = {
draw: function(ctx){
ctx = ctx || this.context.context;
Rat.style(ctx, this.style);
ctx.rect.apply(ctx, this.opt);
if(this.style.fillStyle)
ctx.fill();
if(this.style.strokeStyle)
ctx.stroke();
ctx.restore();
}
};
Rat.prototype.rect = function(opt, style){
return new Rat.Rect(opt, style, this);
};
var path = rat.path([
['moveTo', 10, 10],
['lineTo', 100, 100],
['lineTo', 10, 100],
['closePath']
], {
fillStyle: 'red',
strokeStyle: 'green',
lineWidth: 4
});
var img = new Image();
img.src = "image.jpg";
img.onload = function(){
img = rat.image(img);
path.draw(); // внимание сюда
}
var path = ctx.path([
// можно точно так же указывать функции ( ['lineTo', x, y] )
[10, 10], // но по умолчанию -- 2 аргумента => lineTo
[100, 100], // а в первом -- moveTo
[10, 100],
true // closePath
], 'red', 'green 4px');
var img = ctx.image('image.jpg', x, y);
var context = document.get('canvas').getContext('2d') //псевдокод
h_context = new function(){
this.chain = function(method, args){
context[method].apply(context, args);
return this;
}
return this;
}
h_context
.chain('beginPath')
.chain('fillRect', [0, 0, window.innerWidth, window.innerHeight]);
//ну или
h_context
.chain('beginPath')
.chain('arc', [/*some, arguments*/])
.chain('fill')
var circle = new createjs.Shape();
circle.graphics.beginFill("DeepSkyBlue").drawCircle(0, 0, 50);
circle.x = 100;
circle.y = 100;
stage.addChild(circle);
// зачем делать так??
context.fillStyle('red').fillRect(10, 10, 200, 200);
// когда можно вот так?
context.fillRect(10, 10, 200, 200, 'red');
100 строк на canvas-е: часть 1