Skip to content
Snippets Groups Projects
Commit 65743de5 authored by atm2g19's avatar atm2g19
Browse files

a few additions to static served pages

parent c24e25f7
No related branches found
No related tags found
No related merge requests found
Showing
with 10568 additions and 17 deletions
...@@ -5,8 +5,8 @@ launch.json ...@@ -5,8 +5,8 @@ launch.json
log/ log/
**/*.d.ts **/*.d.ts
**/*.zip **/*.zip
# public/**/*.ts public/**/*.ts
# public/**/tsconfig.json public/**/tsconfig.json
.jsbeautifyrc .jsbeautifyrc
nodemon.json nodemon.json
public/js/p5/.DS_Store public/js/p5/.DS_Store
......
<!DOCTYPE html>
<html>
<head>
<title>Google Code Jam Solutions</title>
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<div id="header">
<h1>
<a href="/" id="home">
Alex Mansfield's web server!
</a>
</h1>
</div>
<div id="subheader">
<h1>
Code Jam Solutions
</h1>
</div>
<div id="container">
<ul>
<li>
2020
<ul>
<li>
</li>
</ul>
</li>
</ul>
</div>
<div id="footer">
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Collisions algorithms</title>
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<div id="header">
<h1>
<a href="/" id="home">
Alex Mansfield's web server!
</a>
</h1>
</div>
<div id="subheader">
<h1>
Collisions algorithms
</h1>
<a href="../">Coding Challenges/</a>
</div>
<div id="container">
<ul>
<li>
<a href="test-every/">For each item, check every other.</a>
</li>
<li>
<a href="test-every-optim/">For each item, check every other. - Optimised</a>
</li>
<li>
<a href="quad-tree/">Quad tree collisions</a>
(WIP)
</li>
</ul>
</div>
<div id="footer">
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Collisions - Quad Trees</title>
<link rel="stylesheet" href="/css/main.css">
<script src="../../../js/p5/p5.js"></script>
<script src="./qtree.js"></script>
<script src="./sketch.js"></script>
</head>
<body>
<div id="header">
<h1>
<a href="/" id="home">
Alex Mansfield's web server!
</a>
</h1>
</div>
<div id="subheader">
<h1>
Quad Tree based collisions algorithm
</h1>
<a href="../../">Coding Challenges/</a>
<a href="../">Collisions Algorithms/</a>
</div>
<div id="container">
</div>
<div id="footer">
</div>
</body>
</html>
\ No newline at end of file
/// <reference path="../../../../p5.global-mode.d.ts"/>
class QuadTree {
constructor(bounds, maxElems) {
this.maxElems = 4;
this.elems = [];
this.bounds = bounds;
if (maxElems)
this.maxElems = maxElems;
}
insert(elem) {
if (!this.children) {
if (this.elems.length >= this.maxElems) {
//generate children
this.children = [];
for (let i = 0; i < 2; i++) {
for (let j = 0; j < 2; j++) {
this.children.push(new QuadTree({
type: 'boundary',
x: this.bounds.x + i * this.bounds.w / 2,
y: this.bounds.y + j * this.bounds.h / 2,
w: this.bounds.w / 2,
h: this.bounds.h / 2
}, this.maxElems));
}
}
for (let i = 0; i < this.elems.length; i++) {
this.insert(this.elems[i]);
}
this.insert(elem);
this.elems = [];
}
else {
this.elems.push(elem);
}
}
else {
//find which child
for (let child of this.children) {
if (child.bounds.x <= elem.x && child.bounds.y <= elem.y &&
child.bounds.x + child.bounds.w > elem.x && child.bounds.y + child.bounds.h > elem.y) {
child.insert(elem);
}
}
}
}
draw() {
noFill();
stroke(100, 100, 100);
strokeWeight((this.bounds.w + this.bounds.h) / 200);
rect(this.bounds.x, this.bounds.y, this.bounds.w, this.bounds.h);
if (this.children) {
for (let c of this.children) {
c.draw();
}
}
}
query(b) {
let elems = [];
if (b.type == 'circle') {
let nb = {
type: 'boundary',
x: b.x - b.r,
y: b.y - b.r,
w: b.r * 2,
h: b.r * 2,
};
return this.query(nb);
}
else if (b.type == 'boundary') {
if (this.children) {
for (let c of this.children) {
//AABB
if (b.x < c.bounds.x + c.bounds.w &&
b.x + b.w > c.bounds.x &&
b.y < c.bounds.y + c.bounds.h &&
b.y + b.h > c.bounds.y) {
elems.push(...c.query(b));
}
}
}
else {
for (let e of this.elems) {
if (e.x > b.x && e.y > b.y &&
e.x < b.x + b.w && e.y < b.y + b.h) {
elems.push(e);
}
}
}
}
return elems;
}
}
/// <reference path="./qtree.ts" />
/// <reference path="../../../../p5.global-mode.d.ts"/>
let count;
let countSlider;
let slider_label;
let frCounter;
let fr = 0;
let circles = [];
let b = {
type: 'boundary',
x: 0,
y: 0,
w: 500,
h: 500,
};
function setup() {
let params = getURLParams();
if (params["count"]) {
count = params["count"];
}
else {
count = 100;
}
//@ts-ignore
countSlider = createSlider(0, 80, Math.log10(count) * 20, 0.1);
countSlider.id("CountSlider");
// createElement("br");
//@ts-ignore
slider_label = createElement("label");
slider_label.attribute("for", "CountSlider");
//@ts-ignore
frCounter = createElement("label");
createElement("br");
createCanvas(500, 500);
frameRate(30);
}
function draw() {
let qtree = new QuadTree(b);
//@ts-ignore
count = Math.floor(Math.pow(10, countSlider.value() / 20));
slider_label.elt.innerText = (count);
fr = fr + (frameRate() - fr) / 8;
frCounter.elt.innerText = `, FrameRate: ${Math.floor(fr)}`;
// console.log(count);
while (circles.length > count) {
circles.pop();
}
while (circles.length < count) {
circles.push(new Circle(Math.random() * width, Math.random() * height, 10));
}
for (let c of circles) {
qtree.insert({
x: c.getX(),
y: c.getY(),
obj: c,
});
}
// console.log(qtree);
background(0);
for (let c of circles) {
let poss = qtree.query({
type: 'circle',
x: c.getX(),
y: c.getY(),
r: c.getRadius() * 2,
});
for (let { obj } of poss) {
if (obj != c && c.intersects(obj)) {
c.setHiglight(true);
obj.setHiglight(true);
}
}
}
for (let c of circles) {
c.draw();
c.move();
c.setHiglight(false);
}
qtree.draw();
// noLoop();
}
class Circle {
constructor(x, y, r) {
this.x = x;
this.y = y;
this.r = r;
this.highlight = false;
}
getRadius() {
return this.r;
}
getX() {
return this.x;
}
getY() {
return this.y;
}
setHiglight(b) {
this.highlight = b;
}
move() {
this.x += Math.random() * 5 - 2.5;
this.y += Math.random() * 5 - 2.5;
}
draw() {
fill(100, 100, 100);
if (this.highlight) {
fill(180, 180, 180);
}
noStroke();
ellipse(this.x, this.y, this.r * 2);
}
intersects(c) {
let minD = c.getRadius() + this.r;
minD *= minD;
let dX = c.getX() - this.x;
dX *= dX;
let dY = c.getY() - this.y;
dY *= dY;
if (dX + dY < minD) {
return true;
}
return false;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Collisions - test all optimised</title>
<link rel="stylesheet" href="/css/main.css">
<script src="../../../js/p5/p5.js"></script>
<script src="./test-every-optim.js"></script>
</head>
<body>
<div id="header">
<h1>
<a href="/" id="home">
Alex Mansfield's web server!
</a>
</h1>
</div>
<div id="subheader">
<h1>
Slightly optimised collisions algorithm
</h1>
<a href="../../">Coding Challenges/</a>
<a href="../">Collisions Algorithms/</a>
</div>
<div id="container">
</div>
<div id="footer">
</div>
</body>
</html>
\ No newline at end of file
/// <reference path="../../../../p5.global-mode.d.ts"/>
let count;
let countSlider;
let circles = [];
function setup() {
createCanvas(500, 500);
let params = getURLParams();
if (params["count"]) {
count = params["count"];
}
else {
count = 100;
}
//@ts-ignore
countSlider = createSlider(1, 100, Math.log10(count) * 20, 1);
}
function draw() {
//@ts-ignore
count = Math.pow(10, countSlider.value() / 20);
console.log(count);
while (circles.length > count) {
circles.pop();
}
while (circles.length < count) {
circles.push(new Circle(Math.random() * width, Math.random() * height, width * height / (1500 * Math.sqrt(count))));
}
background(0);
for (let i = 0; i < circles.length; i++) {
for (let j = i + 1; j < circles.length; j++) {
if (circles[i] != circles[j] && circles[i].intersects(circles[j])) {
circles[i].setHiglight(true);
circles[j].setHiglight(true);
}
}
}
for (let c of circles) {
c.draw();
c.move();
c.setHiglight(false);
}
}
class Circle {
constructor(x, y, r) {
this.x = x;
this.y = y;
this.r = r;
this.highlight = false;
}
getRadius() {
return this.r;
}
getX() {
return this.x;
}
getY() {
return this.y;
}
setHiglight(b) {
this.highlight = b;
}
move() {
this.x += Math.random() * 5 - 2.5;
this.y += Math.random() * 5 - 2.5;
}
draw() {
fill(100, 100, 100);
if (this.highlight) {
fill(180, 180, 180);
}
noStroke();
ellipse(this.x, this.y, this.r * 2);
}
intersects(c) {
let minD = c.getRadius() + this.r;
minD *= minD;
let dX = c.getX() - this.x;
dX *= dX;
let dY = c.getY() - this.y;
dY *= dY;
if (dX + dY < minD) {
return true;
}
return false;
}
}
new p5(null, document.getElementById("container"));
<!DOCTYPE html>
<html>
<head>
<title>Collisions - test all</title>
<link rel="stylesheet" href="/css/main.css">
<script src="../../../js/p5/p5.js"></script>
<script src="./test-every.js"></script>
</head>
<body>
<div id="header">
<h1>
<a href="/" id="home">
Alex Mansfield's web server!
</a>
</h1>
</div>
<div id="subheader">
<h1>
Basic Collisions algorithm
</h1>
<a href="../../">Coding Challenges/</a>
<a href="../">Collisions Algorithms/</a>
</div>
<div id="container">
</div>
<div id="footer">
</div>
</body>
</html>
\ No newline at end of file
/// <reference path="../../../../p5.global-mode.d.ts"/>
var count;
var countSlider;
var slider_label;
var frCounter;
var fr = 0;
var circles = [];
function setup() {
var params = getURLParams();
if (params["count"]) {
count = params["count"];
}
else {
count = 100;
}
//@ts-ignore
countSlider = createSlider(0, 80, Math.log10(count) * 20, 0.1);
countSlider.id("CountSlider");
// createElement("br");
//@ts-ignore
slider_label = createElement("label");
slider_label.attribute("for", "CountSlider");
//@ts-ignore
frCounter = createElement("label");
createElement("br");
createCanvas(500, 500);
}
function draw() {
//@ts-ignore
count = Math.floor(Math.pow(10, countSlider.value() / 20));
console.log(count);
slider_label.elt.innerText = (count);
fr = fr + (frameRate() - fr) / 8;
frCounter.elt.innerText = ", FrameRate: " + Math.floor(fr);
while (circles.length > count) {
circles.pop();
}
while (circles.length < count) {
circles.push(new Circle(Math.random() * width, Math.random() * height, width * height / (1500 * Math.sqrt(count))));
}
background(0);
for (var i = 0; i < circles.length; i++) {
for (var j = 0; j < circles.length; j++) {
if (circles[i] != circles[j] && circles[i].intersects(circles[j])) {
circles[i].setHiglight(true);
circles[j].setHiglight(true);
}
}
}
for (var _i = 0, circles_1 = circles; _i < circles_1.length; _i++) {
var c = circles_1[_i];
c.draw();
c.move();
c.setHiglight(false);
}
}
var Circle = /** @class */ (function () {
function Circle(x, y, r) {
this.x = x;
this.y = y;
this.r = r;
this.highlight = false;
}
Circle.prototype.getRadius = function () {
return this.r;
};
Circle.prototype.getX = function () {
return this.x;
};
Circle.prototype.getY = function () {
return this.y;
};
Circle.prototype.setHiglight = function (b) {
this.highlight = b;
};
Circle.prototype.move = function () {
this.x += Math.random() * 5 - 2.5;
this.y += Math.random() * 5 - 2.5;
};
Circle.prototype.draw = function () {
fill(100, 100, 100);
if (this.highlight) {
fill(180, 180, 180);
}
noStroke();
ellipse(this.x, this.y, this.r * 2);
};
Circle.prototype.intersects = function (c) {
var minD = c.getRadius() + this.r;
minD *= minD;
var dX = c.getX() - this.x;
dX *= dX;
var dY = c.getY() - this.y;
dY *= dY;
if (dX + dY < minD) {
return true;
}
return false;
};
return Circle;
}());
new p5(null, document.getElementById("container"));
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<title>Covid-19 Tracker</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<script src="./index.js"></script>
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<div id="header">
<h1>
<a href="/" id="home">
Alex Mansfield's web server!
</a>
</h1>
</div>
<div id="subheader">
<h1>
Covid-19 Tracker
</h1>
<a href="../">Coding Challenges/</a>
</div>
<div id="container">
<canvas id="chart" width="500" height="500"></canvas>
</div>
<div id="footer">
</div>
</body>
</html>
\ No newline at end of file
async function start() {
let res = await fetch("./cases.csv");
let text = await res.text();
// console.log(text);
let table = text.split('\n');
let header = table[0].split(',');
let rows = table.splice(1).map(row => {
let r = row.split(',');
let _r = {};
header.forEach((col, idx) => {
_r[col] = r[idx];
});
return _r;
});
console.log(header);
console.log(rows);
let t = new tracker(rows);
console.log(t);
createChart();
}
function createChart() {
let myChart = new Chart("chart")
}
class tracker {
constructor(data) {
this.countries = {};
for (let row of data) {
if (!(row.countryterritoryCode in this.countries)) {
this.countries[row.countryterritoryCode] = new country(row.countriesAndTerritories, row.countryterritoryCode, row.geoId);
}
this.countries[row.countryterritoryCode].addCases(row.dateRep, row.cases, row.deaths);
}
}
}
class country {
constructor(name, terr_code, geoId) {
this.name = name;
this.territory_code = terr_code;
this.geoId = geoId;
this.cases = {};
}
addCases(date, cases, deaths) {
let d = date.split('/');
this.cases[`${d[2]}/${d[1]}/${d[0]}`] = {
cases: cases,
deaths: deaths,
}
}
getCases() {
return this.cases;
}
}
window.onload = start;
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Coding challenges!</title>
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<div id="header">
<h1>
<a href="/" id="home">
Alex Mansfield's web server!
</a>
</h1>
</div>
<div id="subheader">
<h1>
Coding Challenges!
</h1>
</div>
<div id="container">
<ul>
<li>
<a href="covid-tracker/">Covid-19 tracker/charter</a>
(WIP)
</li>
<li>
<a href="./collisions/">Collisions algorithms</a>
(WIP)
</li>
</ul>
</div>
<div id="footer">
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
</head> </head>
<body> <body>
<h1> <h1>
Error 500 Error 500
...@@ -14,4 +16,52 @@ ...@@ -14,4 +16,52 @@
Server error! Server error!
</h3><br> </h3><br>
</body> </body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<div id="header">
<h1>
<a href="/" id="home">
Alex Mansfield's web server!
</a>
</h1>
</div>
<div id="subheader">
<h1>
Error
</h1>
</div>
<div id="container" style="text-align: center;">
<h1>
500
</h1>
<p>
Oops
</p>
<h3>
Server Error!
</h3>
<p>
Please contact the system administrator if this page continues to occur. Thank you!
</p>
</div>
<div id="footer">
</div>
</body>
</html> </html>
\ No newline at end of file
...@@ -19,6 +19,12 @@ ...@@ -19,6 +19,12 @@
<li> <li>
<a href="games/">Games</a> <a href="games/">Games</a>
</li> </li>
<li>
<a href="coding_challenges/">Coding Challenges</a>
</li>
<li>
<a href="code_jam/">Google Code Jam</a>
</li>
</ul> </ul>
</div> </div>
<div id="footer"> <div id="footer">
......
< <?xml version="1.0" encoding="UTF-8"?>
\ No newline at end of file <urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->
<url>
<loc>http://mansfields.org/index.html</loc>
<lastmod>2020-04-09T00:17:35+00:00</lastmod>
<priority>1.00</priority>
</url>
<url>
<loc>http://mansfields.org/games/index.html</loc>
<lastmod>2020-04-09T00:17:35+00:00</lastmod>
<priority>0.80</priority>
</url>
<url>
<loc>http://mansfields.org/games/battleships/index.html</loc>
<lastmod>2020-04-09T00:17:35+00:00</lastmod>
<priority>0.64</priority>
</url>
<url>
<loc>http://mansfields.org/games/battleships_v2/index.html</loc>
<lastmod>2020-04-09T00:17:35+00:00</lastmod>
<priority>0.64</priority>
</url>
<url>
<loc>http://mansfields.org/games/cah/index.html</loc>
<lastmod>2020-04-09T00:17:35+00:00</lastmod>
<priority>0.64</priority>
</url>
<url>
<loc>http://mansfields.org/games/backgammon/index.html</loc>
<lastmod>2020-04-09T00:17:35+00:00</lastmod>
<priority>0.64</priority>
</url>
</urlset>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment