HTML and CSS Reference
In-Depth Information
Code
Explanation
}
Close the function
function moveball(dx,dy) {
Header for the
moveball
function
this.sx +=dx;
Increment the
sx
property by
dx
Increment the
sy
property by
dy
this.sy +=dy;
}
Close function
var cball = new Ball(iballx,ibally,
10,"rgb(250,0,0)");
Create a new
Ball
object at the indicated position,
radius, and color. Assign it to the variable
cball
. Note
that nothing is drawn at this time. The information is just
set up for later use.
function Myrectangle(sx,sy,swidth,
sheight,stylestring) {
Header for function to construct a
Myrectangle
object
Sets the
sx
property of
THIS
object
this.sx = sx;
this.sy = sy;
…
sy
this.swidth = swidth;
…
swidth
this.sheight = sheight;
…
sheight
this.fillstyle = stylestring;
…
stylestring
this.draw = drawrects;
…
draw
. This sets up a method that can be invoked.
this.moveit = moveball;
….
moveit
. This sets up a method that can be invoked.
It is not used in this program.
}
Close
Myrectangle
function
function drawrects() {
Header for
drawrects
function
ctx.fillStyle = this.fillstyle;
Set the
fillStyle
ctx.fillRect(this.sx,this.sy,
this.swidth,this.sheight);
Draw the rectangle using the object properties
}
Close function