Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created November 6, 2013 13:07
Show Gist options
  • Select an option

  • Save chikoski/7335783 to your computer and use it in GitHub Desktop.

Select an option

Save chikoski/7335783 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<canvas id="canvas" width="480" height="340"></canvas>
</body>
</html>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var width = 480;
var height = 340;
var lines = 1000;
var red = 255;
var green = 255;
var blue = 255;
var opaque = 255;
var drawRondomLine = function(){
var begin_x = Math.floor(Math.random() * width);
var begin_y = Math.floor(Math.random() * height);
var end_x = Math.floor(Math.random() * width);
var end_y = Math.floor(Math.random() * height);
var r = Math.floor(Math.random() * red);
var g = Math.floor(Math.random() * green);
var b = Math.floor(Math.random() * blue);
var a = Math.floor(Math.random() * opaque);
ctx.strokeStyle = "rgba(" + r + "," + g + "," + b + "," + a + ")";
ctx.beginPath();
ctx.moveTo(begin_x, begin_y);
ctx.lineTo(end_x, end_y);
ctx.stroke();
};
var draw = function(){
if(ctx !== null){
ctx.fillStyle = "black";
ctx.fillRect(0, 0, width, height);
var i = 0;
while(i < lines){
drawRondomLine();
i = i + 1;
}
}
};
draw();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment