• <i id='BjC33'><tr id='BjC33'><dt id='BjC33'><q id='BjC33'><span id='BjC33'><b id='BjC33'><form id='BjC33'><ins id='BjC33'></ins><ul id='BjC33'></ul><sub id='BjC33'></sub></form><legend id='BjC33'></legend><bdo id='BjC33'><pre id='BjC33'><center id='BjC33'></center></pre></bdo></b><th id='BjC33'></th></span></q></dt></tr></i><div id='BjC33'><tfoot id='BjC33'></tfoot><dl id='BjC33'><fieldset id='BjC33'></fieldset></dl></div>
    <legend id='BjC33'><style id='BjC33'><dir id='BjC33'><q id='BjC33'></q></dir></style></legend>

    <small id='BjC33'></small><noframes id='BjC33'>

  • <tfoot id='BjC33'></tfoot>

          <bdo id='BjC33'></bdo><ul id='BjC33'></ul>

        “桶装填"Javascript 或咖啡脚本中的算法

        quot;Bucket Fillquot; algorithm in Javascript or coffeescript(“桶装填Javascript 或咖啡脚本中的算法)

          <bdo id='efMZ4'></bdo><ul id='efMZ4'></ul>
          <tfoot id='efMZ4'></tfoot>
                <tbody id='efMZ4'></tbody>

              <legend id='efMZ4'><style id='efMZ4'><dir id='efMZ4'><q id='efMZ4'></q></dir></style></legend>

                  <i id='efMZ4'><tr id='efMZ4'><dt id='efMZ4'><q id='efMZ4'><span id='efMZ4'><b id='efMZ4'><form id='efMZ4'><ins id='efMZ4'></ins><ul id='efMZ4'></ul><sub id='efMZ4'></sub></form><legend id='efMZ4'></legend><bdo id='efMZ4'><pre id='efMZ4'><center id='efMZ4'></center></pre></bdo></b><th id='efMZ4'></th></span></q></dt></tr></i><div id='efMZ4'><tfoot id='efMZ4'></tfoot><dl id='efMZ4'><fieldset id='efMZ4'></fieldset></dl></div>

                  <small id='efMZ4'></small><noframes id='efMZ4'>

                  本文介绍了“桶装填"Javascript 或咖啡脚本中的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  i'm writing a little coffeescript/js app that allows user to design icons ( 16x16 pixels or 32X32 pixels ). The icon is actually a 2 dimensional array with color cells. A cell can have a color or be empty.

                  I want the user to be able to fill blank cells with a "bucket paint" tool.

                  It means that

                  • if the user clicks on a blank cell , all the cells that are blank next to the clicked cell with be filled with the choosen color , until it reaches a colored cell

                  • if the user clicks on a colored cell , all the cells that are next to the clicked cell and share the same color will be filled , but not the blank ones nor the colored ones ( with another color ).

                  The app already allows the user to fill cells one by one with a chosen color , or delete colored cells with a pen tool.

                  Any suggestions ?

                  (ps : i'm not using html canvas to draw )

                  解决方案

                  Since this is only 16x16 or 32x32 you can use a recursive solution:

                  Say your starting point is to change pixel x/y from color A to color B (A or B can be empty).

                  In pseudo code:

                  function floodfill(x,y,A,B) {
                    if ((x<0) || (x>15) || (y<0) || (y>15)) return;
                    if (get_color(x,y)!=A) return;
                    set_color(x,y,B);
                    floodfill(x-1,y-1,A,B);
                    floodfill(x-1,y,A,B);
                    floodfill(x-1,y+1,A,B);
                    floodfill(x,y-1,A,B);
                    floodfill(x,y+1,A,B);
                    floodfill(x+1,y-1,A,B);
                    floodfill(x+1,y,A,B);
                    floodfill(x+1,y+1,A,B);
                  }
                  

                  这篇关于“桶装填"Javascript 或咖啡脚本中的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  Rails 3.1 ajax:success handling(Rails 3.1 ajax:成功处理)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                    <tbody id='2ChHh'></tbody>
                  <tfoot id='2ChHh'></tfoot>
                  <i id='2ChHh'><tr id='2ChHh'><dt id='2ChHh'><q id='2ChHh'><span id='2ChHh'><b id='2ChHh'><form id='2ChHh'><ins id='2ChHh'></ins><ul id='2ChHh'></ul><sub id='2ChHh'></sub></form><legend id='2ChHh'></legend><bdo id='2ChHh'><pre id='2ChHh'><center id='2ChHh'></center></pre></bdo></b><th id='2ChHh'></th></span></q></dt></tr></i><div id='2ChHh'><tfoot id='2ChHh'></tfoot><dl id='2ChHh'><fieldset id='2ChHh'></fieldset></dl></div>
                    <bdo id='2ChHh'></bdo><ul id='2ChHh'></ul>

                      <small id='2ChHh'></small><noframes id='2ChHh'>

                    1. <legend id='2ChHh'><style id='2ChHh'><dir id='2ChHh'><q id='2ChHh'></q></dir></style></legend>