Random Skyline

Developer
Size
2,353 Kb
Views
24,288

How do I make an random skyline?

Quick sketch for a responsive random skyline. Click on the canvas to create new ones.. What is a random skyline? How do you make a random skyline? This script and codes were developed by Moklick on 20 November 2022, Sunday.

Random Skyline Previews

Random Skyline - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Random Skyline</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="canvas"></canvas>
<span id="info">click on the skyline to create a new one</span> <script src="js/index.js"></script>
</body>
</html>

Random Skyline - Script Codes CSS Codes

*{ margin:0; padding:0;
}
body{ font-family:sans-serif; font-weight:bold;
}
#canvas{	background: rgb(102,175,214); background: -moz-linear-gradient(top, rgba(102,175,214,1) 0%, rgba(6,109,171,1) 100%);	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(102,175,214,1)), color-stop(100%,rgba(6,109,171,1)));	background: -webkit-linear-gradient(top, rgba(102,175,214,1) 0%,rgba(6,109,171,1) 100%); border:5px solid black; display:block; margin: 20px auto; border-radius:2px; cursor:pointer;
}
#info{ text-transform: uppercase; text-align: center; display:block; margin:0 auto; width: 80%; }

Random Skyline - Script Codes JS Codes

var Application = (function(){ var canvas; var ctx; var WIDTH; var HEIGHT; var init = function(){ canvas = document.getElementById('canvas'); ctx = canvas.getContext('2d'); bindEventHandlers(); resize(); }; var genSkyline = function(){	canvas.width = WIDTH;	var maxWidth = WIDTH / 40;	var minWidth = maxWidth / 15;	var maxHeight = HEIGHT / 1.2;	var minHeight = maxHeight / 5;	var amount = random(WIDTH/20,WIDTH/10);	var pos = 0;	while(pos < WIDTH + maxWidth){	var currWidth = random(minWidth,maxWidth);	drawSkyscraper(pos,currWidth,random(minHeight,maxHeight));	pos += currWidth;	} }; var drawSkyscraper = function(pos,scraper_width,scraper_height){	ctx.beginPath(); ctx.rect(pos,HEIGHT-scraper_height,scraper_width,scraper_height);	ctx.stroke();	ctx.fillStyle = 'black';	ctx.fill(); }; var bindEventHandlers = function(){ window.onresize = resize; canvas.addEventListener('click',genSkyline,false); }; var resize = function(){ canvas.width = WIDTH = window.innerWidth * .8; canvas.height = HEIGHT = window.innerHeight * .4; genSkyline(); }; var random = function(a,b){ return Math.random() * (b - a) + a; }; return { init : init };
}());
Application.init();
Random Skyline - Script Codes
Random Skyline - Script Codes
Home Page Home
Developer Moklick
Username moklick
Uploaded November 20, 2022
Rating 3.5
Size 2,353 Kb
Views 24,288
Do you need developer help for Random Skyline?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Moklick (moklick) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!