summaryrefslogtreecommitdiff
path: root/rectangles-borders.html
diff options
context:
space:
mode:
Diffstat (limited to 'rectangles-borders.html')
-rw-r--r--rectangles-borders.html126
1 files changed, 0 insertions, 126 deletions
diff --git a/rectangles-borders.html b/rectangles-borders.html
deleted file mode 100644
index afc153e..0000000
--- a/rectangles-borders.html
+++ /dev/null
@@ -1,126 +0,0 @@
-<!doctype html>
-<html>
-<head>
- <link rel="stylesheet" type="text/css" href="assets/stylesheets/css.css">
-<style type="text/css">
-</style>
-</head>
-<body>
-
-
-</body>
-<script type="text/javascript" src="assets/javascripts/util.js"></script>
-<script type="text/javascript">
-
-(function(){
-
- var canvas = document.createElement("canvas")
- var ctx = canvas.getContext("2d")
- var w = canvas.width = 500
- var h = canvas.height = 500
- document.body.appendChild(canvas)
-
- var rects = []
- var dragging = false
- var mouse = {x:0,y:0,w:0,h:0}
- canvas.addEventListener("mousedown", function(e){
- dragging = true
- mouse.x = e.pageX
- mouse.y = e.pageY
- mouse.w = mouse.h = 0
- })
- canvas.addEventListener("mousemove", function(e){
- if (dragging) {
- mouse.w = e.pageX - mouse.x
- mouse.h = e.pageY - mouse.y
- }
- else {
- mouse.x = e.pageX
- mouse.y = e.pageY
- }
- })
- document.addEventListener("mouseup", function(e){
- if (! dragging) return
- dragging = false
- if (mouse.h != 0 && mouse.w != 0) {
- rects.push(normalize(mouse))
- }
- mouse = {x:e.pageX,y:e.pageY,w:0,h:0}
- })
-
- function animate(){
- requestAnimationFrame(animate)
- ctx.fillStyle = "#fff"
- ctx.fillRect(0,0,w,h)
-
- solve_rects()
- draw_ruler()
- draw_rects()
- draw_mouse()
- }
- animate()
-
- function normalize(rect){
- if (rect.w < 0) {
- rect.x += rect.w
- rect.w = abs(rect.w)
- }
- if (rect.h < 0) {
- rect.y += rect.h
- rect.h = abs(rect.h)
- }
- return rect
- }
- function solve_rects(){
- }
- function draw_ruler(){
- ctx.strokeStyle = "rgba(80,80,80,0.5)"
- ctx.lineWidth = 1
- var len = 5
- for (var i = 0.5; i < w; i += 10) {
- line(i, 0, i, len)
- line(0, i, len, i)
- }
- }
-
- function line (x,y,a,b){
- ctx.beginPath()
- ctx.moveTo(x,y)
- ctx.lineTo(a,b)
- ctx.stroke()
- }
-
- function draw_rects(){
- ctx.strokeStyle = "rgba(80,80,80,0.5)"
- ctx.lineWidth = 1
- // ctx.setLineDash([randint(5)+2,randint(2)+2]);
- ctx.setLineDash([1,1]);
-
- for (var i = 0; i < rects.length; i++) {
- var rect = rects[i]
- ctx.fillStyle = "rgba(0,200,220,0.5)"
- ctx.fillRect(rect.x, rect.y, rect.w, rect.h)
- ctx.strokeRect(rect.x - 0.5, rect.y - 0.5, rect.w+1, rect.h+1)
-
-// line(rect.x, 0, rect.x, rect.y)
-// line(0, rect.y, rect.x, rect.y)
-
- }
- }
- function draw_mouse(){
- if (mouse.w == 0 && mouse.h == 0) {
- ctx.fillStyle = "rgba(255,0,0,0.4)";
- ctx.beginPath();
- ctx.arc(mouse.x, mouse.y, 5, 0, 2*Math.PI, false);
- ctx.fill();
- }
- else {
- ctx.fillStyle = "rgba(255,255,0,0.5)"
- ctx.fillRect(mouse.x, mouse.y, mouse.w, mouse.h)
- }
- }
-
-})()
-
-</script>
-</html>