4 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
5 <link rel=
"icon" href=
"favicon.svg" />
8 CharmBypass: doing transit equity whether they like it or not
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>doing transit equity whether they like it or not
</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):
238 pattern=
"[a-zA-Z0-9]*" />
240 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
241 <input type=
"submit" name=
"go" value=
"Get Ticket" />
246 <legend>Commuter Bus
</legend>
247 <input type=
"hidden" name=
"serviceid" value=
"R" />
248 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
252 Daily security code (optional):
259 pattern=
"[a-zA-Z0-9]*" />
264 <input required
type=
"radio" id=
"zone1" name=
"zone" value=
"Zone 1" />
265 <label for=
"zone1">Zone
1</label>
268 <input required
type=
"radio" id=
"zone2" name=
"zone" value=
"Zone 2" />
269 <label for=
"zone2">Zone
2</label>
272 <input required
type=
"radio" id=
"zone3" name=
"zone" value=
"Zone 3" />
273 <label for=
"zone3">Zone
3</label>
276 <input required
type=
"radio" id=
"zone4" name=
"zone" value=
"Zone 4" />
277 <label for=
"zone4">Zone
4</label>
280 <input required
type=
"radio" id=
"zone5" name=
"zone" value=
"Zone 5" />
281 <label for=
"zone5">Zone
5</label>
284 <input type=
"submit" name=
"go" value=
"Get Ticket" />
289 <legend>MARC Train
</legend>
293 Daily security code (optional):
300 pattern=
"[a-zA-Z0-9]*" />
306 <input required
type=
"radio" id=
"origin1" name=
"origin" value=
"BAL" />
307 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
310 <input required
type=
"radio" id=
"origin2" name=
"origin" value=
"BCA" />
311 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
314 <input required
type=
"radio" id=
"origin3" name=
"origin" value=
"BWE" />
315 <label for=
"origin3">Bowie State (Penn Line)
</label>
318 <input required
type=
"radio" id=
"origin4" name=
"origin" value=
"BWI" />
319 <label for=
"origin4">BWI Airport (Penn Line)
</label>
322 <input required
type=
"radio" id=
"origin5" name=
"origin" value=
"CPK" />
323 <label for=
"origin5">College Park (Camden Line)
</label>
326 <input required
type=
"radio" id=
"origin6" name=
"origin" value=
"SEB" />
327 <label for=
"origin6">Seabrook (Penn Line)
</label>
330 <input required
type=
"radio" id=
"origin7" name=
"origin" value=
"WAS" />
331 <label for=
"origin7">Washington D.C.
</label>
334 <input required
type=
"radio" id=
"origin8" name=
"origin" value=
"WBL" />
335 <label for=
"origin8">West Baltimore (Penn Line)
</label>
340 <input required
type=
"radio" id=
"destination1" name=
"destination" value=
"BAL" />
341 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
344 <input required
type=
"radio" id=
"destination2" name=
"destination" value=
"BCA" />
345 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
348 <input required
type=
"radio" id=
"destination3" name=
"destination" value=
"BWE" />
349 <label for=
"destination3">Bowie State (Penn Line)
</label>
352 <input required
type=
"radio" id=
"destination4" name=
"destination" value=
"BWI" />
353 <label for=
"destination4">BWI Airport (Penn Line)
</label>
356 <input required
type=
"radio" id=
"destination5" name=
"destination" value=
"CPK" />
357 <label for=
"destination5">College Park (Camden Line)
</label>
360 <input required
type=
"radio" id=
"destination6" name=
"destination" value=
"SEB" />
361 <label for=
"destination6">Seabrook (Penn Line)
</label>
364 <input required
type=
"radio" id=
"destination7" name=
"destination" value=
"WAS" />
365 <label for=
"destination7">Washington D.C.
</label>
368 <input required
type=
"radio" id=
"destination8" name=
"destination" value=
"WBL" />
369 <label for=
"destination8">West Baltimore (Penn Line)
</label>
372 <input type=
"hidden" name=
"serviceid" value=
"R" />
373 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
374 <input type=
"submit" name=
"go" value=
"Get Ticket" />
383 /***********************************************/
384 /* First, center the ticket within the browser */
385 /***********************************************/
387 function center_ticket() {
388 /* We're relying on the SVG being the full height of the
389 * viewport already, and on the aspect ratio being
390 * preserved. First, find the center of the ticket. */
391 const r = document.getElementById("ticket").getBoundingClientRect();
392 const c = r.left + (r.width /
2);
394 /* That's the center-line of the ticket. We want to move it to
395 * the center-line of the viewport. */
396 const vc = document.documentElement.clientWidth /
2;
398 /* This is how much we need to translate the SVG */
399 const hdelta = vc - c;
401 /* But before we can set the absolute left-coordinate of the
402 * SVG, we need to know where it is now. Note: without the
403 * "px" this doesn't default to pixels like CSS does. */
404 const svg = document.querySelector("svg");
405 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
409 /******************************/
410 /* Set the service identifier */
411 /******************************/
412 function set_service_id() {
413 const sid = document.getElementById("serviceid");
415 /* Get the "serviceid" from the querystring if it's there */
416 const params = new URLSearchParams(document.location.search);
417 if (params.get("serviceid")) {
418 sid.textContent = params.get("serviceid");
421 /* Otherwise, leave it at "F" */
424 /************************/
425 /* Set the service name */
426 /************************/
427 function set_service_name() {
428 const sid = document.getElementById("servicename");
430 /* Get the "servicename" from the querystring if it's there */
431 const params = new URLSearchParams(document.location.search);
432 if (params.get("servicename")) {
433 sid.textContent = params.get("servicename");
436 /* Otherwise, leave it at "BaltimoreLink" */
440 /************************/
441 /* Set the service zone */
442 /************************/
443 function set_service_zone(event, zone) {
444 /* We can take the zone as a parameter too; this allows us to
445 * use this function for the (computed) MARC Train zone and
446 * not just the querystring Commuter Bus zone. The extra
447 * "event" parameter is there for the event listener, which
448 * would otherwise stuff an onload event into the zone
449 * parameter. "Thankfully" javascript lets us call a
450 * two-argument function with one argument and thereby abuse
451 * the event handler for this. */
452 const z = document.getElementById("zone");
453 const params = new URLSearchParams(document.location.search);
456 z.textContent = zone;
457 z.style.display = "block"; /* It's hidden by default */
459 else if (params.get("zone")) {
460 /* Get the "zone" from the querystring if it's there */
461 z.textContent = params.get("zone");
462 z.style.display = "block"; /* It's hidden by default */
465 /* Otherwise, leave it blank (and hidden) */
468 /***********************************************************/
469 /* Resize the ticket background based on the service name */
470 /***********************************************************/
472 function resize_ticket() {
473 /* Get the "servicename" from the querystring if it's there */
474 const params = new URLSearchParams(document.location.search);
475 const tbg = document.getElementById("ticketbg");
476 const t = document.getElementById("ticket");
477 const sn = document.getElementById("servicename");
479 if (params.get("servicename") == "Commuter Bus") {
480 /* The top of the background is initially at y=
246.859, and
481 * we scale it by a factor of
1.12 to y=
276.482 for a change
482 * of
29.623. So after we scale it, we translate it upwards
483 * by that amount to put it back where it started. */
484 tbg.setAttribute("transform", "translate(
0 -
29.623) scale(
1 1.12)");
486 /* Now translate the entire ticket up by the magic amount,
1/
5
487 * of the size change we made to the background. This ratio
488 * was found by measuring pixels in side-by-side screenshots
489 * of BaltimoreLink and Commuter Bus tickets. */
490 t.setAttribute("transform", "translate(
0 -
9.33)");
492 /* More magic numbers discovered by comparing the two
493 * tickets overlayed in inkscape */
494 sn.setAttribute("transform", "translate(
0 64.28)");
496 else if (params.get("servicename") == "MARC Train") {
497 /* insane tricks are explained above */
498 tbg.setAttribute("transform",
499 "translate(
0 -
72.378) scale(
1 1.2932)");
500 t.setAttribute("transform", "translate(
0 -
67.17)");
501 sn.setAttribute("transform", "translate(
0 131.0)");
504 /* Otherwise, leave it alone. The SVG was designed with the
505 * BaltimoreLink ticket in mind */
508 /****************************************/
509 /* Set and reposition the security code */
510 /****************************************/
512 function set_code() {
513 const ct = document.getElementById("codetext");
515 /* Get the "code" from the querystring if it's there */
516 const params = new URLSearchParams(document.location.search);
517 if (params.get("code")) {
518 ct.textContent = params.get("code").toUpperCase();
521 /* Otherwise, use a random code */
522 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
523 "A","B","C","D","E","F","G","H","I","J",
524 "K","L","M","N","O","P","Q","R","S","T",
525 "U","V","W","X","Y","Z"];
527 /* Two random ints between
0 and
35 */
528 const i1 = Math.floor(Math.random() *
36);
529 const i2 = Math.floor(Math.random() *
36);
530 const d1 = bucket[i1];
531 const d2 = bucket[i2];
532 ct.textContent = d1 + d2;
537 function center_code() {
538 /* Center the security code inside its red box */
539 const ct = document.getElementById("codetext");
540 const bg = document.getElementById("codebg");
542 /* First, find the center of the red box */
543 const r1 = bg.getBoundingClientRect();
544 const c1 = r1.left + (r1.width /
2);
546 /* Now the center of the code text */
547 const r2 = ct.getBoundingClientRect();
548 const c2 = r2.left + (r2.width /
2);
550 /* What do we add to c2 to make it equal to c1? */
551 const hdelta = c1 - c2;
553 /* We've measured everything so far in "client rect"
554 * coordinates, because that's the only available measurement
555 * we have for the width of the
<text> element after futzing
556 * with its contents. But when we reposition that
<text>
557 * element, it will be by adjusting its "x" attribute, and
558 * that attribute uses a different coordinate system than the
559 * client rect does. Specifically, "x" refers to an offset
560 * within the SVG's coordinate system, and the client rect
561 * coordinates are pixels on-screen. To convert between the
562 * two, we can take the "width" attribute of the background
563 * element and compare it to the width of the background
564 * element's client rect. Since the size of the background is
565 * fixed, this should give us a multiplier that turns client recr
566 * distances (what we have) into SVG distances (what we want) */
567 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
569 /* Convert hdelta from client rect to SVG coordinates */
570 const svg_hdelta = hdelta * client_to_svg;
572 /* Since this
<text> element has an "x" attribute it's easier for
573 * us to shift that than it is to mess with the "left" style. */
574 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
577 /*****************************************/
578 /* Next, set up the ticket date and time */
579 /*****************************************/
581 function set_ticket_expiry() {
582 /* There are two parameters, time and date, that we store in one
583 * underlying "date" variable. Default both to an hour and a
584 * half from now. This is what the CharmPass app does for
585 * one-way tickets. */
586 const date = new Date();
588 /* BaltimoreLink and MARC Train are valid for an hour and a half */
590 const params = new URLSearchParams(document.location.search);
591 if (params.get("servicename") == "Commuter Bus") {
592 /* But commuter bus tickets are only valid for ten minutes */
596 /* We use the low-level get/setTime to change the number of
597 * milliseconds since the epoch that this date represents
598 * Obviously correct, and avoids all suspicious corner cases
599 * for a few more decades. */
600 date.setTime(date.getTime() + (minutes*
60*
1000));
602 tt = document.getElementById("tickettime");
603 tt.textContent = date.toLocaleTimeString();
605 const td = document.getElementById("ticketdate");
611 td.textContent = date.toLocaleDateString("en-US", dateopts);
615 /*********************************************************/
616 /* Finally, the onclick handler for the night/day switch */
617 /*********************************************************/
619 /* We always start in "day" mode */
623 sky.style.fill = "#efb02f";
626 function set_night() {
627 sky.style.fill = "#
143b66";
630 function swap_colors() {
642 /*******************************************************/
643 /* Compute the MARC "zone" from its origin/destination */
644 /*******************************************************/
646 /* Sorted on the first component, then the second */
660 /* Compute the zone (string) for the given origin/destination pair.
661 * If we don't know it or if you chose in invalid pair (destination
662 * not on the same line as your origin?) then the empty string is
664 function compute_marc_zone(src, dest) {
665 /* Forward direction key for zone_map */
666 const fwd = src + "_" + dest;
668 /* Reverse direction key for zone_map. The zone_map only
669 * has them listed in one direction, so we check both
670 * directions here. */
671 const rev = dest + "_" + src;
673 /* The default. Obviously wrong for when we don't
674 * have the necessary data. */
678 zone = zone_map[fwd];
680 else if (zone_map[rev]) {
681 zone = zone_map[rev];
684 /* Convert the number to a string */
699 function set_marc_zone() {
700 const params = new URLSearchParams(document.location.search);
701 if (params.get("origin") && params.get("destination")) {
702 const src = params.get("origin");
703 const dest = params.get("destination");
704 const zone = compute_marc_zone(src, dest);
706 set_service_zone(null, zone);
711 /*****************************************************/
712 /* Set the origin and destination for the MARC Train */
713 /*****************************************************/
715 function set_marc_origin_destination() {
716 const params = new URLSearchParams(document.location.search);
717 if (!params.get("origin") || !params.get("destination")) {
721 const src = params.get("origin");
722 const dest = params.get("destination");
724 /* origindest contains both the origin and destination */
725 const origindest = document.getElementById("origindest");
727 const origin = document.getElementById("origin");
728 const destination = document.getElementById("destination");
730 origin.textContent = params.get("origin");
731 destination.textContent = params.get("destination");
733 origindest.style.display = "block"; /* It's hidden by default */
736 /******************************************/
737 /* Display the ticket (and hide the menu) */
738 /******************************************/
741 /* To create our "window" onto the scene, we're going to slide the
742 * SVG off the left-hand side of the screen, and we don't want
743 * scroll bars to appear. */
744 document.body.style.overflow = "hidden";
745 document.body.style.margin = "
0";
746 document.body.style.padding = "
0";
748 const svg = document.querySelector("svg");
749 const menu = document.getElementById("menu");
750 svg.style.display = "initial";
751 menu.style.display = "none";
754 /*****************************************************/
755 /* Add event handlers for all of the functions above */
756 /*****************************************************/
758 const params = new URLSearchParams(document.location.search);
759 if (params.get("go")) {
760 /* First unhide the SVG (swap it with the form) */
761 window.addEventListener("load", go);
763 /* Center the ticket once when the page has loaded */
764 window.addEventListener("load", center_ticket);
766 /* Re-center the ticket when the window is resized */
767 window.addEventListener("resize", center_ticket);
769 /* Set the service identifier when the page has loaded */
770 window.addEventListener("load", set_service_id);
772 /* Set the service name when the page has loaded */
773 window.addEventListener("load", set_service_name);
775 /* Set the service zone when the page has loaded */
776 window.addEventListener("load", set_service_zone);
778 /* Resize the ticket background if necessary */
779 window.addEventListener("load", resize_ticket);
781 /* Set the security code text when the page has loaded */
782 window.addEventListener("load", set_code);
784 /* Center the security code text when the page has loaded; in
785 * particular, after we set the code. */
786 window.addEventListener("load", center_code);
788 /* Set the ticket expiration date/time upon page load */
789 window.addEventListener("load", set_ticket_expiry);
791 /* Set the MARC Train origin and destination, if applicable */
792 window.addEventListener("load", set_marc_origin_destination);
794 /* Set the MARC Train zone, if applicable */
795 window.addEventListener("load", set_marc_zone);
797 /* Swap colors when the screen is tapped */
798 document.body.addEventListener("click", swap_colors);