4 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
7 CharmBypass: doing transit equity whether they like it or not
17 /* Set the height to
100% of the screen, which we'll keep; and the
18 * initial position to (
0,
0), which we're going to change
19 * every time the window is resized, because the exact amount
20 * that we have to slide the SVG to the left to get the ticket
21 * into the center will change. */
27 /* Hide everything by default. We only show it once the user has
28 * submitted the menu form */
32 /* The blinking fade in/out animation for the ticket date and time */
45 #tickettime, #ticketdate {
46 /*
300 two-second blinks is ten minutes */
47 animation: blink
2s linear
300;
50 /* Define, load, and specify the custom font we use for the ticket
51 * date, time, and service name. */
53 font-family: "CharmBypass Regular";
55 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
58 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
59 font-family: "CharmBypass Regular", sans-serif;
63 font-family: "CharmBypass Bold";
65 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
69 font-family: "CharmBypass Bold", sans-serif;
72 /************************/
73 /* Scrolling animations */
74 /************************/
79 transform: translateX(
0%);
82 transform: translateX(-
100%);
87 animation: busroll
23s linear infinite;
94 transform: translateX(
0%);
97 transform: translateX(
100%);
102 animation: tramroll
17s linear infinite;
107 @keyframes trainroll {
109 transform: translateX(
0%);
112 transform: translateX(
100%);
117 animation: trainroll
11s linear infinite;
122 @keyframes cloudsfloat {
124 transform: translateX(
0%);
127 transform: translateX(-
50%);
132 animation: cloudsfloat
40s linear infinite;
135 @keyframes cloudscopyfloat {
137 transform: translateX(
0%);
140 transform: translateX(-
50%);
145 animation: cloudscopyfloat
40s linear infinite;
150 @keyframes treespass {
152 transform: translateX(
0%);
155 transform: translateX(-
50%);
160 /* The trees move a little faster than the clouds */
161 animation: treespass
30s linear infinite;
164 @keyframes treescopypass {
166 transform: translateX(
0%);
169 transform: translateX(-
50%);
174 /* The trees move a little faster than the clouds */
175 animation: treescopypass
30s linear infinite;
180 @keyframes cityscroll {
182 transform: translateX(
0%);
185 transform: translateX(-
50%);
190 /* The city moves faster than the clouds but slower
192 animation: cityscroll
35s linear infinite;
195 @keyframes citycopyscroll {
197 transform: translateX(
0%);
200 transform: translateX(-
50%);
205 /* The city moves faster than the clouds but slower
207 animation: citycopyscroll
35s linear infinite;
215 <h2>doing transit equity whether they like it or not
</h2>
218 <em>Hint:
</em> If you think the driver or fare inspector will
219 actually check it, the daily security code is the same on a
220 $
2.00 BaltimoreLink ticket as it is on a $
9.00 MARC Train
221 ticket. It's also the same on your friend's phone, or for
222 anyone else in Maryland that day.
227 <legend>BaltimoreLink (Bus, Light Rail, Metro)
</legend>
230 Daily security code (optional):
237 pattern=
"[a-zA-Z0-9]*" />
239 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
240 <input type=
"submit" name=
"go" value=
"Get Ticket" />
245 <legend>Commuter Bus
</legend>
246 <input type=
"hidden" name=
"serviceid" value=
"R" />
247 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
251 Daily security code (optional):
258 pattern=
"[a-zA-Z0-9]*" />
263 <input required
type=
"radio" id=
"zone1" name=
"zone" value=
"Zone 1" />
264 <label for=
"zone1">Zone
1</label>
267 <input required
type=
"radio" id=
"zone2" name=
"zone" value=
"Zone 2" />
268 <label for=
"zone2">Zone
2</label>
271 <input required
type=
"radio" id=
"zone3" name=
"zone" value=
"Zone 3" />
272 <label for=
"zone3">Zone
3</label>
275 <input required
type=
"radio" id=
"zone4" name=
"zone" value=
"Zone 4" />
276 <label for=
"zone4">Zone
4</label>
279 <input required
type=
"radio" id=
"zone5" name=
"zone" value=
"Zone 5" />
280 <label for=
"zone5">Zone
5</label>
283 <input type=
"submit" name=
"go" value=
"Get Ticket" />
288 <legend>MARC Train
</legend>
292 Daily security code (optional):
299 pattern=
"[a-zA-Z0-9]*" />
305 <input required
type=
"radio" id=
"origin1" name=
"origin" value=
"BAL" />
306 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
309 <input required
type=
"radio" id=
"origin2" name=
"origin" value=
"BCA" />
310 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
313 <input required
type=
"radio" id=
"origin3" name=
"origin" value=
"BWE" />
314 <label for=
"origin3">Bowie State (Penn Line)
</label>
317 <input required
type=
"radio" id=
"origin4" name=
"origin" value=
"BWI" />
318 <label for=
"origin4">BWI Airport (Penn Line)
</label>
321 <input required
type=
"radio" id=
"origin5" name=
"origin" value=
"CPK" />
322 <label for=
"origin5">College Park (Camden Line)
</label>
325 <input required
type=
"radio" id=
"origin6" name=
"origin" value=
"SEB" />
326 <label for=
"origin6">Seabrook (Penn Line)
</label>
329 <input required
type=
"radio" id=
"origin7" name=
"origin" value=
"WAS" />
330 <label for=
"origin7">Washington D.C.
</label>
333 <input required
type=
"radio" id=
"origin8" name=
"origin" value=
"WBL" />
334 <label for=
"origin8">West Baltimore (Penn Line)
</label>
339 <input required
type=
"radio" id=
"destination1" name=
"destination" value=
"BAL" />
340 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
343 <input required
type=
"radio" id=
"destination2" name=
"destination" value=
"BCA" />
344 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
347 <input required
type=
"radio" id=
"destination3" name=
"destination" value=
"BWE" />
348 <label for=
"destination3">Bowie State (Penn Line)
</label>
351 <input required
type=
"radio" id=
"destination4" name=
"destination" value=
"BWI" />
352 <label for=
"destination4">BWI Airport (Penn Line)
</label>
355 <input required
type=
"radio" id=
"destination5" name=
"destination" value=
"CPK" />
356 <label for=
"destination5">College Park (Camden Line)
</label>
359 <input required
type=
"radio" id=
"destination6" name=
"destination" value=
"SEB" />
360 <label for=
"destination6">Seabrook (Penn Line)
</label>
363 <input required
type=
"radio" id=
"destination7" name=
"destination" value=
"WAS" />
364 <label for=
"destination7">Washington D.C.
</label>
367 <input required
type=
"radio" id=
"destination8" name=
"destination" value=
"WBL" />
368 <label for=
"destination8">West Baltimore (Penn Line)
</label>
371 <input type=
"hidden" name=
"serviceid" value=
"R" />
372 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
373 <input type=
"submit" name=
"go" value=
"Get Ticket" />
382 /***********************************************/
383 /* First, center the ticket within the browser */
384 /***********************************************/
386 function center_ticket() {
387 /* We're relying on the SVG being the full height of the
388 * viewport already, and on the aspect ratio being
389 * preserved. First, find the center of the ticket. */
390 const r = document.getElementById("ticket").getBoundingClientRect();
391 const c = r.left + (r.width /
2);
393 /* That's the center-line of the ticket. We want to move it to
394 * the center-line of the viewport. */
395 const vc = document.documentElement.clientWidth /
2;
397 /* This is how much we need to translate the SVG */
398 const hdelta = vc - c;
400 /* But before we can set the absolute left-coordinate of the
401 * SVG, we need to know where it is now. Note: without the
402 * "px" this doesn't default to pixels like CSS does. */
403 const svg = document.querySelector("svg");
404 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
408 /******************************/
409 /* Set the service identifier */
410 /******************************/
411 function set_service_id() {
412 const sid = document.getElementById("serviceid");
414 /* Get the "serviceid" from the querystring if it's there */
415 const params = new URLSearchParams(document.location.search);
416 if (params.get("serviceid")) {
417 sid.textContent = params.get("serviceid");
420 /* Otherwise, leave it at "F" */
423 /************************/
424 /* Set the service name */
425 /************************/
426 function set_service_name() {
427 const sid = document.getElementById("servicename");
429 /* Get the "servicename" from the querystring if it's there */
430 const params = new URLSearchParams(document.location.search);
431 if (params.get("servicename")) {
432 sid.textContent = params.get("servicename");
435 /* Otherwise, leave it at "BaltimoreLink" */
439 /************************/
440 /* Set the service zone */
441 /************************/
442 function set_service_zone(event, zone) {
443 /* We can take the zone as a parameter too; this allows us to
444 * use this function for the (computed) MARC Train zone and
445 * not just the querystring Commuter Bus zone. The extra
446 * "event" parameter is there for the event listener, which
447 * would otherwise stuff an onload event into the zone
448 * parameter. "Thankfully" javascript lets us call a
449 * two-argument function with one argument and thereby abuse
450 * the event handler for this. */
451 const z = document.getElementById("zone");
452 const params = new URLSearchParams(document.location.search);
455 z.textContent = zone;
456 z.style.display = "block"; /* It's hidden by default */
458 else if (params.get("zone")) {
459 /* Get the "zone" from the querystring if it's there */
460 z.textContent = params.get("zone");
461 z.style.display = "block"; /* It's hidden by default */
464 /* Otherwise, leave it blank (and hidden) */
467 /***********************************************************/
468 /* Resize the ticket background based on the service name */
469 /***********************************************************/
471 function resize_ticket() {
472 /* Get the "servicename" from the querystring if it's there */
473 const params = new URLSearchParams(document.location.search);
474 const tbg = document.getElementById("ticketbg");
475 const t = document.getElementById("ticket");
476 const sn = document.getElementById("servicename");
478 if (params.get("servicename") == "Commuter Bus") {
479 /* The top of the background is initially at y=
246.859, and
480 * we scale it by a factor of
1.12 to y=
276.482 for a change
481 * of
29.623. So after we scale it, we translate it upwards
482 * by that amount to put it back where it started. */
483 tbg.setAttribute("transform", "translate(
0 -
29.623) scale(
1 1.12)");
485 /* Now translate the entire ticket up by the magic amount,
1/
5
486 * of the size change we made to the background. This ratio
487 * was found by measuring pixels in side-by-side screenshots
488 * of BaltimoreLink and Commuter Bus tickets. */
489 t.setAttribute("transform", "translate(
0 -
9.33)");
491 /* More magic numbers discovered by comparing the two
492 * tickets overlayed in inkscape */
493 sn.setAttribute("transform", "translate(
0 64.28)");
495 else if (params.get("servicename") == "MARC Train") {
496 /* insane tricks are explained above */
497 tbg.setAttribute("transform",
498 "translate(
0 -
72.378) scale(
1 1.2932)");
499 t.setAttribute("transform", "translate(
0 -
67.17)");
500 sn.setAttribute("transform", "translate(
0 131.0)");
503 /* Otherwise, leave it alone. The SVG was designed with the
504 * BaltimoreLink ticket in mind */
507 /****************************************/
508 /* Set and reposition the security code */
509 /****************************************/
511 function set_code() {
512 const ct = document.getElementById("codetext");
514 /* Get the "code" from the querystring if it's there */
515 const params = new URLSearchParams(document.location.search);
516 if (params.get("code")) {
517 ct.textContent = params.get("code").toUpperCase();
520 /* Otherwise, use a random code */
521 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
522 "A","B","C","D","E","F","G","H","I","J",
523 "K","L","M","N","O","P","Q","R","S","T",
524 "U","V","W","X","Y","Z"];
526 /* Two random ints between
0 and
35 */
527 const i1 = Math.floor(Math.random() *
36);
528 const i2 = Math.floor(Math.random() *
36);
529 const d1 = bucket[i1];
530 const d2 = bucket[i2];
531 ct.textContent = d1 + d2;
536 function center_code() {
537 /* Center the security code inside its red box */
538 const ct = document.getElementById("codetext");
539 const bg = document.getElementById("codebg");
541 /* First, find the center of the red box */
542 const r1 = bg.getBoundingClientRect();
543 const c1 = r1.left + (r1.width /
2);
545 /* Now the center of the code text */
546 const r2 = ct.getBoundingClientRect();
547 const c2 = r2.left + (r2.width /
2);
549 /* What do we add to c2 to make it equal to c1? */
550 const hdelta = c1 - c2;
552 /* We've measured everything so far in "client rect"
553 * coordinates, because that's the only available measurement
554 * we have for the width of the
<text> element after futzing
555 * with its contents. But when we reposition that
<text>
556 * element, it will be by adjusting its "x" attribute, and
557 * that attribute uses a different coordinate system than the
558 * client rect does. Specifically, "x" refers to an offset
559 * within the SVG's coordinate system, and the client rect
560 * coordinates are pixels on-screen. To convert between the
561 * two, we can take the "width" attribute of the background
562 * element and compare it to the width of the background
563 * element's client rect. Since the size of the background is
564 * fixed, this should give us a multiplier that turns client recr
565 * distances (what we have) into SVG distances (what we want) */
566 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
568 /* Convert hdelta from client rect to SVG coordinates */
569 const svg_hdelta = hdelta * client_to_svg;
571 /* Since this
<text> element has an "x" attribute it's easier for
572 * us to shift that than it is to mess with the "left" style. */
573 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
576 /*****************************************/
577 /* Next, set up the ticket date and time */
578 /*****************************************/
580 function set_ticket_expiry() {
581 /* There are two parameters, time and date, that we store in one
582 * underlying "date" variable. Default both to an hour and a
583 * half from now. This is what the CharmPass app does for
584 * one-way tickets. */
585 const date = new Date();
587 /* BaltimoreLink and MARC Train are valid for an hour and a half */
589 const params = new URLSearchParams(document.location.search);
590 if (params.get("servicename") == "Commuter Bus") {
591 /* But commuter bus tickets are only valid for ten minutes */
595 /* We use the low-level get/setTime to change the number of
596 * milliseconds since the epoch that this date represents
597 * Obviously correct, and avoids all suspicious corner cases
598 * for a few more decades. */
599 date.setTime(date.getTime() + (minutes*
60*
1000));
601 tt = document.getElementById("tickettime");
602 tt.textContent = date.toLocaleTimeString();
604 const td = document.getElementById("ticketdate");
610 td.textContent = date.toLocaleDateString("en-US", dateopts);
614 /*********************************************************/
615 /* Finally, the onclick handler for the night/day switch */
616 /*********************************************************/
618 /* We always start in "day" mode */
622 sky.style.fill = "#efb02f";
625 function set_night() {
626 sky.style.fill = "#
143b66";
629 function swap_colors() {
641 /*******************************************************/
642 /* Compute the MARC "zone" from its origin/destination */
643 /*******************************************************/
645 /* Sorted on the first component, then the second */
659 /* Compute the zone (string) for the given origin/destination pair.
660 * If we don't know it or if you chose in invalid pair (destination
661 * not on the same line as your origin?) then the empty string is
663 function compute_marc_zone(src, dest) {
664 /* Forward direction key for zone_map */
665 const fwd = src + "_" + dest;
667 /* Reverse direction key for zone_map. The zone_map only
668 * has them listed in one direction, so we check both
669 * directions here. */
670 const rev = dest + "_" + src;
672 /* The default. Obviously wrong for when we don't
673 * have the necessary data. */
677 zone = zone_map[fwd];
679 else if (zone_map[rev]) {
680 zone = zone_map[rev];
683 /* Convert the number to a string */
698 function set_marc_zone() {
699 const params = new URLSearchParams(document.location.search);
700 if (params.get("origin") && params.get("destination")) {
701 const src = params.get("origin");
702 const dest = params.get("destination");
703 const zone = compute_marc_zone(src, dest);
705 set_service_zone(null, zone);
710 /*****************************************************/
711 /* Set the origin and destination for the MARC Train */
712 /*****************************************************/
714 function set_marc_origin_destination() {
715 const params = new URLSearchParams(document.location.search);
716 if (!params.get("origin") || !params.get("destination")) {
720 const src = params.get("origin");
721 const dest = params.get("destination");
723 /* origindest contains both the origin and destination */
724 const origindest = document.getElementById("origindest");
726 const origin = document.getElementById("origin");
727 const destination = document.getElementById("destination");
729 origin.textContent = params.get("origin");
730 destination.textContent = params.get("destination");
732 origindest.style.display = "block"; /* It's hidden by default */
735 /******************************************/
736 /* Display the ticket (and hide the menu) */
737 /******************************************/
740 /* To create our "window" onto the scene, we're going to slide the
741 * SVG off the left-hand side of the screen, and we don't want
742 * scroll bars to appear. */
743 document.body.style.overflow = "hidden";
744 document.body.style.margin = "
0";
745 document.body.style.padding = "
0";
747 const svg = document.querySelector("svg");
748 const menu = document.getElementById("menu");
749 svg.style.display = "initial";
750 menu.style.display = "none";
753 /*****************************************************/
754 /* Add event handlers for all of the functions above */
755 /*****************************************************/
757 const params = new URLSearchParams(document.location.search);
758 if (params.get("go")) {
759 /* First unhide the SVG (swap it with the form) */
760 window.addEventListener("load", go);
762 /* Center the ticket once when the page has loaded */
763 window.addEventListener("load", center_ticket);
765 /* Re-center the ticket when the window is resized */
766 window.addEventListener("resize", center_ticket);
768 /* Set the service identifier when the page has loaded */
769 window.addEventListener("load", set_service_id);
771 /* Set the service name when the page has loaded */
772 window.addEventListener("load", set_service_name);
774 /* Set the service zone when the page has loaded */
775 window.addEventListener("load", set_service_zone);
777 /* Resize the ticket background if necessary */
778 window.addEventListener("load", resize_ticket);
780 /* Set the security code text when the page has loaded */
781 window.addEventListener("load", set_code);
783 /* Center the security code text when the page has loaded; in
784 * particular, after we set the code. */
785 window.addEventListener("load", center_code);
787 /* Set the ticket expiration date/time upon page load */
788 window.addEventListener("load", set_ticket_expiry);
790 /* Set the MARC Train origin and destination, if applicable */
791 window.addEventListener("load", set_marc_origin_destination);
793 /* Set the MARC Train zone, if applicable */
794 window.addEventListener("load", set_marc_zone);
796 /* Swap colors when the screen is tapped */
797 document.body.addEventListener("click", swap_colors);