admin管理员组文章数量:1433530
Let's say I have an html table (50 x 50 cells) with a yellow background. I would like to use the background colors of the cells to print letters (A-Z) (e.g. some cells blue and most cells yellow) in an animated loop, using jQuery. I can create a table and a pointer which can loop through all the cells of the table such that it can change the background color of a particular cell (x,y) to different color. However, I don't understand which cells to highlight to form a particular letter. For example, to display the letter "A" on the 50 x 50 grid, which cells do I need to change to a new background color such that I get the letter A displayed on the screen with the cells, and so on for all the other letters. Is there any pattern for this?
Let's say I have an html table (50 x 50 cells) with a yellow background. I would like to use the background colors of the cells to print letters (A-Z) (e.g. some cells blue and most cells yellow) in an animated loop, using jQuery. I can create a table and a pointer which can loop through all the cells of the table such that it can change the background color of a particular cell (x,y) to different color. However, I don't understand which cells to highlight to form a particular letter. For example, to display the letter "A" on the 50 x 50 grid, which cells do I need to change to a new background color such that I get the letter A displayed on the screen with the cells, and so on for all the other letters. Is there any pattern for this?
Share Improve this question edited Jan 11, 2018 at 17:58 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Mar 29, 2012 at 9:47 cam lovercam lover 571 silver badge7 bronze badges 7- I can't quit grasp what you're trying to achieve. – Yoshi Commented Mar 29, 2012 at 9:54
- Am i correct in the assumption that you are trying to implement some obscure CAPTCHA or something? – Kaii Commented Mar 29, 2012 at 9:54
- Not really. I just want to create an animation such that, it would display a persons' name in a loop. For example "Kai" would display K first followed by A, then I – cam lover Commented Mar 29, 2012 at 9:57
- 2 There's no shortcut to happiness here. Take your favorite graphics editor, create a new image sized 50x50 pixels, insert a character and see which pixels it occupies. – JJJ Commented Mar 29, 2012 at 9:59
- Or if you're not married to tables you could draw a character to a 50x50 canvas and scale it up. – JJJ Commented Mar 29, 2012 at 10:00
2 Answers
Reset to default 6Create the cells with a loop such as:
for(var i=65;i<=90;i++) {
console.log(String.fromCharCode(i));
}
(65 is the char code for A
, 90 for Z
).
in the loop, attach id with the char. something like "charA", "charB".
Than you can access the fields searching the id <"char" + letter>.
if you know only the (x,y) in the 50x50 grid, calculate which letter it is with:
String.fromCharCode(65+y*50+x);
Or take the value of it from the elment itself
$(this).val();
Or from attribute you attach to it:
$(this).attr('letter')
Use Canvas (Edit: only for the generation of the letter coordinates in the 50x50 grid, no usage of canvas afterwards).
For each letter possible, print the char on a 50x50 html5/javascript canvas in black and white using something like: http://typeface.neocracy/examples.html
Then access the canvas in each pixel to check if it black or white, and save it in multidimensional javascript arrays. getPixel from HTML Canvas?
print the output and create javascript code or JSON object that saves those coordinates for your use.
After that you'll have all you need: the coordinates for each letter, and (bonus) with a font of your choice.
本文标签: javascriptHow can I display letters using html table cells as colored pixelsStack Overflow
版权声明:本文标题:javascript - How can I display letters using html table cells as colored pixels? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745610681a2666094.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论