drawEquation(), Graph - , . , ( ),
function(x) = Math.sin(x);
, . TransformContext() canvas, y , :
Graph.prototype.transformContext = function(){
var canvas = this.canvas;
var context = this.context;
this.context.translate(this.centerX, this.centerY);
context.scale(this.scaleX, -this.scaleY);
};
Graph.prototype.drawEquation = function(equation, color, thickness){
var canvas = this.canvas;
var context = this.context;
context.save();
this.transformContext();
context.beginPath();
context.moveTo(this.minX, equation(this.minX));
for (var x = this.minX + this.iteration; x <= this.maxX; x += this.iteration) {
context.lineTo(x, equation(x));
}
context.restore();
context.lineJoin = "round";
context.lineWidth = thickness;
context.strokeStyle = color;
context.stroke();
};