Random Skyline
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 - 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();

Developer | Moklick |
Username | moklick |
Uploaded | November 20, 2022 |
Rating | 3.5 |
Size | 2,353 Kb |
Views | 24,276 |
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!
Name | Size |
CSS Map FX | 2,335 Kb |
3D Mapbox | 3,508 Kb |
Damn Particlez | 2,805 Kb |
3D Map Example | 2,980 Kb |
Codepen Inception | 1,384 Kb |
CCTV Everywhere | 3,723 Kb |
Leaflet Transition Example | 33,818 Kb |
Zeichensatz | 2,058 Kb |
A Pen by moklick | 33,698 Kb |
Watch the cursor | 1,657 Kb |
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!
Name | Username | Size |
CSS Clip and Shape Module clearly | Pestov | 2,640 Kb |
Canvas stripes | Adrianparr | 1,948 Kb |
Clock with full screen background | Owebboy | 2,415 Kb |
Android Play Store With Slick Carousel | -J0hn- | 4,982 Kb |
Get third wednesday | Wojtek1150 | 2,691 Kb |
Addthis_button | Esambino | 1,691 Kb |
Animated Vertical CSS3 Menu Black | MaCeLMp4 | 2,750 Kb |
Flat buttons for Eliassen.com | Kdooley89 | 1,737 Kb |
Sticky div | Kaslab | 2,225 Kb |
Large canvas mousemove experiment | Jibbon | 2,885 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!