This example demonstrates spherical alpha shapes in the orthographic projection. An alpha shape is a generalized concave hull which seeks to characterize the "shape" of a set of points on a surface. It is obtained here by computing the (spherical) Delaunay triangulation (accomplished with the aid of an excellent script from Jason Davies), stripping out triangles that are "too big", and then merging the resulting mesh to remove excess interior geometry that remains from the triangulation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
import random | |
class Markov: | |
memory = defaultdict(list) | |
separator = ' ' | |
def get_initial(self): | |
return (' ', ' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple discrete-time PID controller. If plot is true, this will use matplotlib to show a graph. | |
# Otherwise, it will simply print out the successive values of the controller. | |
plot = True | |
if __name__ == '__main__': | |
if plot: | |
import matplotlib.pyplot as plt | |
v = [0] * 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pairify(it): | |
it0, it1 = itertools.tee(it, 2) | |
first = next(it0) | |
return zip(itertools.chain([first, first], it0), it1) | |
def cluster(sequence, maxgap): | |
batch = [] | |
for prev, val in pairify(sequence): | |
if abs(val - prev) >= maxgap: | |
yield batch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (main) where | |
match :: String -> String -> Bool | |
match ('^':rest) text = matchLocal rest text | |
match rex (c:rest) = matchLocal rex (c:rest) || match rex rest | |
match _ _ = False | |
matchLocal :: String -> String -> Bool | |
matchLocal [] _ = True | |
matchLocal "$" [] = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style type="text/css"> | |
html, | |
body { | |
margin: 0; | |
overflow: hidden; | |
height: 100%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def rand_max(arr): | |
curr_max = 0 | |
curr_max_idx = 0 | |
curr_max_count = 1 | |
for i,x in enumerate(arr): | |
if x > curr_max: | |
curr_max = x | |
curr_max_idx = i |
NewerOlder