Obelisk Test Case - Depth Sorting
How do I make an obelisk test case - depth sorting?
Https://github.com/nosir/obelisk.js/issues/3. What is a obelisk test case - depth sorting? How do you make a obelisk test case - depth sorting? This script and codes were developed by Max Huang on 26 December 2022, Monday.
Obelisk Test Case - Depth Sorting - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Obelisk Test Case - Depth Sorting</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src="//nosir.github.io/obelisk.js/dist/obelisk.min.1.0.2.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js" type="text/javascript"></script>
<div class="title">Press any key to add cubes and see the depth sorting</div>
<canvas id="view" width="1500" height="600"></canvas> <script src="js/index.js"></script>
</body>
</html>
Obelisk Test Case - Depth Sorting - Script Codes CSS Codes
.title, .title a { font-family: "Helvetica", Arial, sans-serif; font-size: 13px; color: #AAA;
}
Obelisk Test Case - Depth Sorting - Script Codes JS Codes
Array.prototype.contains = function (element) { for (var i = 0; i < this.length; i++) { if (this[i] === element) { return true; } } return false;
};
var size = 16;
var roomX = 10;
var roomY = 10;
var roomZ = 5;
// get canvas element from DOM
var canvas = document.getElementById('view');
// create pixel isometric 2.5D axis zero point
var point = new obelisk.Point(230, 80);
// canvas could be either DOM or jQuery element
var pixelView = new obelisk.PixelView(canvas, point);
var color = new obelisk.SideColor().getByInnerColor(obelisk.ColorPattern.BLUE);
var dimension = new obelisk.BrickDimension(size, size);
var brick = new obelisk.Brick(dimension, color);
for (var y = 0; y < roomY; y++) { for (var x = 0; x < roomX; x++) { var p3d = new obelisk.Point3D(x * (size + 2), y * (size + 2), 0); pixelView.renderObject(brick, p3d); }
}
// create cube dimension and color instance
var dimension = new obelisk.CubeDimension(size, size, size);
var gray = obelisk.ColorPattern.GRAY;
var color = new obelisk.CubeColor().getByHorizontalColor(gray);
// build cube with dimension and color instance
var cube = new obelisk.Cube(dimension, color, false);
var p3d = new obelisk.Point3D(0, 0, 0);
// render primitive into view
pixelView.renderObject(cube, p3d);
var cubes = [];
var cubesDepth = [];
document.addEventListener('keypress', function (e) { var transparentCube = new obelisk.Cube(dimension, new obelisk.CubeColor().getByHorizontalColor(obelisk.ColorPattern.getRandomComfortableColor()), false); // cube properties var xPos = Math.floor(Math.random() * roomX); var yPos = Math.floor(Math.random() * roomY); var depthIndex = yPos * roomX + xPos; transparentCube.xPos = xPos; transparentCube.yPos = yPos; transparentCube.zPos = 0; for (var i = 0; i < cubes.length; i++) { // place occupied if (cubes[i].depthIndex === depthIndex) { // top up z for (var j = 1; j < roomZ; j++) { if (!cubesDepth.contains(j * roomX * roomY + depthIndex)) { transparentCube.zPos = j; depthIndex = j * roomX * roomY + depthIndex; break; } } // reach the top of the room if (j === roomZ) { return; } } } transparentCube.depthIndex = depthIndex; cubes.push(transparentCube); cubesDepth.push(depthIndex); // sort the cube array by real depth cubes.sort(function (x, y) { return x.depthIndex - y.depthIndex; }); // render the queue for (var i = 0; i < cubes.length; i++) { var p3d1 = new obelisk.Point3D(cubes[i].xPos * (size + 2), cubes[i].yPos * (size + 2), cubes[i].zPos * size); pixelView.renderObject(cubes[i], p3d1); }
}, true);
Developer | Max Huang |
Username | nosir |
Uploaded | December 26, 2022 |
Rating | 3.5 |
Size | 2,707 Kb |
Views | 6,072 |
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 |
Obelisk Test Case | 3,253 Kb |
Segments mouse following | 2,909 Kb |
Pixel Isometric Input Text Rendering | 3,248 Kb |
Pixel Isometric Cube Generator | 2,195 Kb |
Lissajous Particles | 3,201 Kb |
Fireworks fountain | 3,155 Kb |
Pixel Isometric Flappy Bird | 3,836 Kb |
Build Monument Valley by Obelisk.js | 3,775 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 |
Pure CSS Animated Photo Stack | Depthdev | 2,486 Kb |
3D-box | Parthviroja | 2,346 Kb |
Getting Started | Viblast | 1,500 Kb |
Material design - button rainbow circle | Kunukn | 3,652 Kb |
The CodePen Logo | Kindofone | 4,259 Kb |
Revolving Text Landing Page Trial | TimRuby | 2,976 Kb |
Count checked checkboxes with jQuery | Mestika | 2,343 Kb |
Animated Slide Hamburger Mobile Menu | BJack | 2,247 Kb |
03 - CSS Variables | Run-time | 2,682 Kb |
Coming Soon | MariamMassadeh | 1,680 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!