Skip to content

Instantly share code, notes, and snippets.

@mgold
mgold / README.md
Last active August 28, 2021 19:20
Spherical Coordinates

Grab the brown and black knobs. You can also dial some of the numbers on the right.

Spherical coordinates are defined by ρ (rho, the distance from the origin), θ (theta, rotation parallel to the xy-plane), and φ (phi, inclination from the north pole to the south pole). This interactive drawing shows how they relate to the Cartesian xyz coordinates. The key is the horizontal slice of radius r.

  • z = ρ cos φ
  • r = ρ sin φ

Which makes sense: when φ=0, we're looking at the north pole, z=ρ and r=0. Then we're left with the familiar equations:

  • x = r cos θ
@mgold
mgold / Main.elm
Created February 22, 2016 16:54
Toggle in Elm
module Main (..) where
import Color
import Date exposing (Date)
import Task exposing (Task)
import Json.Decode
import Html exposing (Html, div, tr, td, th)
import Html.Attributes as Attrs exposing (class)
import Html.Events exposing (onClick, on)
import StartApp exposing (start)
@mgold
mgold / using_mailboxes_in_elm.md
Last active March 24, 2020 16:05
Using Mailboxes in Elm: a tutorial blog post

Using Mailboxes in Elm

Max Goldstein | July 30, 2015 | Elm 0.15.1

In Elm, signals always have a data source associated with them. Window.dimensions is exactly what you think it is, and you can't send your own events on it. You can derive your own signals from these primitives using map, filter, and merge, but the timing of events is beyond your control.

This becomes a problem when you try to add UI elements. We want to be able to add checkboxes and dropdown menus, and to receive the current state of these elements as a signal. So how do we do that?

The Bad Old Days

@mgold
mgold / README.md
Created September 3, 2014 02:03
Testing d3.bullet

Testing each option to d3.bullet, taken from d3-plugins and slightly revised. This shows that all of the options still work, and some of them work in edge cases where they didn't before. Also shown are cases that do not yet work. This is not an automated test suite; determining success or failure must be done manually (optically).

@mgold
mgold / .block
Last active May 26, 2018 20:53
65 Years
license: mit
@mgold
mgold / README.md
Last active December 21, 2017 20:15 — forked from mbostock/.block
Multi-Series Line Chart Demoing Selection Groups

This is a fork of Mike Bostock's Multi-Series Line Chart, which adds circles along the line for each data point. The circles help anchor us to the real datapoints (rather than extrapolations) when comparing across lines.

But this is really an exercise in nested selections, leveraging selections as groups. The data consists of multiple lines, which each have multiple data points. We call .data twice: first with the data for all cities, binding the array for each city as a single datum. This is good enough for D3's line generators but not for placing circles. So we selectAll circles from the merged enter-update selection, and then bind the data for each line using a function, which is passed each datum from the prior join. This step produces a new data join, and you need to do it even if the function you pass is the identity. Since there are no circles, we skip straight to the enter selection and append them. Then we assign them x and y positions based on the accessor

@mgold
mgold / .block
Last active June 14, 2017 06:37
Wheat Plot
license: mit
@mgold
mgold / .block
Last active March 5, 2017 01:40
valv
license: mit
@mgold
mgold / .block
Last active January 5, 2017 06:05
Zukei Puzzle Solver
license: mit
@mgold
mgold / Perlin.elm
Created January 15, 2016 18:17
Perlin noise in Elm (requires mgold/elm-random-pcg)
module Perlin (noise, octaves) where
{-|
Technically, this is an implementation of [Improved Noise](http://mrl.nyu.edu/~perlin/paper445.pdf), a refinement on the
original Perlin noise, but not Simplex Noise.
-}
import Random.PCG as PCG
type alias Gradient = (Float, Float)