Skip to content

Instantly share code, notes, and snippets.

@aemkei
Forked from 140bytes/LICENSE.txt
Created October 8, 2011 15:11
Show Gist options
  • Save aemkei/1272408 to your computer and use it in GitHub Desktop.
Save aemkei/1272408 to your computer and use it in GitHub Desktop.
Digital Segment Display - 140byt.es

Digital Segment Display - 140byt.es

Converts single digits into old-school ASCII string.

See my digital clock example.

Digit List

 _      _  _       _   _  _   _   _
| |  |  _| _| |_| |_  |_   | |_| |_|
|_|  | |_  _|   |  _| |_|  | |_|  _|

Sample Clock

         _  _     _  _  
| |_| .  _| _| . |_   | 
|   | . |_  _| .  _|  | 

For more information

See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.

To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.

140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.

function f(
a, // number to convert
b // placeholer: index in string to replace
){
return "\n_ |"[ // character map
b % 4 && // add line break for position 4 and 8
b % 2 + -~a // draw space, "|" or "_" based on position
] || "ცᕦဨဢᒦႂႊᅦႪႦ" // data is stored in unicode character
.charCodeAt(a) // convert character to integer
.toString(2) // convert to binary representaion
.replace( // parse binary data
/./g, f // analyse every char
)
}
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Digital Clock - 140bytes</title>
<style type="text/css">
body { font-weight: bold; color: lime; background: black; }
pre { display: inline-block; width: auto; }
</style>
<div id="time"></div>
<script>
var digits =
function f(a,b){return"\n_ |"[b%4&&b%2+-~a]||"ცᕦဨဢᒦႂႊᅦႪႦ".charCodeAt(a).toString(2).replace(/./g,f)}
function pad(number){
return (number < 10 ? "0" : "") + number;
}
setInterval(function(){
var display = "",
date = new Date(),
time = pad(date.getHours()) +
pad(date.getMinutes()) +
pad(date.getSeconds()),
i;
for(i in time){
display += "<pre>" + digits(time[i]) + "</pre>";
if (i==1 || i==3){
display += "<pre>\n.\n.</pre>"
}
}
document.getElementById( "time" ).innerHTML = display
}, 1000);
</script>
function f(a,b){return"\n_ |"[b%4&&b%2+-~a]||"ცᕦဨဢᒦႂႊᅦႪႦ".charCodeAt(a).toString(2).replace(/./g,f)}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "toDigital",
"description": "Converts digits into an old-school digital ASCII string.",
"keywords": [
"number",
"digital",
"ascii",
"string"
],
"contributors": [
{
"name" : "Martin Kleppe",
"url" : "https://github.com/aemkei"
},
{
"name" : "@tsaniel",
"url" : "https://github.com/tsaniel"
}
]
}
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Digits - 140bytes</title>
<style type="text/css"> pre { display: inline-block; width: auto;}</style>
<div id="output"></div>
<script>
var digits =
function f(a,b){return"\n_ |"[b%4&&b%2+-~a]||"ცᕦဨဢᒦႂႊᅦႪႦ".charCodeAt(a).toString(2).replace(/./g,f)}
for (var i=0; i<10; i++){
document.getElementById( "output" ).innerHTML += "<pre>" + digits(i) + "</pre>"
}
</script>
@tsaniel
Copy link

tsaniel commented Dec 4, 2011

@subzey: Seems you miss 2 and 3 ?

@subzey
Copy link

subzey commented Dec 4, 2011

Sorry. Some weird thing is happened with non-printable chars.

Thanks for your reply, @tsaniel! I suppose, my entry cannot be valid as even if it consists of 111 bytes, it cannot be tweeted without corruption.

@tsaniel
Copy link

tsaniel commented Dec 5, 2011

Anyway, good work @subzey!
By the way, could you use the similar trick on the early version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment