Skip to content

Instantly share code, notes, and snippets.

@daveknights
daveknights / index.html
Created December 20, 2023 16:53
Santa sliding puzzle.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sliding Santa Puzzle</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
@daveknights
daveknights / index.html
Created December 3, 2023 15:17
Representing the time using the first chemical element atomic numbers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chemical Element Clock</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
@daveknights
daveknights / index.html
Last active November 18, 2023 14:41
Matrix themed game using Mattes.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Escape The Matrix</title>
<script src="matter.min.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
<body>
@daveknights
daveknights / cre8bit-minifier.js
Last active February 13, 2024 09:54
Node js custom minifier for the Cre8bitJS library.
const events = require('events')
const fs = require('fs')
const readline = require('readline')
const a2z = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
const fileName = process.argv[2]
const varMin = [...a2z.slice(0, 13)]
const constMin = [...a2z.slice(0, 23)]
const letMin = [...a2z.slice(0, 10)]
const funcMin = [...a2z.slice(0, 7)]
const spacesAround = ['=', , '===', '=>', '+', '&&', '?', '>', '+=']
@daveknights
daveknights / index.html
Created July 24, 2023 08:04
A basic Javascript version of Space Invaders using divs as lcd blocks.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Div Invaders</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<main class="console">
@daveknights
daveknights / App.css
Created January 15, 2023 23:09
An online game with increasing levels of difficulty.
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@800&family=Spectral:wght@800&display=swap');
:root {
--brick-pattern: repeating-linear-gradient(90deg, #fad79e, #fad79e 2px, #cca065 2px, #cca065 38px, #965c00 38px, #965c00 40px);
--brick-border-bottom: solid 1px #965c00;
--brick-border-top: solid 2px #fad79e;
--engraved-colour: #aa9668;
--game-bg: linear-gradient(#2487dc, #90c6ef 600px, #dfc07c 600px, #e3bc81);
--gold-grad: linear-gradient(yellow, gold 80%, sandybrown);
--red-grad: linear-gradient(pink, red 80%, darkred);
@daveknights
daveknights / http-server.js
Created October 2, 2022 14:22
Upload images to Node server
const http = require('http')
const fs = require('fs')
const path = require('path')
const formidable = require('formidable')
const static = require('node-static')
const fileServer = new(static.Server)('./public')
const hostname = '127.0.0.1'
const port = 4000
const imgExtensions = ['.jpg', '.png', '.webp']
@daveknights
daveknights / game-client.js
Created July 11, 2022 08:14
Two player penalty shoot out game using Socket IO and P5 JS.
const socket = io();
const gravity = 0.2;
let form, label, nameInput, joinBtn, playerName, joined, waiting, playerNames, result, resultText, playerLeaves;
let player, keeper, attempts, dropSpeed, ballWidth, ballX, ballShotX, ballY, ballShotY, shoot, goalie, goalieX, goalieY, checkSave;
const stripeData = [
{colour: '#4e801c', y: 190, h: 80},
{colour: '#679931', y: 270, h: 97},
{colour: '#4e801c', y: 367, h: 110},
{colour: '#679931', y: 477, h: 123}
];
@daveknights
daveknights / sketch.js
Created May 29, 2022 17:19
3D driving game using P5 JS with WEBGL
const laneXs = [-35, 0 ,35];
let myCar, car1, car2, myCarX, car1X, car2X, newXs, fillColour, timer;
function preload() {
timer = loadFont('roboto.ttf');
}
function car() {
return {
/**
@daveknights
daveknights / pot-black.html
Last active May 23, 2022 08:19
Very basic attempt at a snooker style game using P5.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pot Black</title>
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.1/lib/p5.js"></script>
<style>
body {