cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

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

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

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

Re: Random Placement Greatness

Highlighted
Super User
Super User

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

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

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (3,175)