MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / Ball

Function Ball

assets/js/BouncingBalls.js:50–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48
49// Funtion to make our balls(to set each and every property used to draw a ball)
50function Ball() {
51 this.color = randomColor();
52
53 // to make circle of radius ranging from 14mm to 34mm
54 this.radius = Math.random() * 20 + 14;
55 this.startradius = this.radius;
56 this.x = Math.random() * (tx - this.radius * 2) + this.radius;
57 this.y = Math.random() * (ty - this.radius);
58 this.dy = Math.random() * 2;
59 this.dx = Math.round((Math.random() - 0.5) * 10);
60
61 // velocity of ball.
62 this.vel = Math.random() / 5;
63 this.update = function () {
64
65 // to begin a path of the ball.
66 c.beginPath();
67 // arc function is used to draw a circle.
68 // arc(x coordinate of centre, y coordinate of centre, radius of circle, starting angle, ending angle)
69 c.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
70 c.fillStyle = this.color;
71
72 // fill is used to fill the current drawing path and fillstyle is used to choose the color to be filled
73 c.fill();
74 };
75}
76
77// Array containing all the balls
78let bal = [];

Callers

nothing calls this directly

Calls 1

randomColorFunction · 0.70

Tested by

no test coverage detected