Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ctx = null;
- var canvas = null;
- var mousedownX = 0;
- var mousedownY = 0;
- var mouseupX = 0;
- var mouseupY = 0;
- var debugtxt = "";
- var mouseisup = true;
- $(document).ready(function () {
- window.setInterval(loop, dt * 1000);
- $(document).mousedown(function (e) {
- if (e.which == 1) {
- var offset = $("#canvas").offset();
- mousedownX = Math.floor(e.pageX - offset.left);
- mousedownY = Math.floor(e.pageY - offset.top);
- mouseisup = false;
- mouseDown();
- //debugtxt = offset.left + " " + offset.top;
- }
- });
- $(document).mouseup(function (e) {
- if (e.which == 1) {
- var offset = $("#canvas").offset();
- mouseupX = Math.floor(e.pageX - offset.left);
- mouseupY = Math.floor(e.pageY - offset.top);
- mouseisup = true;
- mouseUp();
- }
- });
- canvas = document.getElementById('canvas');
- ctx = canvas.getContext('2d');
- })
- function clearScreen() {
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- }
- function drawRect(color, a, b, c, d) {
- ctx.strokeStyle = color;
- ctx.strokeRect(a, b, c, d);
- }
- function fillRect(color, a, b, c, d) {
- ctx.fillStyle = color;
- ctx.fillRect(a, b, c, d);
- }
- function drawImage(image, x, y, w, h) {
- ctx.drawImage(image, x, y, w, h);
- }
- function drawCircle(color, x, y, r) {
- ctx.beginPath();
- ctx.arc(x, y, r, 0, 2 * Math.PI, false);
- ctx.strokeStyle = color;
- ctx.stroke();
- }
- function fillCircle(color, x, y, r) {
- ctx.beginPath();
- ctx.arc(x, y, r, 0, 2 * Math.PI, false);
- ctx.fillStyle = color;
- ctx.fill();
- }
- function drawLine(color, startx, starty, endx, endy) {
- ctx.beginPath();
- ctx.moveTo(startx, starty);
- ctx.lineTo(endx, endy);
- ctx.strokeStyle = color;
- ctx.closePath();
- ctx.stroke();
- }
- function fillText(str, x, y) {
- ctx.fillText(str, x, y);
- }
- function random(n) {
- return Math.floor(Math.random()*(n+1));
- }
- function randomcolor() {
- return "rgba(" + random(255) + "," + random(255) + "," + random(255) + "," + random(100)/100 + ")";
- }
- clearscreen = clearScreen;
- drawrect = drawRect;
- fillrect = fillRect;
- drawimage = drawImage;
- drawcircle = drawCircle;
- drawline = drawLine;
- fillcircle = fillCircle;
- filltext = fillText;
- mousedown = mouseDown;
- randomcolour = randomcolor;
Add Comment
Please, Sign In to add comment