Randomizing image

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Timberduck
Regular
Posts: 60
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

Randomizing image

#1 Post by Timberduck » Sat Jan 04, 2014 1:10 am

I have created a photo gallery
sample list :

##Gallery 1
image a = "a.jpg"
image ab = "ab.jpg"
image ac = "ac.jpg"
image ad = "ad.jpg"

and so on...

What I want to do is view 12 random images from the above chart then jump randommenu

bonus: is there a way to make sure the same image those not show up more then once in the 12 random image cycle.
I have over 300 some images charted


Any help would be awsome

\m/ TIMBERDUCK \m/

:D :D :D :D :D

User avatar
Biomass
Regular
Posts: 104
Joined: Tue Jan 01, 2013 11:13 pm
Contact:

Re: Randomizing image

#2 Post by Biomass » Sat Jan 04, 2014 2:16 am

You're looking to produce a random permutation of images from a list.

Theres a permutation function in the itertools python package that may be of interest to you.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Randomizing image

#3 Post by Alex » Sat Jan 04, 2014 1:17 pm

Try smth like

Code: Select all

##Gallery 1
image a = "a.jpg"
image ab = "ab.jpg"
image ac = "ac.jpg"
image ad = "ad.jpg"

label start:
    "..."
    $ img_list = ["a", "ab", "ac", "ad"]
    $ i = 2
    while i > 0:
        $ img_to_show = renpy.random.choice(img_list)
        $ img_list.remove(img_to_show)
        $ i -= 1
        show expression img_to_show with dissolve
        $ renpy.pause(1.0)
    jump randommenu

label randommenu:
    "?"
http://www.renpy.org/wiki/renpy/doc/ref ... dom.choice
http://www.renpy.org/doc/html/displayin ... -statement

Timberduck
Regular
Posts: 60
Joined: Sat Jan 04, 2014 12:52 am
Location: Canada
Contact:

Re: Randomizing image

#4 Post by Timberduck » Sat Jan 04, 2014 7:12 pm

Thanks Alex

It works perfectly.
Ill be publishing soon.

\m/ Timberduck \m/

Post Reply

Who is online

Users browsing this forum: Google [Bot]