5 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
8 href=
"data:image/svg+xml;base64,@FAVICON@" />
11 CharmBypass: it's transit equity y'all
30 /* Set the height to
100% of the screen, which we'll keep; and the
31 * initial position to (
0,
0), which we're going to change
32 * every time the window is resized, because the exact amount
33 * that we have to slide the SVG to the left to get the ticket
34 * into the center will change. */
40 /* Hide everything by default. We only show it once the user has
41 * submitted the menu form */
45 /* The blinking fade in/out animation for the ticket date and time */
52 #tickettime, #ticketdate {
53 /*
300 two-second blinks is ten minutes */
54 animation: blink
2s linear
300;
57 /* Define, load, and specify the custom font we use for the ticket
58 * date, time, and service name. */
60 font-family: "CharmBypass Regular";
62 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
65 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
66 font-family: "CharmBypass Regular", sans-serif;
70 font-family: "CharmBypass Bold";
72 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
76 font-family: "CharmBypass Bold", sans-serif;
79 /************************/
80 /* Scrolling animations */
81 /************************/
85 from { transform: translateX(
0%); }
86 to { transform: translateX(-
100%); }
90 animation: busroll
23s linear infinite;
96 from { transform: translateX(
0%); }
97 to { transform: translateX(
100%); }
101 animation: tramroll
17s linear infinite;
106 @keyframes trainroll {
107 from { transform: translateX(
0%); }
108 to { transform: translateX(
100%); }
112 animation: trainroll
11s linear infinite;
117 @keyframes cloudsfloat {
118 from { transform: translateX(
0%); }
119 to { transform: translateX(-
50%); }
123 animation: cloudsfloat
40s linear infinite;
126 @keyframes cloudscopyfloat {
127 from { transform: translateX(
0%); }
128 to { transform: translateX(-
50%); }
132 animation: cloudscopyfloat
40s linear infinite;
137 @keyframes treespass {
138 from { transform: translateX(
0%); }
139 to { transform: translateX(-
50%); }
143 /* The trees move a little faster than the clouds */
144 animation: treespass
30s linear infinite;
147 @keyframes treescopypass {
148 from { transform: translateX(
0%); }
149 to { transform: translateX(-
50%); }
153 /* The trees move a little faster than the clouds */
154 animation: treescopypass
30s linear infinite;
159 @keyframes cityscroll {
160 from { transform: translateX(
0%); }
161 to { transform: translateX(-
50%); }
165 /* The city moves faster than the clouds but slower
167 animation: cityscroll
35s linear infinite;
170 @keyframes citycopyscroll {
171 from { transform: translateX(
0%); }
172 to { transform: translateX(-
50%); }
176 /* The city moves faster than the clouds but slower
178 animation: citycopyscroll
35s linear infinite;
186 <h2>it's transit equity y'all
</h2>
189 <em>Hint:
</em> If you think the driver or fare inspector will
190 actually check it, the daily security code is the same on a
191 $
2.00 BaltimoreLink ticket as it is on a $
9.00 MARC Train
192 ticket. It's also the same on your friend's phone, or for
193 anyone else in Maryland that day.
198 <legend>Local Bus, Light Rail, or Metro
</legend>
201 Daily security code (optional):
209 pattern=
"[a-zA-Z0-9]*" />
211 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
212 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
217 <legend>Commuter Bus
</legend>
218 <input type=
"hidden" name=
"serviceid" value=
"R" />
219 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
223 Daily security code (optional):
231 pattern=
"[a-zA-Z0-9]*" />
236 <input type=
"radio" required
240 <label for=
"zone1">Zone
1</label>
243 <input type=
"radio" required
247 <label for=
"zone2">Zone
2</label>
250 <input type=
"radio" required
254 <label for=
"zone3">Zone
3</label>
257 <input type=
"radio" required
261 <label for=
"zone4">Zone
4</label>
264 <input type=
"radio" required
268 <label for=
"zone5">Zone
5</label>
271 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
276 <legend>MARC Train
</legend>
280 Daily security code (optional):
288 pattern=
"[a-zA-Z0-9]*" />
293 <input type=
"radio" required
297 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
300 <input type=
"radio" required
304 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
307 <input type=
"radio" required
311 <label for=
"origin3">Bowie State (Penn Line)
</label>
314 <input type=
"radio" required
318 <label for=
"origin4">BWI Airport (Penn Line)
</label>
321 <input type=
"radio" required
325 <label for=
"origin5">College Park (Camden Line)
</label>
328 <input type=
"radio" required
332 <label for=
"origin6">Seabrook (Penn Line)
</label>
335 <input type=
"radio" required
339 <label for=
"origin7">Washington D.C.
</label>
342 <input type=
"radio" required
346 <label for=
"origin8">West Baltimore (Penn Line)
</label>
351 <input type=
"radio" required
355 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
358 <input type=
"radio" required
362 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
365 <input type=
"radio" required
369 <label for=
"destination3">Bowie State (Penn Line)
</label>
372 <input type=
"radio" required
376 <label for=
"destination4">BWI Airport (Penn Line)
</label>
379 <input type=
"radio" required
383 <label for=
"destination5">College Park (Camden Line)
</label>
386 <input type=
"radio" required
390 <label for=
"destination6">Seabrook (Penn Line)
</label>
393 <input type=
"radio" required
397 <label for=
"destination7">Washington D.C.
</label>
400 <input type=
"radio" required
404 <label for=
"destination8">West Baltimore (Penn Line)
</label>
407 <input type=
"hidden" name=
"serviceid" value=
"R" />
408 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
409 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
418 /***********************************************/
419 /* First, center the ticket within the browser */
420 /***********************************************/
422 function center_ticket() {
423 /* We're relying on the SVG being the full height of the
424 * viewport already, and on the aspect ratio being
425 * preserved. First, find the center of the ticket. */
426 const r = document.getElementById("ticket").getBoundingClientRect();
427 const c = r.left + (r.width /
2);
429 /* That's the center-line of the ticket. We want to move it to
430 * the center-line of the viewport. */
431 const vc = document.documentElement.clientWidth /
2;
433 /* This is how much we need to translate the SVG */
434 const hdelta = vc - c;
436 /* But before we can set the absolute left-coordinate of the
437 * SVG, we need to know where it is now. Note: without the
438 * "px" this doesn't default to pixels like CSS does. */
439 const svg = document.querySelector("svg");
440 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
444 /******************************/
445 /* Set the service identifier */
446 /******************************/
447 function set_service_id() {
448 const sid = document.getElementById("serviceid");
450 /* Get the "serviceid" from the querystring if it's there */
451 const params = new URLSearchParams(document.location.search);
452 if (params.get("serviceid")) {
453 sid.textContent = params.get("serviceid");
456 /* Otherwise, leave it at "F" */
459 /************************/
460 /* Set the service name */
461 /************************/
462 function set_service_name() {
463 const sid = document.getElementById("servicename");
465 /* Get the "servicename" from the querystring if it's there */
466 const params = new URLSearchParams(document.location.search);
467 if (params.get("servicename")) {
468 sid.textContent = params.get("servicename");
471 /* Otherwise, leave it at "BaltimoreLink" */
475 /************************/
476 /* Set the service zone */
477 /************************/
478 function set_service_zone(event, zone) {
479 /* We can take the zone as a parameter too; this allows us to
480 * use this function for the (computed) MARC Train zone and
481 * not just the querystring Commuter Bus zone. The extra
482 * "event" parameter is there for the event listener, which
483 * would otherwise stuff an onload event into the zone
484 * parameter. "Thankfully" javascript lets us call a
485 * two-argument function with one argument and thereby abuse
486 * the event handler for this. */
487 const z = document.getElementById("zone");
488 const params = new URLSearchParams(document.location.search);
491 z.textContent = zone;
492 z.style.display = "block"; /* It's hidden by default */
494 else if (params.get("zone")) {
495 /* Get the "zone" from the querystring if it's there */
496 z.textContent = params.get("zone");
497 z.style.display = "block"; /* It's hidden by default */
500 /* Otherwise, leave it blank (and hidden) */
503 /***********************************************************/
504 /* Resize the ticket background based on the service name */
505 /***********************************************************/
507 function resize_ticket() {
508 /* Get the "servicename" from the querystring if it's there */
509 const params = new URLSearchParams(document.location.search);
510 const tbg = document.getElementById("ticketbg");
511 const t = document.getElementById("ticket");
512 const sn = document.getElementById("servicename");
514 if (params.get("servicename") == "Commuter Bus") {
515 /* The top of the background is initially at y=
246.859, and
516 * we scale it by a factor of
1.12 to y=
276.482 for a change
517 * of
29.623. So after we scale it, we translate it upwards
518 * by that amount to put it back where it started. */
519 tbg.setAttribute("transform", "translate(
0 -
29.623) scale(
1 1.12)");
521 /* Now translate the entire ticket up by the magic amount,
1/
5
522 * of the size change we made to the background. This ratio
523 * was found by measuring pixels in side-by-side screenshots
524 * of BaltimoreLink and Commuter Bus tickets. */
525 t.setAttribute("transform", "translate(
0 -
9.33)");
527 /* More magic numbers discovered by comparing the two
528 * tickets overlayed in inkscape */
529 sn.setAttribute("transform", "translate(
0 64.28)");
531 else if (params.get("servicename") == "MARC Train") {
532 /* insane tricks are explained above */
533 tbg.setAttribute("transform",
534 "translate(
0 -
72.378) scale(
1 1.2932)");
535 t.setAttribute("transform", "translate(
0 -
67.17)");
536 sn.setAttribute("transform", "translate(
0 131.0)");
539 /* Otherwise, leave it alone. The SVG was designed with the
540 * BaltimoreLink ticket in mind */
543 /****************************************/
544 /* Set and reposition the security code */
545 /****************************************/
547 function set_code() {
548 const ct = document.getElementById("codetext");
550 /* Get the "code" from the querystring if it's there */
551 const params = new URLSearchParams(document.location.search);
552 if (params.get("code")) {
553 ct.textContent = params.get("code").toUpperCase();
556 /* Otherwise, use a random code */
557 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
558 "A","B","C","D","E","F","G","H","I","J",
559 "K","L","M","N","O","P","Q","R","S","T",
560 "U","V","W","X","Y","Z"];
562 /* Two random ints between
0 and
35 */
563 const i1 = Math.floor(Math.random() *
36);
564 const i2 = Math.floor(Math.random() *
36);
565 const d1 = bucket[i1];
566 const d2 = bucket[i2];
567 ct.textContent = d1 + d2;
572 function center_code() {
573 /* Center the security code inside its red box */
574 const ct = document.getElementById("codetext");
575 const bg = document.getElementById("codebg");
577 /* First, find the center of the red box */
578 const r1 = bg.getBoundingClientRect();
579 const c1 = r1.left + (r1.width /
2);
581 /* Now the center of the code text */
582 const r2 = ct.getBoundingClientRect();
583 const c2 = r2.left + (r2.width /
2);
585 /* What do we add to c2 to make it equal to c1? */
586 const hdelta = c1 - c2;
588 /* We've measured everything so far in "client rect"
589 * coordinates, because that's the only available measurement
590 * we have for the width of the
<text> element after futzing
591 * with its contents. But when we reposition that
<text>
592 * element, it will be by adjusting its "x" attribute, and
593 * that attribute uses a different coordinate system than the
594 * client rect does. Specifically, "x" refers to an offset
595 * within the SVG's coordinate system, and the client rect
596 * coordinates are pixels on-screen. To convert between the
597 * two, we can take the "width" attribute of the background
598 * element and compare it to the width of the background
599 * element's client rect. Since the size of the background is
600 * fixed, this should give us a multiplier that turns client recr
601 * distances (what we have) into SVG distances (what we want) */
602 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
604 /* Convert hdelta from client rect to SVG coordinates */
605 const svg_hdelta = hdelta * client_to_svg;
607 /* Since this
<text> element has an "x" attribute it's easier for
608 * us to shift that than it is to mess with the "left" style. */
609 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
612 /*****************************************/
613 /* Next, set up the ticket date and time */
614 /*****************************************/
616 function set_ticket_expiry() {
617 /* There are two parameters, time and date, that we store in one
618 * underlying "date" variable. Default both to an hour and a
619 * half from now. This is what the CharmPass app does for
620 * one-way tickets. */
621 const date = new Date();
623 /* BaltimoreLink and MARC Train are valid for an hour and a half */
625 const params = new URLSearchParams(document.location.search);
626 if (params.get("servicename") == "Commuter Bus") {
627 /* But commuter bus tickets are only valid for ten minutes */
631 /* We use the low-level get/setTime to change the number of
632 * milliseconds since the epoch that this date represents
633 * Obviously correct, and avoids all suspicious corner cases
634 * for a few more decades. */
635 date.setTime(date.getTime() + (minutes*
60*
1000));
637 tt = document.getElementById("tickettime");
638 tt.textContent = date.toLocaleTimeString();
640 const td = document.getElementById("ticketdate");
646 td.textContent = date.toLocaleDateString("en-US", dateopts);
650 /*********************************************************/
651 /* Finally, the onclick handler for the night/day switch */
652 /*********************************************************/
654 /* We always start in "day" mode */
658 sky.style.fill = "#efb02f";
661 function set_night() {
662 sky.style.fill = "#
143b66";
665 function swap_colors() {
677 /*******************************************************/
678 /* Compute the MARC "zone" from its origin/destination */
679 /*******************************************************/
681 /* Sorted on the first component, then the second */
695 /* Compute the zone (string) for the given origin/destination pair.
696 * If we don't know it or if you chose in invalid pair (destination
697 * not on the same line as your origin?) then the empty string is
699 function compute_marc_zone(src, dest) {
700 /* Forward direction key for zone_map */
701 const fwd = src + "_" + dest;
703 /* Reverse direction key for zone_map. The zone_map only
704 * has them listed in one direction, so we check both
705 * directions here. */
706 const rev = dest + "_" + src;
708 /* The default. Obviously wrong for when we don't
709 * have the necessary data. */
713 zone = zone_map[fwd];
715 else if (zone_map[rev]) {
716 zone = zone_map[rev];
719 /* Convert the number to a string */
734 function set_marc_zone() {
735 const params = new URLSearchParams(document.location.search);
736 if (params.get("origin") && params.get("destination")) {
737 const src = params.get("origin");
738 const dest = params.get("destination");
739 const zone = compute_marc_zone(src, dest);
741 set_service_zone(null, zone);
746 /*****************************************************/
747 /* Set the origin and destination for the MARC Train */
748 /*****************************************************/
750 function set_marc_origin_destination() {
751 const params = new URLSearchParams(document.location.search);
752 if (!params.get("origin") || !params.get("destination")) {
756 const src = params.get("origin");
757 const dest = params.get("destination");
759 /* origindest contains both the origin and destination */
760 const origindest = document.getElementById("origindest");
762 const origin = document.getElementById("origin");
763 const destination = document.getElementById("destination");
765 origin.textContent = params.get("origin");
766 destination.textContent = params.get("destination");
768 origindest.style.display = "block"; /* It's hidden by default */
771 /******************************************/
772 /* Display the ticket (and hide the menu) */
773 /******************************************/
776 /* To create our "window" onto the scene, we're going to slide the
777 * SVG off the left-hand side of the screen, and we don't want
778 * scroll bars to appear. */
779 document.body.style.overflow = "hidden";
780 document.body.style.margin = "
0";
781 document.body.style.padding = "
0";
783 const svg = document.querySelector("svg");
784 const menu = document.getElementById("menu");
785 svg.style.display = "initial";
786 menu.style.display = "none";
789 /*****************************************************/
790 /* Add event handlers for all of the functions above */
791 /*****************************************************/
793 const params = new URLSearchParams(document.location.search);
794 if (params.get("go")) {
795 /* First unhide the SVG (swap it with the form) */
796 window.addEventListener("load", go);
798 /* Center the ticket once when the page has loaded */
799 window.addEventListener("load", center_ticket);
801 /* Re-center the ticket when the window is resized */
802 window.addEventListener("resize", center_ticket);
804 /* Set the service identifier when the page has loaded */
805 window.addEventListener("load", set_service_id);
807 /* Set the service name when the page has loaded */
808 window.addEventListener("load", set_service_name);
810 /* Set the service zone when the page has loaded */
811 window.addEventListener("load", set_service_zone);
813 /* Resize the ticket background if necessary */
814 window.addEventListener("load", resize_ticket);
816 /* Set the security code text when the page has loaded */
817 window.addEventListener("load", set_code);
819 /* Center the security code text when the page has loaded; in
820 * particular, after we set the code. */
821 window.addEventListener("load", center_code);
823 /* Set the ticket expiration date/time upon page load */
824 window.addEventListener("load", set_ticket_expiry);
826 /* Set the MARC Train origin and destination, if applicable */
827 window.addEventListener("load", set_marc_origin_destination);
829 /* Set the MARC Train zone, if applicable */
830 window.addEventListener("load", set_marc_zone);
832 /* Swap colors when the screen is tapped */
833 document.body.addEventListener("click", swap_colors);