JSFiddle - React, Tailwind, and code Playground
by loktar
HTML
<canvas class='hacker-3d-shiz'></canvas>
<canvas class='bars-and-stuff'></canvas>
<div class="output-console"></div>
CSS
body {
font-family: consolas;
background:#000;
color: #00FF00;
margin:0;
}
canvas {
position:absolute;
top:0;
left:0;
}
.bars-and-stuff{
left:66.6%;
}
.output-console {
position:fixed;
overflow:hidden;
}
p{margin:0}
JavaScript
var canvas = document.querySelector(".hacker-3d-shiz"),
ctx = canvas.getContext("2d"),
canvasBars = document.querySelector(".bars-and-stuff"),
ctxBars = canvasBars.getContext("2d"),
outputConsole = document.querySelector(".output-console");
canvas.width = (window.innerWidth/3)*2;
canvas.height = window.innerHeight / 3;
canvasBars.width = window.innerWidth/3;
canvasBars.height = canvas.height;
outputConsole.style.height = (window.innerHeight / 3) * 2 + 'px';
outputConsole.style.top = window.innerHeight / 3 + 'px'
/* Graphics stuff */
function Square(z) {
this.width = canvas.width/2;
this.height = canvas.height;
z = z || 0;
this.points = [
new Point({
x: (canvas.width / 2) - this.width,
y: (canvas.height / 2) - this.height,
z: z
}),
new Point({
x: (canvas.width / 2) + this.width,
y: (canvas.height / 2) - this.height,
z: z
}),
new Point({
x: (canvas.width / 2) + this.width,
y: (canvas.height / 2) + this.height,
z: z
}),
new Point({
x: (canvas.width / 2) - this.width,
y: (canvas.height / 2) + this.height,
z: z
})];
this.dist = 0;
}
Square.prototype.update = function () {
for (var p = 0; p < this.points.length; p++) {
this.points[p].rotateZ(0.001);
this.points[p].z -= 3;
if (this.points[p].z < -300) {
this.points[p].z = 2700;
}
this.points[p].map2D();
}
}
Square.prototype.render = function () {
ctx.beginPath();
ctx.moveTo(this.points[0].xPos, this.points[0].yPos);
for (var p = 1; p < this.points.length; p++) {
if (this.points[p].z > -(focal - 50)) {
ctx.lineTo(this.points[p].xPos, this.points[p].yPos);
}
}
ctx.closePath();
ctx.stroke();
this.dist = this.points[this.points.length - 1].z;
};
function Point(pos) {
this.x = pos.x - canvas.width / 2 || 0;
this.y = pos.y -...