It's asked to write a script to generate a source data to feed a JavaScript renderer.
JS Renderer documentation
The JS renderer is this script:
function o(x){
r=x.split(' ');
(d=document).write('<style>i{position:absolute;width:10;height:10;background:#000}</style>');
for(i=0;i<r.length;++i){c=r[i].split(',');d.write('<i style=top:'+(e=eval)(c[0])+';left:'+e(c[1])+'></i>')
}
}
It takes as input a list of X/Y coordinates separated by spaces and commas and prints on DOM the points as 10×10 pixel squares.
For example, if you call the script with:
o('0,0 10,0 20,0 30,0 40,0 20,10 20,20 0,30 10,30 20,30 30,30 40,30 0,50 10,50 20,50 30,50 40,50');
It will print:
Notice that the values can be expressed as calculations, so it will accept:
o('10*2,50/5');
Your task
Write a script that, given as input a string of characters ([A-Z0-9 ]
; uppercase letters, numbers, spaces) prints on stdout
the coordinates to feed the JS renderer.
Rules
- The "line-height" of the characters should be of at least 50px
- Your script doesn't need to run the JS parser
- The expected output format is:
x,y x,y x,y x,y
- The shortest code wins
Bonus: if you could reduce the length of the JS renderer without changing the behavior would be great :)
x,y
but your code produces'top:'+eval(cp[0])+';left:'+eval(cp[1])
which is the opposite. Which one is right? \$\endgroup\$ – Tobia Feb 11 '14 at 23:33