Skip to content

Instantly share code, notes, and snippets.

View bedekelly's full-sized avatar

Bede Kelly bedekelly

View GitHub Profile
@bedekelly
bedekelly / fixedPose.js
Last active April 2, 2019 16:07
Fixed Pose
import React, { useState } from "react";
import posed from "react-pose";
import "./App.css";
const Box = posed.div({
regular: { width: '10vw', height: '10vh', flip: true },
fullscreen: { width: "100vw", height: '100vh', flip: true }
});
@bedekelly
bedekelly / pose.js
Created April 2, 2019 15:45
Broken Pose
import React, { useState } from "react";
import posed from "react-pose";
import "./App.css";
export default function App() {
const [fullscreen, setFullscreen] = useState(false);
const toggle = () => setFullscreen(!fullscreen);
const pose = fullscreen ? 'fullscreen' : 'regular';
@bedekelly
bedekelly / parallaxListeners.js
Created March 31, 2019 15:36
Parallax Event Listeners
document.addEventListener("mousemove", event => {
const height = event.clientY / window.innerHeight;
const width = event.clientX / window.innerWidth;
updatePositions(height, width);
});
window.addEventListener("deviceorientation", event => {
const height = -event.beta / 90;
const width = event.gamma / 180;
@bedekelly
bedekelly / parallax.js
Last active September 26, 2019 11:29
Quick'n'dirty parallax for a bunch of stacked layers
MAX_TRANSLATE = 6;
const elements = [
"background", "clouds", "back-mountain", "front-mountain",
"hills-4", "hills-3", "hills-2", "hills-1", "birds"
].map(klass => document.querySelector(`.${klass}`));
function updatePositions(height, width) {
const maxVHTranslation = -height * MAX_TRANSLATE;
@bedekelly
bedekelly / circle.html
Last active March 24, 2019 09:23
Simple circle to use for line-drawing
<svg width="120" height="120" class="ring two">
<circle class="path" cx="60" cy="60"
r="58" stroke="rgb(176, 168, 142)"
stroke-width="2" fill="none" />
</svg>
@bedekelly
bedekelly / circle-drawing.css
Created March 24, 2019 09:18
Animate Drawing a Circle
.ring.two {
stroke-dasharray: calc(2 * 3.1415 * 58);
stroke-dashoffset: calc(2 * 3.1415 * 58);
stroke-dashoffset: -calc(2 * 3.1415 * 58);
transform: rotate(-90deg);
transition: stroke-dashoffset linear 0.5s;
}
.button:hover .ring.two {
stroke-dashoffset: 0;
@bedekelly
bedekelly / maps.py
Created March 19, 2018 02:33
First stab at an implementation of Record types
"""
A MapKeyValue is a name-value pair retrieved from a map.
The name is a string, and the value can be anything at all.
"""
MapKeyValue = namedtuple("MapKeyValue", "key value")
"""
A MapEntrySpec is a specification for an entry in a Map.
The key is a number, the name is a string exposed to the user,
@bedekelly
bedekelly / ExceptionMonad.elm
Last active November 28, 2017 12:57
A simple exception monad in Elm
import Html exposing (text)
type Result a
= Return a
| Raise Exception
type alias Exception =
String
@bedekelly
bedekelly / blog2.c
Created November 19, 2017 03:34
Draw the Mandelbrot Set
#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
#define MAX_X 384
#define MAX_Y 216
#define X_LOWER -2.5
@bedekelly
bedekelly / blog1.c
Created October 28, 2017 17:42
Write an image from a C program
#include <stdio.h>
#include <stdlib.h>
void get_color(int i, int j, char color[]) {
static char r = 0, g = 0, b = 0;
r++; g--; b++;
color[0] = r;
color[1] = g;
color[2] = b;