Commits

Anonymous committed e8530b1

Make OO more JS-y. Add local copy of (public domain) image.

  • Participants
  • Parent commits aff0772

Comments (0)

Files changed (3)

File javascript/Elevator_1_(PSF).png

Added
New image

File javascript/canvas5.html

 
 </body>
 <script>
-  Canvas5Controller(document.getElementById('canvas')).start();
+  new Canvas5Controller().start(document.getElementById('canvas'));
 </script>

File javascript/canvas5.js

-function Canvas5Controller(canvas) {
-    var self = {};
+Canvas5Controller = function() {
+    var canvas;
     var interval_id;
 
     var img = new Image();
         shapes[i].alpha = Math.random() * 0.66;
     }
 
-    self.draw = function() {
+    this.draw = function() {
         var ctx = canvas.getContext('2d');
 
         ctx.clearRect(0, 0, canvas.width, canvas.height);
         }
     }
 
-    self.start = function() {
+    this.start = function(c) {
+        canvas = c;
         for (var i = 0; i < NUM_SHAPES; i++) {
             shapes[i] = {};
             new_shape(i);
         }
+        var self = this;
         img.onload = function() {
             self.draw();
             interval_id = setInterval(self.draw, 20);
         }
-        img.src = 'http://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Elevator_1_%28PSF%29.png/640px-Elevator_1_%28PSF%29.png';
+        // http://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Elevator_1_%28PSF%29.png/640px-Elevator_1_%28PSF%29.png
+        img.src = 'Elevator_1_(PSF).png';
     }
 
-    self.stop = function() {
+    this.stop = function() {
         if (interval_id === undefined)
             return;
         clearInterval(interval_id);
         interval_id = undefined;
     }
-
-    return self;
 }