This commit is contained in:
Jay
2026-03-10 21:01:46 +00:00
commit 9006b2e06a
242 changed files with 30823 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
class dot{
constructor(x, y){
this.x = x;
this.y = y;
}
}

View File

@@ -0,0 +1,60 @@
<?php
if($_SERVER['HTTP_X_FORWARDED_PROTO'] !== 'https') {
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
die();
}
?>
<DOCTYPE! html>
<html>
<title>Constructing Ellipses</title>
<p>Drag your cursor around the canvas (you can use the left and right buttons for different results) to contruct an ellipse</p>
<p>Inspired by Grant Sanderson from 3blue1brown</p>
<p>Watch his <a href="https://twitter.com/3blue1brown/status/1016936129117937664">here</a></p>
<p>NOTE: doesn't work on mobile, go get a PC</p>
<div class="quantity">
<input id="numPoints" type="number" min="10" max="100" step="10" value="10">
</div>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<script src="../frameworks/p5.min.js"></script>
<script src="../frameworks/p5.dom.min.js"></script>
<script src="../frameworks/jquery-3.3.1.min.js"></script>
<script src="script.js"></script>
<script src="dot.js"></script>
<script>
jQuery('<div class="quantity-nav"><div class="quantity-button quantity-up">+</div><div class="quantity-button quantity-down">-</div></div>').insertAfter('.quantity input');
jQuery('.quantity').each(function() {
var spinner = jQuery(this),
input = spinner.find('input[type="number"]'),
btnUp = spinner.find('.quantity-up'),
btnDown = spinner.find('.quantity-down'),
min = input.attr('min'),
max = input.attr('max');
btnUp.click(function() {
var oldValue = parseFloat(input.val());
if (oldValue >= max) {
var newVal = oldValue;
} else {
var newVal = oldValue + 1;
}
spinner.find("input").val(newVal);
spinner.find("input").trigger("change");
});
btnDown.click(function() {
var oldValue = parseFloat(input.val());
if (oldValue <= min) {
var newVal = oldValue;
} else {
var newVal = oldValue - 1;
}
spinner.find("input").val(newVal);
spinner.find("input").trigger("change");
});
});
</script>
</html>

View File

@@ -0,0 +1,138 @@
var ux, uy;
var points = [];
var numericValue;
function setup(){
createCanvas(800, 800);
background(41);
}
function draw(){
numericValue = document.getElementById('numPoints').value;
translate(width/2, height/2);
background(41);
stroke(75, 75, 215);
strokeWeight(2);
noFill();
ellipse(0, 0, width-(0.0625*width), height - (0.0625*height));
stroke(215, 215, 15);
strokeWeight(7);
point(0,0);
if (mouseY > 0 && mouseY < height && mouseX > 0 && mouseX < width){
if (mouseIsPressed == true && mouseButton == LEFT){
ux = mouseX - width/2;
uy = mouseY - height/2;
point(ux, uy);
getCirclePoints();
drawLines(ux, uy);
drawTLines(ux, uy);
} else if(mouseIsPressed == true && mouseButton == RIGHT){
ux = mouseX - width/2;
uy = mouseY - height/2;
point(ux, uy);
getCirclePoints();
drawTLines(ux, uy);
}
}
}
function getCirclePoints(){
var r = (width-(0.0625*width)) / 2;
var step = 1 / numericValue;
var index = 0;
for (var i = 0; i < TWO_PI; i += step){
var cx = r * Math.sin(i);
var cy = r * Math.cos(i);
points[index] = new dot(cx, cy);
index ++;
}
}
function drawLines(startX, startY){
strokeWeight(0.4);
stroke(255);
for (var i = 0; i < points.length; i ++){
line(startX, startY, points[i].x, points[i].y);
//findMidpoint(startX, startY, points[i].x, points[i].y);
}
}
function drawTLines(startX, startY){
strokeWeight(0.4);
stroke(255);
for (var i = 0; i < points.length; i ++){
findMidpoint(startX, startY, points[i].x, points[i].y);
}
}
function findMidpoint(x1, y1, x2, y2){
//find center
var cx = (x1+x2)/2;
var cy = (y1+y2)/2;
//move line to the center on the origin
x1 -= cx; y1 -= cy;
x2 -= cx; y2 -= cy;
//rotate both points
xtemp = x1; ytemp = y1;
x1=-ytemp; y1=xtemp;
xtemp = x2; ytemp = y2;
x2=-ytemp; y2=xtemp;
//move the center point back to where it was
x1+=cx; y1+=cy;
x2+=cx; y2+=cy;
stroke(255, 0, 0);
line(x1, y1, x2, y2);
stroke(255);
}
function genLines(){
var pointOk = false;
do{
ux = random(width);
uy = random(height);
if(getDist(0, ux, 0, uy) <= (width-(0.0625*width)) / 2){
pointOk = true;
}
}
while(!pointOk);
point(ux, uy);
getCirclePoints();
drawLines(ux, uy);
drawTLines(ux, uy);
}
function genTLines(){
var pointOk = false;
do{
ux = random(width);
uy = random(height);
if(getDist(0, ux, 0, uy) <= (width-(0.0625*width)) / 2){
pointOk = true;
}
}
while(!pointOk);
point(ux, uy);
getCirclePoints();
drawTLines(ux, uy);
}
function getDist(x1, x2, y1, y2){
return Math.sqrt((x1 - x2)^2 + (y1 - y2)^2);
}

View File

@@ -0,0 +1,76 @@
@import url('https://fonts.googleapis.com/css?family=Roboto');
.quantity {
position: absolute;
bottom: 50px;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button
{
-webkit-appearance: none;
margin: 0;
}
input[type=number]
{
-moz-appearance: textfield;
}
.quantity input {
width: 45px;
height: 42px;
line-height: 1.65;
float: left;
display: block;
padding: 0;
margin: 0;
border: 1px solid #eee;
}
.quantity input:focus {
outline: 0;
}
.quantity-nav {
float: left;
position: relative;
height: 42px;
}
.quantity-button {
position: relative;
cursor: pointer;
border-left: 1px solid #eee;
width: 20px;
text-align: center;
color: #333;
font-size: 13px;
font-family: "Trebuchet MS", Helvetica, sans-serif !important;
line-height: 1.7;
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
.quantity-button.quantity-up {
position: absolute;
height: 50%;
top: 0;
border-bottom: 1px solid #eee;
}
.quantity-button.quantity-down {
position: absolute;
bottom: -1px;
height: 50%;
}
p{
font-family: 'Roboto', sans-serif;
font-size: 24px;
}