Skip to content

Instantly share code, notes, and snippets.

@Johann150
Last active December 29, 2023 06:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Johann150/fe92ff6463c98b5a21dfc12affffb0e8 to your computer and use it in GitHub Desktop.
Save Johann150/fe92ff6463c98b5a21dfc12affffb0e8 to your computer and use it in GitHub Desktop.
<html>
<head>
<style>
#out{
display:flex;
flex-flow: row no-wrap;
justify-content:center;
margin-bottom: 40px;
}
#out>samp{
font-family: 'Segoe UI Symbol',monospace;
font-size: 40px;
line-height: 30px;
}
#out>samp>p{
margin:0;
}
.toggle{
display:none;
}
#fold{
display:none;
padding:5px;
padding-left:20px;
background-color:#f8f888;
margin-bottom:10px;
}
#fold *{
vertical-align: top;
}
#fold input,#fold label{
float:right;
}
.toggle ~ label{
/*poisiton:absolute;*/
float:left;
cursor:zoom-in;
}
.toggle ~ label:before{
content:'\25B6';
width:20px;
display:inline-block;
}
.toggle:checked ~ #fold{
display:block;
}
.toggle:checked ~ label{
cursor:zoom-out;
}
.toggle:checked ~ label:before{
content: '\25BC';
}
</style>
</head>
<body>
<input type="checkbox" checked="true" class="toggle" id="t"/>
<label for="t"></label>
<table id="fold">
<tr><td>
<textarea id="in" cols="120" rows="5">
All hu-man be-ings are born free and e-qual in dig-ni-ty and rights.
They are en-dowed with rea-son and con-science and should act to-wards one an-oth-er in a spir-it of broth-er-hood.
</textarea><br>
<input type="button" onclick="draw()" value="draw!"/>
<label for="round">rounded</label><input type="checkbox" checked="true" id="round"/>
</td><td>
NOTES:
<ul>
<li>Use line breaks to separate columns.</li>
<li>Use spaces to separate words.</li>
<li>Use dashes to separate syllables.</li>
<li>This version additionally supports a non-standard comma and full stop.</li>
</ul>
<a href="https://gist.github.com/Johann150/fe92ff6463c98b5a21dfc12affffb0e8">this file as a gist</a>
<a href="https://www.reddit.com/r/neography/comments/a9yd0d/i_made_a_griddy_cipher_where_letters_smush/">from this reddit post</a>
<p xmlns:dct="http://purl.org/dc/terms/" xmlns:cc="http://creativecommons.org/ns#" class="license-text">This work is licensed under <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0</a>. &#x1F16D;&#x1f6ca;&#x2b75;</p>
</td></tr>
</table>
<div id="out"></div><!-- will be filled by Javascript-->
<script>
var alpha={
/*
1: -
2: |
3: +
*/
"a":[2,1,1],
"b":[1,2,3],
"c":[2,3,2],
"d":[1,3,1],
"e":[1,1,1],
"f":[3,2,1],
"g":[1,3,3],
"h":[2,2,1],
"i":[1,1,2],
"j":[2,3,3],
"k":[3,1,3],
"l":[1,1,3],
"m":[2,2,3],
"n":[1,2,2],
"o":[1,2,1],
"p":[3,1,2],
"q":[3,3,1],
"r":[3,1,1],
"s":[2,1,2],
"t":[2,2,2],
"u":[3,2,2],
"v":[2,3,1],
"w":[1,3,2],
"x":[3,2,3],
"y":[2,1,3],
"z":[3,3,2],
",":[2,3,3],
".":[3,3,3]
};
function draw(){
text=document.getElementById('in').value.toLowerCase().split("");
/*
in order to work, 1 unit is grid/2
the grid is planned out in a bitmap-like form
cell data:
1 bit:right
2 bit:down
4 bit:left
8 bit:up
=> cells are divided in quarters again
*/
var table=[[]];
var group=0,x=1,y=1;
text.forEach((l)=>{
if(l=='\n'){
table[++group]=[];
x=1;
y=1;
}else if(l=='-'){
x=1;
table[group][y]=[16];
y++;
}else if(l==' '){
x=1;
y++;
}else if(alpha.hasOwnProperty(l)){
var symbols=alpha[l];
while(table[group].length<=y){
// make sure that all required rows exist (not "undefined")
table[group].push([]);
}
if(l=='.'||l==','){
table[group][y]=[16];
y++;
// make up for incrementing y
table[group].push([]);
x=0;
}
for(var i=0;i<3;i++){
// always add one more box to the right
while(table[group][y].length<=x+1){
table[group][y].push(0);
}
// symbol data can conveniently be converted to cell data by mulitplying with five!
table[group][y][x]=symbols[i]*5;
x+=2;
}
y++;
x-=5;
}
});
for(group=0;group<table.length;group++){
for(y=0;y<table[group].length;y++){
for(x=0;x<table[group][y].length;x++){
/*
this cell is part of the original code
and can therefore not be modified
*/
if(table[group][y][x]!=0) continue;
if(x>0&&(table[group][y][x-1]&1)){
// there is a cell on the left with a right line
table[group][y][x]|=4;// set left line
}
if(x+1<table[group][y].length&&(table[group][y][x+1]&4)){
// there is a cell on the right with a left line
table[group][y][x]|=1;// set right line
}
if(y>0&&x<table[group][y-1].length&&(table[group][y-1][x]&2)){
// there is a cell above with a down line
table[group][y][x]|=8;// set up line
}
if(y+1<table[group].length&&x<table[group][y+1].length&&(table[group][y+1][x]&8)){
// there is a cell above with a up line
table[group][y][x]|=2;// set down line
}
}
}
}
var round=document.getElementById('round').checked;
var txt="";
for(group=0;group<table.length;group++){
txt+="<samp><p>";
for(y=0;y<table[group].length;y++){
for(x=0;x<table[group][y].length;x++){
var c;
switch(table[group][y][x]){
case 0:c="&#8194;";break;// En-Space
case 1:c="&#9590;";break;
case 2:c="&#9591;";break;
case 3:c=(round?"&#9581;":"&#9484;");break;
case 4:c="&#9588;";break;
case 5:c="&#9472;";break;
case 6:c=(round?"&#9582;":"&#9488;");break;
case 7:c="&#9516;";break;
case 8:c="&#9589;";break;
case 9:c=(round?"&#9584;":"&#9492;");break;
case 10:c="&#9474;";break;
case 11:c="&#9500;";break;
case 12:c=(round?"&#9583;":"&#9496;");break;
case 13:c="&#9524;";break;
case 14:c="&#9508;";break;
case 15:c="&#9532;";break;
case 16:c="</p><p>";break;
}
txt+=c;
}
txt+="<br>";
}
txt+="</p></samp>";
}
document.getElementById('out').innerHTML=txt.replace(/<p><br>/g,"<p>");
}
draw();// default text
</script>
</body>
</html>
@shaos
Copy link

shaos commented Dec 27, 2023

Hi, Johann

"j":[3,3,3],

I think here for J it has to be 2,3,3 (pipe, plus, plus)

@Johann150
Copy link
Author

Yup, have fixed it @shaos

@shaos
Copy link

shaos commented Dec 28, 2023

Great! But here it's still +++:
https://qwertqwefsday.eu/griddy.html

@shaos
Copy link

shaos commented Dec 29, 2023

It's fixed now - thanks! :)

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