我使用本教程:http://www.html5canvastutorials.com/labs/html5-canvas-graphing-an-equation/在HTML5作圖的線性方程
裏面drawEquation
方法,有被稱爲另一種方法transformContext
(線153):
transformContext = function() {
var context = this.context;
// move context to center of canvas
this.context.translate(this.centerX, this.centerY);
/*
* stretch grid to fit the canvas window, and
* invert the y scale so that that increments
* as you move upwards
*/
context.scale(this.scaleX, -this.scaleY);
};
該方法使得可以繪製方程式來引用0,0 origin
而不是畫布的左上角原點(我知道這一點,因爲我評論了它並觀察了結果)。但是,我不明白這種方法內發生了什麼。畫布中心的translate
和scale
如何能夠從原點繪製方程式?
代碼中的註釋也沒有幫助。如何移動環境或拉伸它造成這種影響?
請幫助。