最后一段组成Star对象prototype的代码,是被构造函数调用,以及刚刚在动画中随机生成闪光和非闪光颜色的:
317 Star.prototype.randomiseColors = function () {
318 // Give the star a random color for normal
319 // circumstances...
320 this.r = Math.random();
321 this.g = Math.random();
322 this.b = Math.random();
323
324 // When the star is twinkling, we draw it twice, once
325 // in the color below (not spinning) and then once in the
326 // main color defined above.
327 this.twinkleR = Math.random();
328 this.twinkleG = Math.random();
329 this.twinkleB = Math.random();
330 };
这样我们就完成了Star对象的prototype,其中我们建立了一个星星的对象,并且填充了方法来完成绘制和动画。现在,就在这些函数上面你可以看到绘制星星的代码(相当无趣):用第一节课中我们熟知的方法绘制一个正方形,其中需要正确地使用纹理坐标数组、顶点位置数组……
function drawStar() {