4 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
5 <link rel=
"icon" href=
"favicon.svg" />
8 CharmBypass: it's transit equity y'all
18 /* Set the height to
100% of the screen, which we'll keep; and the
19 * initial position to (
0,
0), which we're going to change
20 * every time the window is resized, because the exact amount
21 * that we have to slide the SVG to the left to get the ticket
22 * into the center will change. */
28 /* Hide everything by default. We only show it once the user has
29 * submitted the menu form */
33 /* The blinking fade in/out animation for the ticket date and time */
46 #tickettime, #ticketdate {
47 /*
300 two-second blinks is ten minutes */
48 animation: blink
2s linear
300;
51 /* Define, load, and specify the custom font we use for the ticket
52 * date, time, and service name. */
54 font-family: "CharmBypass Regular";
56 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
59 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
60 font-family: "CharmBypass Regular", sans-serif;
64 font-family: "CharmBypass Bold";
66 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
70 font-family: "CharmBypass Bold", sans-serif;
73 /************************/
74 /* Scrolling animations */
75 /************************/
80 transform: translateX(
0%);
83 transform: translateX(-
100%);
88 animation: busroll
23s linear infinite;
95 transform: translateX(
0%);
98 transform: translateX(
100%);
103 animation: tramroll
17s linear infinite;
108 @keyframes trainroll {
110 transform: translateX(
0%);
113 transform: translateX(
100%);
118 animation: trainroll
11s linear infinite;
123 @keyframes cloudsfloat {
125 transform: translateX(
0%);
128 transform: translateX(-
50%);
133 animation: cloudsfloat
40s linear infinite;
136 @keyframes cloudscopyfloat {
138 transform: translateX(
0%);
141 transform: translateX(-
50%);
146 animation: cloudscopyfloat
40s linear infinite;
151 @keyframes treespass {
153 transform: translateX(
0%);
156 transform: translateX(-
50%);
161 /* The trees move a little faster than the clouds */
162 animation: treespass
30s linear infinite;
165 @keyframes treescopypass {
167 transform: translateX(
0%);
170 transform: translateX(-
50%);
175 /* The trees move a little faster than the clouds */
176 animation: treescopypass
30s linear infinite;
181 @keyframes cityscroll {
183 transform: translateX(
0%);
186 transform: translateX(-
50%);
191 /* The city moves faster than the clouds but slower
193 animation: cityscroll
35s linear infinite;
196 @keyframes citycopyscroll {
198 transform: translateX(
0%);
201 transform: translateX(-
50%);
206 /* The city moves faster than the clouds but slower
208 animation: citycopyscroll
35s linear infinite;
216 <h2>it's transit equity y'all
</h2>
219 <em>Hint:
</em> If you think the driver or fare inspector will
220 actually check it, the daily security code is the same on a
221 $
2.00 BaltimoreLink ticket as it is on a $
9.00 MARC Train
222 ticket. It's also the same on your friend's phone, or for
223 anyone else in Maryland that day.
228 <legend>BaltimoreLink (Bus, Light Rail, Metro)
</legend>
231 Daily security code (optional):
239 pattern=
"[a-zA-Z0-9]*" />
241 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
242 <input type=
"submit" name=
"go" value=
"Get Ticket" />
247 <legend>Commuter Bus
</legend>
248 <input type=
"hidden" name=
"serviceid" value=
"R" />
249 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
253 Daily security code (optional):
261 pattern=
"[a-zA-Z0-9]*" />
266 <input required
type=
"radio" id=
"zone1" name=
"zone" value=
"Zone 1" />
267 <label for=
"zone1">Zone
1</label>
270 <input required
type=
"radio" id=
"zone2" name=
"zone" value=
"Zone 2" />
271 <label for=
"zone2">Zone
2</label>
274 <input required
type=
"radio" id=
"zone3" name=
"zone" value=
"Zone 3" />
275 <label for=
"zone3">Zone
3</label>
278 <input required
type=
"radio" id=
"zone4" name=
"zone" value=
"Zone 4" />
279 <label for=
"zone4">Zone
4</label>
282 <input required
type=
"radio" id=
"zone5" name=
"zone" value=
"Zone 5" />
283 <label for=
"zone5">Zone
5</label>
286 <input type=
"submit" name=
"go" value=
"Get Ticket" />
291 <legend>MARC Train
</legend>
295 Daily security code (optional):
303 pattern=
"[a-zA-Z0-9]*" />
309 <input required
type=
"radio" id=
"origin1" name=
"origin" value=
"BAL" />
310 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
313 <input required
type=
"radio" id=
"origin2" name=
"origin" value=
"BCA" />
314 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
317 <input required
type=
"radio" id=
"origin3" name=
"origin" value=
"BWE" />
318 <label for=
"origin3">Bowie State (Penn Line)
</label>
321 <input required
type=
"radio" id=
"origin4" name=
"origin" value=
"BWI" />
322 <label for=
"origin4">BWI Airport (Penn Line)
</label>
325 <input required
type=
"radio" id=
"origin5" name=
"origin" value=
"CPK" />
326 <label for=
"origin5">College Park (Camden Line)
</label>
329 <input required
type=
"radio" id=
"origin6" name=
"origin" value=
"SEB" />
330 <label for=
"origin6">Seabrook (Penn Line)
</label>
333 <input required
type=
"radio" id=
"origin7" name=
"origin" value=
"WAS" />
334 <label for=
"origin7">Washington D.C.
</label>
337 <input required
type=
"radio" id=
"origin8" name=
"origin" value=
"WBL" />
338 <label for=
"origin8">West Baltimore (Penn Line)
</label>
343 <input required
type=
"radio" id=
"destination1" name=
"destination" value=
"BAL" />
344 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
347 <input required
type=
"radio" id=
"destination2" name=
"destination" value=
"BCA" />
348 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
351 <input required
type=
"radio" id=
"destination3" name=
"destination" value=
"BWE" />
352 <label for=
"destination3">Bowie State (Penn Line)
</label>
355 <input required
type=
"radio" id=
"destination4" name=
"destination" value=
"BWI" />
356 <label for=
"destination4">BWI Airport (Penn Line)
</label>
359 <input required
type=
"radio" id=
"destination5" name=
"destination" value=
"CPK" />
360 <label for=
"destination5">College Park (Camden Line)
</label>
363 <input required
type=
"radio" id=
"destination6" name=
"destination" value=
"SEB" />
364 <label for=
"destination6">Seabrook (Penn Line)
</label>
367 <input required
type=
"radio" id=
"destination7" name=
"destination" value=
"WAS" />
368 <label for=
"destination7">Washington D.C.
</label>
371 <input required
type=
"radio" id=
"destination8" name=
"destination" value=
"WBL" />
372 <label for=
"destination8">West Baltimore (Penn Line)
</label>
375 <input type=
"hidden" name=
"serviceid" value=
"R" />
376 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
377 <input type=
"submit" name=
"go" value=
"Get Ticket" />
386 /***********************************************/
387 /* First, center the ticket within the browser */
388 /***********************************************/
390 function center_ticket() {
391 /* We're relying on the SVG being the full height of the
392 * viewport already, and on the aspect ratio being
393 * preserved. First, find the center of the ticket. */
394 const r = document.getElementById("ticket").getBoundingClientRect();
395 const c = r.left + (r.width /
2);
397 /* That's the center-line of the ticket. We want to move it to
398 * the center-line of the viewport. */
399 const vc = document.documentElement.clientWidth /
2;
401 /* This is how much we need to translate the SVG */
402 const hdelta = vc - c;
404 /* But before we can set the absolute left-coordinate of the
405 * SVG, we need to know where it is now. Note: without the
406 * "px" this doesn't default to pixels like CSS does. */
407 const svg = document.querySelector("svg");
408 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
412 /******************************/
413 /* Set the service identifier */
414 /******************************/
415 function set_service_id() {
416 const sid = document.getElementById("serviceid");
418 /* Get the "serviceid" from the querystring if it's there */
419 const params = new URLSearchParams(document.location.search);
420 if (params.get("serviceid")) {
421 sid.textContent = params.get("serviceid");
424 /* Otherwise, leave it at "F" */
427 /************************/
428 /* Set the service name */
429 /************************/
430 function set_service_name() {
431 const sid = document.getElementById("servicename");
433 /* Get the "servicename" from the querystring if it's there */
434 const params = new URLSearchParams(document.location.search);
435 if (params.get("servicename")) {
436 sid.textContent = params.get("servicename");
439 /* Otherwise, leave it at "BaltimoreLink" */
443 /************************/
444 /* Set the service zone */
445 /************************/
446 function set_service_zone(event, zone) {
447 /* We can take the zone as a parameter too; this allows us to
448 * use this function for the (computed) MARC Train zone and
449 * not just the querystring Commuter Bus zone. The extra
450 * "event" parameter is there for the event listener, which
451 * would otherwise stuff an onload event into the zone
452 * parameter. "Thankfully" javascript lets us call a
453 * two-argument function with one argument and thereby abuse
454 * the event handler for this. */
455 const z = document.getElementById("zone");
456 const params = new URLSearchParams(document.location.search);
459 z.textContent = zone;
460 z.style.display = "block"; /* It's hidden by default */
462 else if (params.get("zone")) {
463 /* Get the "zone" from the querystring if it's there */
464 z.textContent = params.get("zone");
465 z.style.display = "block"; /* It's hidden by default */
468 /* Otherwise, leave it blank (and hidden) */
471 /***********************************************************/
472 /* Resize the ticket background based on the service name */
473 /***********************************************************/
475 function resize_ticket() {
476 /* Get the "servicename" from the querystring if it's there */
477 const params = new URLSearchParams(document.location.search);
478 const tbg = document.getElementById("ticketbg");
479 const t = document.getElementById("ticket");
480 const sn = document.getElementById("servicename");
482 if (params.get("servicename") == "Commuter Bus") {
483 /* The top of the background is initially at y=
246.859, and
484 * we scale it by a factor of
1.12 to y=
276.482 for a change
485 * of
29.623. So after we scale it, we translate it upwards
486 * by that amount to put it back where it started. */
487 tbg.setAttribute("transform", "translate(
0 -
29.623) scale(
1 1.12)");
489 /* Now translate the entire ticket up by the magic amount,
1/
5
490 * of the size change we made to the background. This ratio
491 * was found by measuring pixels in side-by-side screenshots
492 * of BaltimoreLink and Commuter Bus tickets. */
493 t.setAttribute("transform", "translate(
0 -
9.33)");
495 /* More magic numbers discovered by comparing the two
496 * tickets overlayed in inkscape */
497 sn.setAttribute("transform", "translate(
0 64.28)");
499 else if (params.get("servicename") == "MARC Train") {
500 /* insane tricks are explained above */
501 tbg.setAttribute("transform",
502 "translate(
0 -
72.378) scale(
1 1.2932)");
503 t.setAttribute("transform", "translate(
0 -
67.17)");
504 sn.setAttribute("transform", "translate(
0 131.0)");
507 /* Otherwise, leave it alone. The SVG was designed with the
508 * BaltimoreLink ticket in mind */
511 /****************************************/
512 /* Set and reposition the security code */
513 /****************************************/
515 function set_code() {
516 const ct = document.getElementById("codetext");
518 /* Get the "code" from the querystring if it's there */
519 const params = new URLSearchParams(document.location.search);
520 if (params.get("code")) {
521 ct.textContent = params.get("code").toUpperCase();
524 /* Otherwise, use a random code */
525 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
526 "A","B","C","D","E","F","G","H","I","J",
527 "K","L","M","N","O","P","Q","R","S","T",
528 "U","V","W","X","Y","Z"];
530 /* Two random ints between
0 and
35 */
531 const i1 = Math.floor(Math.random() *
36);
532 const i2 = Math.floor(Math.random() *
36);
533 const d1 = bucket[i1];
534 const d2 = bucket[i2];
535 ct.textContent = d1 + d2;
540 function center_code() {
541 /* Center the security code inside its red box */
542 const ct = document.getElementById("codetext");
543 const bg = document.getElementById("codebg");
545 /* First, find the center of the red box */
546 const r1 = bg.getBoundingClientRect();
547 const c1 = r1.left + (r1.width /
2);
549 /* Now the center of the code text */
550 const r2 = ct.getBoundingClientRect();
551 const c2 = r2.left + (r2.width /
2);
553 /* What do we add to c2 to make it equal to c1? */
554 const hdelta = c1 - c2;
556 /* We've measured everything so far in "client rect"
557 * coordinates, because that's the only available measurement
558 * we have for the width of the
<text> element after futzing
559 * with its contents. But when we reposition that
<text>
560 * element, it will be by adjusting its "x" attribute, and
561 * that attribute uses a different coordinate system than the
562 * client rect does. Specifically, "x" refers to an offset
563 * within the SVG's coordinate system, and the client rect
564 * coordinates are pixels on-screen. To convert between the
565 * two, we can take the "width" attribute of the background
566 * element and compare it to the width of the background
567 * element's client rect. Since the size of the background is
568 * fixed, this should give us a multiplier that turns client recr
569 * distances (what we have) into SVG distances (what we want) */
570 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
572 /* Convert hdelta from client rect to SVG coordinates */
573 const svg_hdelta = hdelta * client_to_svg;
575 /* Since this
<text> element has an "x" attribute it's easier for
576 * us to shift that than it is to mess with the "left" style. */
577 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
580 /*****************************************/
581 /* Next, set up the ticket date and time */
582 /*****************************************/
584 function set_ticket_expiry() {
585 /* There are two parameters, time and date, that we store in one
586 * underlying "date" variable. Default both to an hour and a
587 * half from now. This is what the CharmPass app does for
588 * one-way tickets. */
589 const date = new Date();
591 /* BaltimoreLink and MARC Train are valid for an hour and a half */
593 const params = new URLSearchParams(document.location.search);
594 if (params.get("servicename") == "Commuter Bus") {
595 /* But commuter bus tickets are only valid for ten minutes */
599 /* We use the low-level get/setTime to change the number of
600 * milliseconds since the epoch that this date represents
601 * Obviously correct, and avoids all suspicious corner cases
602 * for a few more decades. */
603 date.setTime(date.getTime() + (minutes*
60*
1000));
605 tt = document.getElementById("tickettime");
606 tt.textContent = date.toLocaleTimeString();
608 const td = document.getElementById("ticketdate");
614 td.textContent = date.toLocaleDateString("en-US", dateopts);
618 /*********************************************************/
619 /* Finally, the onclick handler for the night/day switch */
620 /*********************************************************/
622 /* We always start in "day" mode */
626 sky.style.fill = "#efb02f";
629 function set_night() {
630 sky.style.fill = "#
143b66";
633 function swap_colors() {
645 /*******************************************************/
646 /* Compute the MARC "zone" from its origin/destination */
647 /*******************************************************/
649 /* Sorted on the first component, then the second */
663 /* Compute the zone (string) for the given origin/destination pair.
664 * If we don't know it or if you chose in invalid pair (destination
665 * not on the same line as your origin?) then the empty string is
667 function compute_marc_zone(src, dest) {
668 /* Forward direction key for zone_map */
669 const fwd = src + "_" + dest;
671 /* Reverse direction key for zone_map. The zone_map only
672 * has them listed in one direction, so we check both
673 * directions here. */
674 const rev = dest + "_" + src;
676 /* The default. Obviously wrong for when we don't
677 * have the necessary data. */
681 zone = zone_map[fwd];
683 else if (zone_map[rev]) {
684 zone = zone_map[rev];
687 /* Convert the number to a string */
702 function set_marc_zone() {
703 const params = new URLSearchParams(document.location.search);
704 if (params.get("origin") && params.get("destination")) {
705 const src = params.get("origin");
706 const dest = params.get("destination");
707 const zone = compute_marc_zone(src, dest);
709 set_service_zone(null, zone);
714 /*****************************************************/
715 /* Set the origin and destination for the MARC Train */
716 /*****************************************************/
718 function set_marc_origin_destination() {
719 const params = new URLSearchParams(document.location.search);
720 if (!params.get("origin") || !params.get("destination")) {
724 const src = params.get("origin");
725 const dest = params.get("destination");
727 /* origindest contains both the origin and destination */
728 const origindest = document.getElementById("origindest");
730 const origin = document.getElementById("origin");
731 const destination = document.getElementById("destination");
733 origin.textContent = params.get("origin");
734 destination.textContent = params.get("destination");
736 origindest.style.display = "block"; /* It's hidden by default */
739 /******************************************/
740 /* Display the ticket (and hide the menu) */
741 /******************************************/
744 /* To create our "window" onto the scene, we're going to slide the
745 * SVG off the left-hand side of the screen, and we don't want
746 * scroll bars to appear. */
747 document.body.style.overflow = "hidden";
748 document.body.style.margin = "
0";
749 document.body.style.padding = "
0";
751 const svg = document.querySelector("svg");
752 const menu = document.getElementById("menu");
753 svg.style.display = "initial";
754 menu.style.display = "none";
757 /*****************************************************/
758 /* Add event handlers for all of the functions above */
759 /*****************************************************/
761 const params = new URLSearchParams(document.location.search);
762 if (params.get("go")) {
763 /* First unhide the SVG (swap it with the form) */
764 window.addEventListener("load", go);
766 /* Center the ticket once when the page has loaded */
767 window.addEventListener("load", center_ticket);
769 /* Re-center the ticket when the window is resized */
770 window.addEventListener("resize", center_ticket);
772 /* Set the service identifier when the page has loaded */
773 window.addEventListener("load", set_service_id);
775 /* Set the service name when the page has loaded */
776 window.addEventListener("load", set_service_name);
778 /* Set the service zone when the page has loaded */
779 window.addEventListener("load", set_service_zone);
781 /* Resize the ticket background if necessary */
782 window.addEventListener("load", resize_ticket);
784 /* Set the security code text when the page has loaded */
785 window.addEventListener("load", set_code);
787 /* Center the security code text when the page has loaded; in
788 * particular, after we set the code. */
789 window.addEventListener("load", center_code);
791 /* Set the ticket expiration date/time upon page load */
792 window.addEventListener("load", set_ticket_expiry);
794 /* Set the MARC Train origin and destination, if applicable */
795 window.addEventListener("load", set_marc_origin_destination);
797 /* Set the MARC Train zone, if applicable */
798 window.addEventListener("load", set_marc_zone);
800 /* Swap colors when the screen is tapped */
801 document.body.addEventListener("click", swap_colors);