Welcome, dear traveller or meddler!
This generates designs that, in some abstract way, are made of train tracks (monorails?) that connect smoothly together. The paths are smooth by virtue of being Bézier curves. There are no actual trains currently.
The code is in script.ts
. The overview is first I
generate some "track end-points" that consist of a location and an
orientation, and then I connect every pair of end-point sides[1] that meet
certain criteria.
The end-points are little and purple, while the tracks are black.
The connections are cubic Bézier curves whose control points are in the direction from each endpoint matching that endpoint's angle, at a distance from the endpoint equal to half the Euclidean distance between the two endpoints. (Bézier curves are a little weird but you can look them up. Currently I'm using http://pomax.github.io/bezierjs/ for most of the computations with them. Many graphics engines let you draw Bézier curves directly, including SVG, HTML 2D Canvas, Apple Cocoa, but not OpenGL. Currently I am creating SVG elements dynamically from Javascript. (Actually I'm using TypeScript compiled to Javascript, because having a type system really helps me figure out what I want.)
The next step is to have any trains for these tracks. Currently there are no trains.
[1] I call each of the two sides of an end-point a "switch" because more than one track can be connected to the same side of an end point. If there are more than one track on one side (and at least one track on the other side), then it will function as a switch once there are any trains. Otherwise it is a kind of silly name to call a straight-through track connection (or a dead-end) a "switch", but it works okay.
Yeah, you need the TypeScript tools. Run ./setup.sh
unless this readme sentence is out of date.
No.
No. There are unrelated things called TrainWorld, so the II was a cheesy way to give this project a more unique name.
There is no dispatcher, except maybe the viewer.
In a fantasy world, you can build train tracks and power trains for free, effortlessly. Right? Right???
HTML: index.html
CSS: style.css
JS: script.ts (typescript that you should compile to javascript)
Third party libraries:
- collections.ts
- bezier.js (I wrote bezier.d.ts to integrate it better with typescript)
I made this into a twitter-bot. It requires nodejs, npm, git,
and typescript. Compile using ./setup.sh
; add to config.js
your twitter-bot credentials and a path to a git repo with a v1/ directory;
run using ./bot.js
to post an image to twitter+github.