cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
seadude
Memorable Member
Memorable Member

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
Community Champion
Community Champion

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
Community Champion
Community Champion

 

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
Community Champion
Community Champion

seadude
Memorable Member
Memorable Member

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
Community Champion
Community Champion

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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,917)