Skip to content

Instantly share code, notes, and snippets.

@mrkatey
Last active September 19, 2022 09:31
Show Gist options
  • Save mrkatey/f4778cae13c3ed0f356c83381deb6759 to your computer and use it in GitHub Desktop.
Save mrkatey/f4778cae13c3ed0f356c83381deb6759 to your computer and use it in GitHub Desktop.
Generate random fields
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="3840" height="2160" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
function random_color(){
let max = 255
let a = Math.ceil(Math.random()*max);
let b = Math.ceil(Math.random()*max);
let c = Math.ceil(Math.random()*max);
let d = Math.ceil(Math.random()*100)*.001
return `rgba(${a}, ${b}, ${c}, ${d})`
let colors = ['blue','red','orange','white','pink']
return colors[Math.floor(Math.random()*colors.length)]
}
function random_size(min=1,max=300){
return Math.ceil(Math.random()*max-min)
}
function random_circle(width, height, size,color){
let x = Math.ceil(Math.random()*width)
let y = Math.ceil(Math.random()*height)
let sk = Math.ceil(Math.random()*100)
ctx.beginPath();
ctx.moveTo(x+size,y);
ctx.arc(x, y, size, sk, 2 * Math.PI);
//ctx.stroke();
ctx.fillStyle = color
ctx.fill();
}
function make_many(total=100000){
let count = 0
while(count<total){
count +=1
let color = random_color()
let size = random_size()
random_circle(3840, 2160, size,color)
}
}
make_many()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment