infinity mirror effect
This commit is contained in:
@@ -24,12 +24,7 @@ class Canvas {
|
|||||||
/* -----------------------------
|
/* -----------------------------
|
||||||
Rectangle
|
Rectangle
|
||||||
----------------------------- */
|
----------------------------- */
|
||||||
rect = {
|
rects = [];
|
||||||
x: -300,
|
|
||||||
y: -200,
|
|
||||||
w: 600,
|
|
||||||
h: 400
|
|
||||||
};
|
|
||||||
|
|
||||||
resize = () => {
|
resize = () => {
|
||||||
// Make Canvas Fill Screen
|
// Make Canvas Fill Screen
|
||||||
@@ -97,40 +92,50 @@ class Canvas {
|
|||||||
ctx.clearRect(0, 0, this.c.width, this.c.height);
|
ctx.clearRect(0, 0, this.c.width, this.c.height);
|
||||||
|
|
||||||
let drawMenus = () => {
|
let drawMenus = () => {
|
||||||
|
|
||||||
ctx.setTransform(1, 0, 0, 1, 0, 0); // reset transform for UI
|
|
||||||
ctx.fillStyle = "rgba(30,30,30,0.8)";
|
|
||||||
ctx.fillRect(10,10,150,100);
|
|
||||||
|
|
||||||
ctx.fillStyle = "#FEB279";
|
ctx.fillStyle = "#FEB279";
|
||||||
ctx.fillRect(20,20,120,30);
|
ctx.strokeRect(20,20,220,100);
|
||||||
ctx.fillRect(20,60,120,30);
|
|
||||||
|
|
||||||
ctx.fillStyle = "#000";
|
ctx.fillStyle = "#000";
|
||||||
ctx.font = "60px arial";
|
ctx.font = "60px arial";
|
||||||
ctx.fillText("Button 1", 20, 40);
|
// ctx.fillText("Button 1", 20, 100);
|
||||||
ctx.fillText("Button 2", 20, 80);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let drawSpace = () => {
|
let drawSpaces = () => {
|
||||||
ctx.translate(this.c.width / 2, this.c.height / 2);
|
for(let i=0; i<this.rects.length; i++) {
|
||||||
ctx.scale(scale, scale);
|
let rect = this.rects[i]
|
||||||
ctx.translate(-camera.x, -camera.y);
|
|
||||||
|
|
||||||
ctx.strokeStyle = this.STROKE_COLOR;
|
let x = -300 + i
|
||||||
ctx.lineWidth = 0.5 / scale;
|
let y = -200 + i
|
||||||
ctx.strokeRect(rect.x, rect.y, rect.w, rect.h);
|
let w = 600 + i
|
||||||
|
let h = 400 + i
|
||||||
|
|
||||||
|
ctx.translate(this.c.width / 2, this.c.height / 2);
|
||||||
|
ctx.scale(scale, scale);
|
||||||
|
ctx.translate(-camera.x, -camera.y);
|
||||||
|
|
||||||
|
ctx.strokeStyle = this.STROKE_COLOR;
|
||||||
|
ctx.lineWidth = 0.5 / scale;
|
||||||
|
ctx.strokeRect(x, y, w, h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.save()
|
ctx.save()
|
||||||
|
|
||||||
drawSpace()
|
drawSpaces()
|
||||||
|
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
|
|
||||||
drawMenus(ctx);
|
drawMenus(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fetchDownloads() {
|
||||||
|
let res = await fetch("/downloads", {method: "GET"})
|
||||||
|
console.log(res)
|
||||||
|
let json = await res.json()
|
||||||
|
console.log(json)
|
||||||
|
this.rects = json
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
document.body.appendChild(this.c)
|
document.body.appendChild(this.c)
|
||||||
this.ctx = this.c.getContext("2d");
|
this.ctx = this.c.getContext("2d");
|
||||||
@@ -140,6 +145,8 @@ class Canvas {
|
|||||||
|
|
||||||
this.c.addEventListener("wheel", this.onWheel, { passive: false });
|
this.c.addEventListener("wheel", this.onWheel, { passive: false });
|
||||||
this.draw()
|
this.draw()
|
||||||
|
|
||||||
|
this.fetchDownloads()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,18 +8,21 @@ import forms from 'forms'
|
|||||||
|
|
||||||
import { initWebSocket } from './ws.js'
|
import { initWebSocket } from './ws.js'
|
||||||
import util from './util.js'
|
import util from './util.js'
|
||||||
|
import getAllDownloadsFiles from "./getDownloads.js"
|
||||||
|
|
||||||
export default class Server {
|
export default class Server {
|
||||||
store;
|
store;
|
||||||
|
|
||||||
registerRoutes(router) {
|
registerRoutes(router) {
|
||||||
|
router.get('/downloads', this.getDownloads)
|
||||||
router.get('/*', this.get)
|
router.get('/*', this.get)
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|
||||||
index = async (req, res) => {
|
getDownloads = async (req, res) => {
|
||||||
let filePath = path.join(util.CAVE_PATH, "index.html");
|
let arr = await getAllDownloadsFiles()
|
||||||
res.sendFile(filePath)
|
console.log(arr)
|
||||||
|
res.json(arr)
|
||||||
}
|
}
|
||||||
|
|
||||||
get = async (req, res) => {
|
get = async (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user