Example 2:
creates many rectangles

View SourceCodeaddRectangle NextStep

Global variables:

              var canvasDiv="viewport";
              var canvasContext;
              var canvasObject;
              var renderObject;
            

Function

              function addRandomRectangle()
              {
                posx=Math.floor((Math.random() * 500) + 1);
                posy=Math.floor((Math.random() * 500) + 1);
                test=new Shape();
                test.createRectangle(posx,posy,100,50);
                renderObject.addRenderElement(test);
              }
            

createRectangle function

              Shape.prototype.createRectangle=function(x,y,width,height)
              {
                this.addMarker(x,y);
                this.addMarker(x+width,y);
                this.addMarker(x+width,y+height);
                this.addMarker(x,y+height);
              }