UNPKG

rectangles

Version:

A function collection for working with rectangles

36 lines (23 loc) 855 B
<html> <head> <title>Rectangle Normalization Test</title> </head> <body> <canvas id="canvas"></canvas> <script src="../rectangles.js"></script> <script> function drawRect(a, col) { ctx.fillStyle = col || a.col; ctx.fillRect(a.x1, a.y1, a.x2 - a.x1, a.y2 - a.y1); } var canvas = document.getElementById('canvas'); var ctx = canvas.getContext("2d"); canvas.height = 500; canvas.width = 500; var A = {x2: 20, y2: 20, x1: 100, y1: 100, col: "rgba(255,0,0,0.3)"}; var B = {x1: 20, y1: 20, x2: 100, y2: 100, col: "rgba(0,255,0,0.3)"}; drawRect(Rectangles.normalize(A), A.col); drawRect(Rectangles.normalize(B), B.col); </script> </body> </html>