Jump to content

Hey guys! 

 

I'm excited to share with you all, what I have came up with in a time frame of under 1 hour. 

 

<html>
 <head>
    <title>Random Canvas Renderer</title>
    <script type="text/javascript">

        function render(){
            
        var xD = document.getElementById('thisCanvas');
        canvas = xD.getContext('2d');
            
            canvas.fillStyle = "gray";
            
            var edge = 3;
            
            var xBeg = Math.floor((Math.random() * 1920) + 1);
            var yBeg = Math.floor((Math.random() * 1014) + 1);
            
            canvas.beginPath();
            canvas.moveTo(xBeg,yBeg);
            
            for (x = 0; x < edge; x++){
                var xPos = Math.floor((Math.random() * 1890) + 1);
                var yPos = Math.floor((Math.random() * 990) + 1);
                
                var colorRandom = '#'+Math.floor(Math.random()*16777215).toString(16);
                canvas.strokeStyle = colorRandom;
                canvas.fillStyle = colorRandom;
                
                canvas.lineTo(xPos, yPos);
                canvas.fill();
        }
               canvas.closePath();
    }
        
        window.addEventListener("load", render, false);
        
    </script>
 </head>
 <body>
    <canvas style = "border: solid 1px;" id = "thisCanvas" width="1890" height="990" ></canvas>
 </body>
</html>

Run this code or click THIS link. Awesome, isn't it? Try changing the edge variable (use 2 for triangles). If anyone wants, I will explain. 

 

Looking forward to your replies. Its really flexible, so try modifying this code. 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×