Attempt to implement diamond square algorithm
How do I make an attempt to implement diamond square algorithm?
Just a quick diamond square canvas thing.... What is a attempt to implement diamond square algorithm? How do you make a attempt to implement diamond square algorithm? This script and codes were developed by Jeff Daze on 18 January 2023, Wednesday.
Attempt to implement diamond square algorithm - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Attempt to implement diamond square algorithm</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div> <button id="run">Draw</button>
</div>
<canvas id="c"></canvas> <script src="js/index.js"></script>
</body>
</html>
Attempt to implement diamond square algorithm - Script Codes CSS Codes
#c{ border:1px solid #000;
}
Attempt to implement diamond square algorithm - Script Codes JS Codes
//this must always be a power of 2 +1
//eg 65, 129, 267,
var size="513";
//set the canvas to the specified height and width... //square only for now! $("#c").width= size; $("#c").height= size;
//draw a random single color pixel in the canvas...
function draw(canvas){ var ctx = canvas.getContext('2d'); var canvasData = ctx.createImageData(canvas.width, canvas.height); for (var y=0; y<canvas.height; y++){ for (var x=0; x<canvas.width; x++){ setPixel(canvasData, x, y, getRandomInt(0, 255), getRandomInt(0, 255), getRandomInt(0, 255), 255); } } ctx.putImageData(canvasData, 0, 0);
}
//single pixel rendering...
function setPixel(imageData, x, y, r, g, b, a) { index = (x + y * imageData.width) * 4; imageData.data[index+0] = r; imageData.data[index+1] = g; imageData.data[index+2] = b; imageData.data[index+3] = a;
}
//bind click to button...
$("#run").addEventListener('click', function() { draw($('#c'));
}, false);
//utility functions here...
function getRandomInt(min, max){ return Math.floor(Math.random() * (max - min + 1)) + min;
}
function $(selector){ return document.querySelector(selector);
}
Developer | Jeff Daze |
Username | jeffdaze |
Uploaded | January 18, 2023 |
Rating | 3 |
Size | 2,110 Kb |
Views | 8,096 |
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 |
Speed Reading | 6,553 Kb |
Circular Drag and Drop | 2,451 Kb |
Angular Drag Example | 2,497 Kb |
Pulsing Button | 1,659 Kb |
JS test and Box Shadow | 1,906 Kb |
Simulation of famous C64 code... | 1,788 Kb |
Corner Triangle | 1,490 Kb |
Transparent Gradient | 2,735 Kb |
Tilemap Edge CSS | 2,159 Kb |
A test card for a Munchkin-like game | 2,044 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 |
Bloomberg Style Link Hover | Gil-- | 1,609 Kb |
Foundation 5 Menu - Accessibility | Xporter | 1,999 Kb |
Transition | Shayhowe | 1,632 Kb |
Learning canvas drawing | Aurer | 2,204 Kb |
Promodoro | Bencarp | 1,712 Kb |
Spin | Elalemanyo | 8,262 Kb |
Tile Animation Thing | Frxnz | 4,332 Kb |
Popover Example | Seanboom | 2,429 Kb |
Template | Indra_z85 | 2,323 Kb |
Simple search using AngularJS | Haykou | 1,802 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!