5 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
6 <link rel=
"icon" href=
"favicon.svg" />
9 CharmBypass: it's transit equity y'all
28 /* Set the height to
100% of the screen, which we'll keep; and the
29 * initial position to (
0,
0), which we're going to change
30 * every time the window is resized, because the exact amount
31 * that we have to slide the SVG to the left to get the ticket
32 * into the center will change. */
38 /* Hide everything by default. We only show it once the user has
39 * submitted the menu form */
43 /* The blinking fade in/out animation for the ticket date and time */
56 #tickettime, #ticketdate {
57 /*
300 two-second blinks is ten minutes */
58 animation: blink
2s linear
300;
61 /* Define, load, and specify the custom font we use for the ticket
62 * date, time, and service name. */
64 font-family: "CharmBypass Regular";
66 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
69 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
70 font-family: "CharmBypass Regular", sans-serif;
74 font-family: "CharmBypass Bold";
76 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
80 font-family: "CharmBypass Bold", sans-serif;
83 /************************/
84 /* Scrolling animations */
85 /************************/
90 transform: translateX(
0%);
93 transform: translateX(-
100%);
98 animation: busroll
23s linear infinite;
103 @keyframes tramroll {
105 transform: translateX(
0%);
108 transform: translateX(
100%);
113 animation: tramroll
17s linear infinite;
118 @keyframes trainroll {
120 transform: translateX(
0%);
123 transform: translateX(
100%);
128 animation: trainroll
11s linear infinite;
133 @keyframes cloudsfloat {
135 transform: translateX(
0%);
138 transform: translateX(-
50%);
143 animation: cloudsfloat
40s linear infinite;
146 @keyframes cloudscopyfloat {
148 transform: translateX(
0%);
151 transform: translateX(-
50%);
156 animation: cloudscopyfloat
40s linear infinite;
161 @keyframes treespass {
163 transform: translateX(
0%);
166 transform: translateX(-
50%);
171 /* The trees move a little faster than the clouds */
172 animation: treespass
30s linear infinite;
175 @keyframes treescopypass {
177 transform: translateX(
0%);
180 transform: translateX(-
50%);
185 /* The trees move a little faster than the clouds */
186 animation: treescopypass
30s linear infinite;
191 @keyframes cityscroll {
193 transform: translateX(
0%);
196 transform: translateX(-
50%);
201 /* The city moves faster than the clouds but slower
203 animation: cityscroll
35s linear infinite;
206 @keyframes citycopyscroll {
208 transform: translateX(
0%);
211 transform: translateX(-
50%);
216 /* The city moves faster than the clouds but slower
218 animation: citycopyscroll
35s linear infinite;
226 <h2>it's transit equity y'all
</h2>
229 <em>Hint:
</em> If you think the driver or fare inspector will
230 actually check it, the daily security code is the same on a
231 $
2.00 BaltimoreLink ticket as it is on a $
9.00 MARC Train
232 ticket. It's also the same on your friend's phone, or for
233 anyone else in Maryland that day.
238 <legend>Local Bus, Light Rail, or Metro
</legend>
241 Daily security code (optional):
249 pattern=
"[a-zA-Z0-9]*" />
251 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
252 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
257 <legend>Commuter Bus
</legend>
258 <input type=
"hidden" name=
"serviceid" value=
"R" />
259 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
263 Daily security code (optional):
271 pattern=
"[a-zA-Z0-9]*" />
276 <input required
type=
"radio" id=
"zone1" name=
"zone" value=
"Zone 1" />
277 <label for=
"zone1">Zone
1</label>
280 <input required
type=
"radio" id=
"zone2" name=
"zone" value=
"Zone 2" />
281 <label for=
"zone2">Zone
2</label>
284 <input required
type=
"radio" id=
"zone3" name=
"zone" value=
"Zone 3" />
285 <label for=
"zone3">Zone
3</label>
288 <input required
type=
"radio" id=
"zone4" name=
"zone" value=
"Zone 4" />
289 <label for=
"zone4">Zone
4</label>
292 <input required
type=
"radio" id=
"zone5" name=
"zone" value=
"Zone 5" />
293 <label for=
"zone5">Zone
5</label>
296 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
301 <legend>MARC Train
</legend>
305 Daily security code (optional):
313 pattern=
"[a-zA-Z0-9]*" />
318 <input required
type=
"radio" id=
"origin1" name=
"origin" value=
"BAL" />
319 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
322 <input required
type=
"radio" id=
"origin2" name=
"origin" value=
"BCA" />
323 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
326 <input required
type=
"radio" id=
"origin3" name=
"origin" value=
"BWE" />
327 <label for=
"origin3">Bowie State (Penn Line)
</label>
330 <input required
type=
"radio" id=
"origin4" name=
"origin" value=
"BWI" />
331 <label for=
"origin4">BWI Airport (Penn Line)
</label>
334 <input required
type=
"radio" id=
"origin5" name=
"origin" value=
"CPK" />
335 <label for=
"origin5">College Park (Camden Line)
</label>
338 <input required
type=
"radio" id=
"origin6" name=
"origin" value=
"SEB" />
339 <label for=
"origin6">Seabrook (Penn Line)
</label>
342 <input required
type=
"radio" id=
"origin7" name=
"origin" value=
"WAS" />
343 <label for=
"origin7">Washington D.C.
</label>
346 <input required
type=
"radio" id=
"origin8" name=
"origin" value=
"WBL" />
347 <label for=
"origin8">West Baltimore (Penn Line)
</label>
352 <input required
type=
"radio" id=
"destination1" name=
"destination" value=
"BAL" />
353 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
356 <input required
type=
"radio" id=
"destination2" name=
"destination" value=
"BCA" />
357 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
360 <input required
type=
"radio" id=
"destination3" name=
"destination" value=
"BWE" />
361 <label for=
"destination3">Bowie State (Penn Line)
</label>
364 <input required
type=
"radio" id=
"destination4" name=
"destination" value=
"BWI" />
365 <label for=
"destination4">BWI Airport (Penn Line)
</label>
368 <input required
type=
"radio" id=
"destination5" name=
"destination" value=
"CPK" />
369 <label for=
"destination5">College Park (Camden Line)
</label>
372 <input required
type=
"radio" id=
"destination6" name=
"destination" value=
"SEB" />
373 <label for=
"destination6">Seabrook (Penn Line)
</label>
376 <input required
type=
"radio" id=
"destination7" name=
"destination" value=
"WAS" />
377 <label for=
"destination7">Washington D.C.
</label>
380 <input required
type=
"radio" id=
"destination8" name=
"destination" value=
"WBL" />
381 <label for=
"destination8">West Baltimore (Penn Line)
</label>
384 <input type=
"hidden" name=
"serviceid" value=
"R" />
385 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
386 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
395 /***********************************************/
396 /* First, center the ticket within the browser */
397 /***********************************************/
399 function center_ticket() {
400 /* We're relying on the SVG being the full height of the
401 * viewport already, and on the aspect ratio being
402 * preserved. First, find the center of the ticket. */
403 const r = document.getElementById("ticket").getBoundingClientRect();
404 const c = r.left + (r.width /
2);
406 /* That's the center-line of the ticket. We want to move it to
407 * the center-line of the viewport. */
408 const vc = document.documentElement.clientWidth /
2;
410 /* This is how much we need to translate the SVG */
411 const hdelta = vc - c;
413 /* But before we can set the absolute left-coordinate of the
414 * SVG, we need to know where it is now. Note: without the
415 * "px" this doesn't default to pixels like CSS does. */
416 const svg = document.querySelector("svg");
417 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
421 /******************************/
422 /* Set the service identifier */
423 /******************************/
424 function set_service_id() {
425 const sid = document.getElementById("serviceid");
427 /* Get the "serviceid" from the querystring if it's there */
428 const params = new URLSearchParams(document.location.search);
429 if (params.get("serviceid")) {
430 sid.textContent = params.get("serviceid");
433 /* Otherwise, leave it at "F" */
436 /************************/
437 /* Set the service name */
438 /************************/
439 function set_service_name() {
440 const sid = document.getElementById("servicename");
442 /* Get the "servicename" from the querystring if it's there */
443 const params = new URLSearchParams(document.location.search);
444 if (params.get("servicename")) {
445 sid.textContent = params.get("servicename");
448 /* Otherwise, leave it at "BaltimoreLink" */
452 /************************/
453 /* Set the service zone */
454 /************************/
455 function set_service_zone(event, zone) {
456 /* We can take the zone as a parameter too; this allows us to
457 * use this function for the (computed) MARC Train zone and
458 * not just the querystring Commuter Bus zone. The extra
459 * "event" parameter is there for the event listener, which
460 * would otherwise stuff an onload event into the zone
461 * parameter. "Thankfully" javascript lets us call a
462 * two-argument function with one argument and thereby abuse
463 * the event handler for this. */
464 const z = document.getElementById("zone");
465 const params = new URLSearchParams(document.location.search);
468 z.textContent = zone;
469 z.style.display = "block"; /* It's hidden by default */
471 else if (params.get("zone")) {
472 /* Get the "zone" from the querystring if it's there */
473 z.textContent = params.get("zone");
474 z.style.display = "block"; /* It's hidden by default */
477 /* Otherwise, leave it blank (and hidden) */
480 /***********************************************************/
481 /* Resize the ticket background based on the service name */
482 /***********************************************************/
484 function resize_ticket() {
485 /* Get the "servicename" from the querystring if it's there */
486 const params = new URLSearchParams(document.location.search);
487 const tbg = document.getElementById("ticketbg");
488 const t = document.getElementById("ticket");
489 const sn = document.getElementById("servicename");
491 if (params.get("servicename") == "Commuter Bus") {
492 /* The top of the background is initially at y=
246.859, and
493 * we scale it by a factor of
1.12 to y=
276.482 for a change
494 * of
29.623. So after we scale it, we translate it upwards
495 * by that amount to put it back where it started. */
496 tbg.setAttribute("transform", "translate(
0 -
29.623) scale(
1 1.12)");
498 /* Now translate the entire ticket up by the magic amount,
1/
5
499 * of the size change we made to the background. This ratio
500 * was found by measuring pixels in side-by-side screenshots
501 * of BaltimoreLink and Commuter Bus tickets. */
502 t.setAttribute("transform", "translate(
0 -
9.33)");
504 /* More magic numbers discovered by comparing the two
505 * tickets overlayed in inkscape */
506 sn.setAttribute("transform", "translate(
0 64.28)");
508 else if (params.get("servicename") == "MARC Train") {
509 /* insane tricks are explained above */
510 tbg.setAttribute("transform",
511 "translate(
0 -
72.378) scale(
1 1.2932)");
512 t.setAttribute("transform", "translate(
0 -
67.17)");
513 sn.setAttribute("transform", "translate(
0 131.0)");
516 /* Otherwise, leave it alone. The SVG was designed with the
517 * BaltimoreLink ticket in mind */
520 /****************************************/
521 /* Set and reposition the security code */
522 /****************************************/
524 function set_code() {
525 const ct = document.getElementById("codetext");
527 /* Get the "code" from the querystring if it's there */
528 const params = new URLSearchParams(document.location.search);
529 if (params.get("code")) {
530 ct.textContent = params.get("code").toUpperCase();
533 /* Otherwise, use a random code */
534 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
535 "A","B","C","D","E","F","G","H","I","J",
536 "K","L","M","N","O","P","Q","R","S","T",
537 "U","V","W","X","Y","Z"];
539 /* Two random ints between
0 and
35 */
540 const i1 = Math.floor(Math.random() *
36);
541 const i2 = Math.floor(Math.random() *
36);
542 const d1 = bucket[i1];
543 const d2 = bucket[i2];
544 ct.textContent = d1 + d2;
549 function center_code() {
550 /* Center the security code inside its red box */
551 const ct = document.getElementById("codetext");
552 const bg = document.getElementById("codebg");
554 /* First, find the center of the red box */
555 const r1 = bg.getBoundingClientRect();
556 const c1 = r1.left + (r1.width /
2);
558 /* Now the center of the code text */
559 const r2 = ct.getBoundingClientRect();
560 const c2 = r2.left + (r2.width /
2);
562 /* What do we add to c2 to make it equal to c1? */
563 const hdelta = c1 - c2;
565 /* We've measured everything so far in "client rect"
566 * coordinates, because that's the only available measurement
567 * we have for the width of the
<text> element after futzing
568 * with its contents. But when we reposition that
<text>
569 * element, it will be by adjusting its "x" attribute, and
570 * that attribute uses a different coordinate system than the
571 * client rect does. Specifically, "x" refers to an offset
572 * within the SVG's coordinate system, and the client rect
573 * coordinates are pixels on-screen. To convert between the
574 * two, we can take the "width" attribute of the background
575 * element and compare it to the width of the background
576 * element's client rect. Since the size of the background is
577 * fixed, this should give us a multiplier that turns client recr
578 * distances (what we have) into SVG distances (what we want) */
579 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
581 /* Convert hdelta from client rect to SVG coordinates */
582 const svg_hdelta = hdelta * client_to_svg;
584 /* Since this
<text> element has an "x" attribute it's easier for
585 * us to shift that than it is to mess with the "left" style. */
586 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
589 /*****************************************/
590 /* Next, set up the ticket date and time */
591 /*****************************************/
593 function set_ticket_expiry() {
594 /* There are two parameters, time and date, that we store in one
595 * underlying "date" variable. Default both to an hour and a
596 * half from now. This is what the CharmPass app does for
597 * one-way tickets. */
598 const date = new Date();
600 /* BaltimoreLink and MARC Train are valid for an hour and a half */
602 const params = new URLSearchParams(document.location.search);
603 if (params.get("servicename") == "Commuter Bus") {
604 /* But commuter bus tickets are only valid for ten minutes */
608 /* We use the low-level get/setTime to change the number of
609 * milliseconds since the epoch that this date represents
610 * Obviously correct, and avoids all suspicious corner cases
611 * for a few more decades. */
612 date.setTime(date.getTime() + (minutes*
60*
1000));
614 tt = document.getElementById("tickettime");
615 tt.textContent = date.toLocaleTimeString();
617 const td = document.getElementById("ticketdate");
623 td.textContent = date.toLocaleDateString("en-US", dateopts);
627 /*********************************************************/
628 /* Finally, the onclick handler for the night/day switch */
629 /*********************************************************/
631 /* We always start in "day" mode */
635 sky.style.fill = "#efb02f";
638 function set_night() {
639 sky.style.fill = "#
143b66";
642 function swap_colors() {
654 /*******************************************************/
655 /* Compute the MARC "zone" from its origin/destination */
656 /*******************************************************/
658 /* Sorted on the first component, then the second */
672 /* Compute the zone (string) for the given origin/destination pair.
673 * If we don't know it or if you chose in invalid pair (destination
674 * not on the same line as your origin?) then the empty string is
676 function compute_marc_zone(src, dest) {
677 /* Forward direction key for zone_map */
678 const fwd = src + "_" + dest;
680 /* Reverse direction key for zone_map. The zone_map only
681 * has them listed in one direction, so we check both
682 * directions here. */
683 const rev = dest + "_" + src;
685 /* The default. Obviously wrong for when we don't
686 * have the necessary data. */
690 zone = zone_map[fwd];
692 else if (zone_map[rev]) {
693 zone = zone_map[rev];
696 /* Convert the number to a string */
711 function set_marc_zone() {
712 const params = new URLSearchParams(document.location.search);
713 if (params.get("origin") && params.get("destination")) {
714 const src = params.get("origin");
715 const dest = params.get("destination");
716 const zone = compute_marc_zone(src, dest);
718 set_service_zone(null, zone);
723 /*****************************************************/
724 /* Set the origin and destination for the MARC Train */
725 /*****************************************************/
727 function set_marc_origin_destination() {
728 const params = new URLSearchParams(document.location.search);
729 if (!params.get("origin") || !params.get("destination")) {
733 const src = params.get("origin");
734 const dest = params.get("destination");
736 /* origindest contains both the origin and destination */
737 const origindest = document.getElementById("origindest");
739 const origin = document.getElementById("origin");
740 const destination = document.getElementById("destination");
742 origin.textContent = params.get("origin");
743 destination.textContent = params.get("destination");
745 origindest.style.display = "block"; /* It's hidden by default */
748 /******************************************/
749 /* Display the ticket (and hide the menu) */
750 /******************************************/
753 /* To create our "window" onto the scene, we're going to slide the
754 * SVG off the left-hand side of the screen, and we don't want
755 * scroll bars to appear. */
756 document.body.style.overflow = "hidden";
757 document.body.style.margin = "
0";
758 document.body.style.padding = "
0";
760 const svg = document.querySelector("svg");
761 const menu = document.getElementById("menu");
762 svg.style.display = "initial";
763 menu.style.display = "none";
766 /*****************************************************/
767 /* Add event handlers for all of the functions above */
768 /*****************************************************/
770 const params = new URLSearchParams(document.location.search);
771 if (params.get("go")) {
772 /* First unhide the SVG (swap it with the form) */
773 window.addEventListener("load", go);
775 /* Center the ticket once when the page has loaded */
776 window.addEventListener("load", center_ticket);
778 /* Re-center the ticket when the window is resized */
779 window.addEventListener("resize", center_ticket);
781 /* Set the service identifier when the page has loaded */
782 window.addEventListener("load", set_service_id);
784 /* Set the service name when the page has loaded */
785 window.addEventListener("load", set_service_name);
787 /* Set the service zone when the page has loaded */
788 window.addEventListener("load", set_service_zone);
790 /* Resize the ticket background if necessary */
791 window.addEventListener("load", resize_ticket);
793 /* Set the security code text when the page has loaded */
794 window.addEventListener("load", set_code);
796 /* Center the security code text when the page has loaded; in
797 * particular, after we set the code. */
798 window.addEventListener("load", center_code);
800 /* Set the ticket expiration date/time upon page load */
801 window.addEventListener("load", set_ticket_expiry);
803 /* Set the MARC Train origin and destination, if applicable */
804 window.addEventListener("load", set_marc_origin_destination);
806 /* Set the MARC Train zone, if applicable */
807 window.addEventListener("load", set_marc_zone);
809 /* Swap colors when the screen is tapped */
810 document.body.addEventListener("click", swap_colors);