Attempt to implement diamond square algorithm

Developer
Size
2,110 Kb
Views
8,096

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 Previews

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);
}
Attempt to implement diamond square algorithm - Script Codes
Attempt to implement diamond square algorithm - Script Codes
Home Page Home
Developer Jeff Daze
Username jeffdaze
Uploaded January 18, 2023
Rating 3
Size 2,110 Kb
Views 8,096
Do you need developer help for Attempt to implement diamond square algorithm?

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!

Jeff Daze (jeffdaze) Script Codes
Create amazing sales emails 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!