cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
seadude
Level 10

Random Placement Greatness

Hello @mr-dang

 

I'm trying to implement the revered "full screen randomness" of a Gallery with TemplateSize 0, and I need your insights. 

 

So far I have: 

  • A Sharepoint list of 1508 emojis called "emojiList"
  • 2018-07-29_18-02-00.png
  • An OnStart Collection that grabs all the URL's of said emojis
    ClearCollect(
        colAllMojis, 
        {
            emoji: emojiList.url
        }
    )
  • An OnSelect button action of: 

 

ClearCollect(
    colDisplayEmojis, 
    {
        emoji: First(colAllMojis).emoji.url, 
        y: Rand(), 
        x: Rand()
    }
)
  • And finally an image Control in a TemplateSize-0 Gallery with Image Property set to:
  • ThisItem.emoji.url

But this is not working for me! I'm looking to click the button and see 1500 emojis on the screen in random places with each click (similar to your awesome Baby Smash-like text example). 

 

If I set the image control to : 

First(
    ThisItem.emoji).url

...I can get a single emoji to jump around the screen, but I WANT ALL 1500 ! :(). 

 

Can you guide?

 

1 ACCEPTED SOLUTION

Accepted Solutions
mr-dang
Level 10

Re: Random Placement Greatness

I think what you may need to do is change where you do the ForAll:

 

//Collect all emojis from Sharepoint column and apply a random x and y coordinate//

Clear(AllMojis);
ForAll(emojiList,
    Collect(
        AllMojis, 
            {
                link: url,
                x: RoundUp(Rand() * 1266 , 0 ),
                y: RoundUp(Rand() * 668 , 0 )
            }
    )
)

 

This means, "For each of the emojis in your emojiList, collect a record in a collection called AllMojis. Make it include the link to the respective URL in the emojiList, and give it a random number in the x and y column."

 

I rounded up the x and y to whole numbers.

Microsoft Employee
@8bitclassroom

View solution in original post

4 REPLIES 4
mr-dang
Level 10

Re: Random Placement Greatness

 

Ah, I know what it is. Rand() generates a random number between 0 and 1 (0 is inclusive, but not 1). You need to multiply it by the range you want to get the x and y coordinates you want.

 

So in the x direction, you'd multiply by Screen.Width, and in the y direction, you'd multiply by Screen.Height.

 

Let me know if that's it.

 

Brian

Microsoft Employee
@8bitclassroom
mr-dang
Level 10

Re: Random Placement Greatness

seadude
Level 10

Re: Random Placement Greatness

Wow... ~ 01:13 into Space Invaders Episode 1... incredible!

 

I'm close. Implemented your idea of screen size (minus size of emoji).

 

  • OnVisible of screen:
    • //Collect all emojis from Sharepoint column and apply a random x and y coordinate//
      
      ClearCollect(
          AllMojis, 
              {
                  link: emojiList.url,
                  x: ForAll(emojiList.url, Rand() * 1266),
                  y: ForAll(emojiList.url, Rand() * 668)
              }
      )
  • Gallery Items set to: 
    • First(AllMojis.link).link.url
  • Image in Gallery set to: (seriously!)
    • url
    • This works fine. I get all emojis on the screen...:
    • Screenshot from 2018-07-30 01-34-43.png
  • OnSelect of the Engage Coolness button: 
    • ClearCollect(
          colEmojis, 
          {
              //image: ForAll(AllMojis,link),//
              x: ForAll(AllMojis.link, Rand() * 1266),
              y: ForAll(AllMojis.link, Rand() * 668)
          } 
      )
  • Gallery Image X Property (sub "y" for Y Property as well):
    • First(First(colEmojis.x).x).Value
  • The emoji "stack" jumps around the screen when I hit Engage Coolnes, just can't seem to get EACH one to jump to a unique position. Getting wrapped around the wheel on this one.
  • Its difficult to understand how the First function and dot.notation are working here with these nested tables. 
  • Can you see where I can tweak the X and Y to randomize the emoji placement? 
    • Screenshot from 2018-07-30 01-34-45.png
  • Thanks so much
mr-dang
Level 10

Re: Random Placement Greatness

I think what you may need to do is change where you do the ForAll:

 

//Collect all emojis from Sharepoint column and apply a random x and y coordinate//

Clear(AllMojis);
ForAll(emojiList,
    Collect(
        AllMojis, 
            {
                link: url,
                x: RoundUp(Rand() * 1266 , 0 ),
                y: RoundUp(Rand() * 668 , 0 )
            }
    )
)

 

This means, "For each of the emojis in your emojiList, collect a record in a collection called AllMojis. Make it include the link to the respective URL in the emojiList, and give it a random number in the x and y column."

 

I rounded up the x and y to whole numbers.

Microsoft Employee
@8bitclassroom

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,902)