DEV Community

Cover image for Cartographer Magic: Power Automate Bitmaps Revealed
Bala Madhusoodhanan
Bala Madhusoodhanan

Posted on

Cartographer Magic: Power Automate Bitmaps Revealed

Intro:
How cool will it be to encode a user message as a bitmap? The concept involving a multiline string that transforms into a 2D image, creating a quirky bitmap. A world map where space characters act as empty spaces, and every other character becomes a canvas for your personalized message. The magic is using power automate.

Logic:

1) Determine the length of the input string:
In this step, the algorithm calculates the length of the input string, providing the necessary information for subsequent operations.

2) Create a variable that would be your bitmap template:
A template is established, presumably in the form of a string, that serves as the foundation for building the final bitmap. This template likely contains a placeholder character, such as ',' which will be replaced with the actual user input.
Create a variable with only character '
' and length of 20:


   **************   *  *** **  *      ******************************
  ********************* ** ** *  * ****************************** *
 **      *****************       ******************************
          *************          **  * **** ** ************** *
           *********            *******   **************** * *
            ********           ***************************  *
   *        * **** ***         *************** ******  ** *
               ****  *         ***************   *** ***  *
                 ******         *************    **   **  *
                 ********        *************    *  ** ***
                   ********         ********          * *** ****
                   *********         ******  *        **** ** * **
                   *********         ****** * *           *** *   *
                     ******          ***** **             *****   *
                     *****            **** *            ********
                    *****             ****              *********
                    ****              **                 *******   *
                    ***                                       *    *
                    **     *                    *

Enter fullscreen mode Exit fullscreen mode
  1. A variable is created with a sequence of 20 asterisk ('*') characters. This variable acts as a reference or placeholder for the initial replacement in the bitmap template.

  2. The algorithm replaces all occurrences of the substring generated in step 3 within the bitmap template with the actual user input text. This ensures that the portion of the template matching the length of the user input is now filled with the content of the input.
    Replace the '*' characters one by one with the user input text:

replace(outputs('BitmapTemplate'),outputs('replace'),triggerBody()['text'])
Enter fullscreen mode Exit fullscreen mode

In this final step, the remaining '*' characters in the bitmap template (those less than the length of the user input) are replaced one by one with the respective characters from the user input. This process completes the construction of the bitmap template, incorporating the user's message.

substring(outputs('Star'),0,sub(length(outputs('UsrInpt')),iterationIndexes('do_until')))
Enter fullscreen mode Exit fullscreen mode
replace(variables('Intoutput'),outputs('outputrefine'),substring(triggerBody()['text'],0,sub(length(triggerBody()['text']),iterationIndexes('do_until'))))
Enter fullscreen mode Exit fullscreen mode

Demo:

Devtp

Output:


   DevToDevToDevT   D  Dev De  D      DevToDevToDevToDevToDevToDevTo
  DevToDevToDevToDevToD De De D  D DevToDevToDevToDevToDevToDevTo D
 De      DevToDevToDevToDe       DevToDevToDevToDevToDevToDevTo
          DevToDevToDev          De  D DevT De DevToDevToDevT D
           DevToDevT            DevToDe   DevToDevToDevToD D D
            DevToDev           DevToDevToDevToDevToDevToDe  D
   D        D DevT Dev         DevToDevToDevTo DevToD  De D
               DevT  D         DevToDevToDevTo   Dev Dev  D
                 DevToD         DevToDevToDev    De   De  D
                 DevToDev        DevToDevToDev    D  De Dev
                   DevToDev         DevToDev          D Dev DevT
                   DevToDevT         DevToD  D        DevT De D De
                   DevToDevT         DevToD D D           Dev D   D
                     DevToD          DevTo De             DevTo   D
                     DevTo            DevT D            DevToDev
                    DevTo             DevT              DevToDevT
                    DevT              De                 DevToDe   D
                    Dev                                       D    D
                    De     D                    D

Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed this tutorial on how to create a bitmap with Power Automate. Hope to share few more tips in the future

Top comments (0)