12345678910111213141516171819202122232425262728293031323334353637383940 |
- function BinaryFloater() {
- var x = 10, y = 10, radius = 5;
- var velocity = {x: 1, y: 1};
- var binaryText = "1";
- this.init = function(canvas) {
- x = Math.floor(canvas.width * Math.random());
- y = Math.floor(canvas.height * Math.random());
- velocity.x = Math.floor(10 * Math.random() - 5);
- velocity.y = Math.floor(10 * Math.random() - 5);
- binaryText = (Math.floor(Math.random() * 2) == 0) ? "1" : "0";
- };
- this.update = function(canvas) {
- x += velocity.x;
- y += velocity.y;
- if(x + radius > canvas.width) {
- x = canvas.width - radius;
- velocity.x *= -1.1;
- }
- if(x < radius) {
- x = radius;
- velocity.x *= -1.1;
- }
- if(y + radius > canvas.height) {
- y = canvas.height - radius;
- velocity.y *= -1.1;
- }
- if(y < radius) {
- y = radius;
- velocity.y *= -1.1;
- }
- velocity.x = Math.max(-5, Math.min(5, velocity.x));
- velocity.y = Math.max(-5, Math.min(5, velocity.y));
- },
- this.draw = function(context) {
- context.fillStyle = "#00FF00";
- context.font = "16px Roboto";
- context.fillText(binaryText, x - radius, y + radius);
- }
- }
|