Skip to content

Instantly share code, notes, and snippets.

View joshuafcole's full-sized avatar

Joshua Cole joshuafcole

View GitHub Profile
throttle = function(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
options || (options = {});
var later = function() {
previous = options.leading === false ? 0 : getTime();
timeout = null;
result = func.apply(context, args);
context = args = null;
function() {
// LCG courtesy of <https://gist.github.com/Protonk/5389384>
let m = Math.pow(2, 24), a = 16598013, c = 12820163, z = 3;
function rand() {
return z = (a * z + c) % m / m;
}
function ancestors(elem:HTMLElement) {
let ancestors = [];
while(elem) {

Breaking Down Tic-tac-toe

Last week, @RubenSandwich posted an interactive demo on the mailing list capable of playing and scoring tic-tac-toe matches. He provided some great feedback about the issues he ran into along the way. Now that the language is becoming more stable, our first priority is seeing it used and addressing the problems which surface. To that end, his troubles became our guide to making Eve a little friendlier for writing interactive applications in general and tic-tac-toe in specific.

This analysis (and future breakdowns) will be written inline in Eve to make the discussion flow more naturally. Since our blog is capable of rendering Markdown, we can provide a pleasant reading experience directly from the source code. At the moment, Eve's syntax only lends itself to a subset of Markdown, but we plan to make some small changes in the near future to become fully compatible with [GFM][2

Aggregation Statification Station Vacation III: Tokyo Drift

Misc. Notes

  • Only aggregates require stratification

  • We want to aim for the fewest strata possible

  • Aggregates that look the same should always have the same output

  • Aggregates which depend on their own outputs (directly or otherwise) are unorderable

  • Aggregates which filter (rather than provide) the rows contributing to their inputs are orderable

  • Aggregates have four kinds of variables

Custom Functions and modules in Eve

Note: We plan to do a thorough documentation pass in the coming weeks to clean up and document the codebase. This document is a very rough draft intended to help intrepid adventurers navigate the jungle until then.

Terms Sheet

  • Cardinality - The number of results a thing would return.
  • Intermediate - A value which is necessary to derive the final result, but not part of the result.
  • Referential Transparency - The property of always returning exactly the same output given an input.

2048

A version of 2048 written in Eve.

Setup

This section sets up the records we will use to represent the game board and store the current state.

  • The #game record will store the overall game state.
  • #axis records represent the horizontal and vertical axis
blarp
``` eve
search
[#foo]
```
import {Program} from "witheve";
let prog = new Program("clock");
prog.attach("system");
prog.attach("svg");
let html = prog.attach("html") as any;
let content = document.createElement("content");
document.body.appendChild(content);

Snake Game

Special thanks to Simon Craggs @ soundbible.com for crunch.mp3 http://soundbible.com/1968-Apple-Bite.html, and Mike Koenig @ soundbible.com for beep.mp3 http://soundbible.com/1251-Beep.html.

We'll use a #system/timer to advance the game one frame each tick. The #movement records contain some housekeeping information about the ways a snake can move, and what precisely those movements mean. The #pixel-scale record can be adjusted in the future by a (not yet added) resize event to resample the board appropriately.

commit
  [#system/timer #time resolution: 1000 / 6] // Tick the game 6 times a second.

[#movement direction: "left" dx: -1 dy: 0 | opposite: "right"]