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,288 |
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 |
Fullscreen fun | 1,984 Kb |
3D Mapbox | 3,508 Kb |
... is watching you | 2,423 Kb |
Watch the cursor | 1,657 Kb |
A Pen by moklick | 33,698 Kb |
3D Map Example | 2,980 Kb |
Berlin Building Map | 2,477 Kb |
CCTV Everywhere | 3,723 Kb |
SVG Dom Visualization | 3,859 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 |
Wrap_Test | Mscfourn | 7,503 Kb |
Loading Bar | Jaradlight | 2,333 Kb |
CSS Tooltips | Darylldoyle | 2,599 Kb |
Super Discount | Orrinward | 3,225 Kb |
Navcube | Wbarlow | 4,775 Kb |
Pricing Table | Semenchenko | 6,784 Kb |
Subscription Newsletter - Before inlining | Bradstrong | 7,526 Kb |
A Pen by Matt Popovich | Mpopv | 3,349 Kb |
Scroll effect with text with help from Skrollr | Luxonglassing | 2,935 Kb |
GLSL Hills | Ykob | 6,991 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!