Images randomised according to rules?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
streamline
Posts: 10
Joined: Wed May 13, 2009 4:04 am

Images randomised according to rules?

Post by streamline » Wed May 13, 2009 4:19 am

Hi,

I've done some searching on the forum and while I couldn't find answers to my questions it is apparent that the users here are very helpful, so I thought I'd ask questions myself.

The basic application of a program I am trying to write has two stages which are repeated numerous times. The second stage is a pair of images, the first stage will either be an image which matches one of the pair, an image which doesn't match either of the pair, or there will be no image at all.

Matching image/different image/no image -> Pair of images

Now the problem: I want every image randomised -- but -- there needs to be equal instances of there being matching/different/no image. So for example 10 instances where the first image matched one of the pair shown after it, 10 where the image didn't match either, and 10 where no image is shown at all (but the pair still is). Also I don't want any pairs to be repeated, and the images in the pair cannot be the same one.

I'm not sure how to approach this, and have limited Rev knowledge so I don't know where to begin. Any help would be greatly appreciated.


Edit: Also, this would be repeated around 60-120 times or more. So making a separate card for each set would be unworkable. How can I break it down into fewer cards?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Wed May 13, 2009 10:50 am

Streamline,

welcome to the forum.

I do not completely understand what you want. But from what I gather you could do it all on one card with all the images on one card but hidden.
You would have lists of names of the images that you can easily handle to decide which images to show and how often.

If you put the names of matching pairs on a line and separate them by comma. So you could say

Code: Select all

show image (item 1 of line x of myList)
show image (item 2 of line x of myList)
if item 3 of line x of myList is not empty then
  show image (item 3 of line x of myList)
end if
to hide images just do

Code: Select all

repeat with i = 1 to the number of images
hide image i
end repeat
If your images are large or the computer is slow then you can wrapp the image hide/show commands with lock screen/unlock screen.
The idea is that once you have the names of the images in a list then you have pretty good control over what you make visible and how and for how long you make it visible. Random is no problem in this approach.

does this make any sense in your setting?
regards
Bernd

streamline
Posts: 10
Joined: Wed May 13, 2009 4:04 am

Post by streamline » Wed May 13, 2009 3:16 pm

I'm not sure what you mean, how does that script make it random? It has to be different every time the program is run, I can't manually randomise it once and keep using those choices.

Also this may be complicated by the fact that I am recording things. After each pair is shown, the user will choose an image by pressing a button below the one they want, which will note the choice in a text file (not sure how I'm going to make it recognise matched pairs etc, I figured I'd work out the randomisation before how to record it). The button will make the buttons hide and be replaced by a new button which must be pressed to go to the next set of images.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Wed May 13, 2009 3:50 pm

streamline,

to do some sort of random you would do

Code: Select all

put any line of myListOfImages into myVariable
show image item 1 of myVariable 
show image item 2 of myVariable
show image item 3 of myVariable
the keyword any is not random in a true mathematical sense (which seems to be hard to get) but for most purposes it is sufficent.
or you could say

Code: Select all

put line (random(the number of lines of myListOfImages) of myListOfImages into myVariable
which is the same as what you get with 'any'

look up 'random' and 'any' in the dictionary. It is helpful to look at how Rev operates on chunks (an item, a word, a line, a character) and so on. So if you make up your list of image as I suggested made up of lines (return delimited) and on each line items (all the text between commas) then you could do what I think you are doing. Of cours there are other ways, depending on what you want exactly. But the line/item thing is very flexible and easy to understand/manipulate. And for lists that are not very long (150 lines is not very long) speed should not be an issue. If speed is an issue you might want to use an array which on the other hand is a little more involved.

is it this what you mean? Apparently you are doing some experiments. In my opinion Rev is very well suited to do that. You have very good control over how long an image is displayed, how long it takes to answer, what the answer is and so on. Just keep asking.
Bernd

streamline
Posts: 10
Joined: Wed May 13, 2009 4:04 am

Post by streamline » Thu May 14, 2009 3:40 am

Yep, it's for a psychology experiment. The only coding I've done in the past is HTML/CSS (does that even count?) and I was first introduced to Revolution on Monday so this is a bit of a learning experience.

Also, here's the current script I've written on the main card, which might give more of an idea of what I'm doing.

Code: Select all

on preOpenCard
   hide image "Prime" -- must be randomised
   hide image "Left" -- must be randomised
   hide image "Right" -- must be randomised and different to Left
   hide image "Mask" 
   hide field "txtReady"
   hide group "grpQuestion"
   hide button "btNextPair"
end preOpenCard
on openCard
   show field "txtReady"
   wait 2000 millisec
   hide field "txtReady"
   show image "Mask"
   wait 500 millisec
   lock screen
   hide image "Mask"
   show image "Prime"
   unlock screen
   wait 35 millisec
   lock screen
   hide image "Prime"
   show image "Mask"
   unlock screen
   wait 500 millisec
   lock screen
   hide image "Mask"
   show image "Left"
   show image "Right"
   unlock screen
   wait 1500 millisec
   show group "grpQuestion"
end openCard
Thanks for the help so far, the last post looks promising, I will play around with your suggestions soon.

streamline
Posts: 10
Joined: Wed May 13, 2009 4:04 am

Post by streamline » Thu May 14, 2009 5:45 am

A few questions, I think I misunderstand your idea.

- where would I put the list?
- how would I format the list? like this?:
Images/1.png,Images/2.png,Images/3.png
- wouldn't this mean I need to list all possible combinations of prime-left-right images? 120x120x120 = a lot of lines...

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am

Post by acidjazz » Thu May 14, 2009 6:56 am

Streamline,
You can do pretty much your entire study on one card, using "repeat" statements to loop through the images, checking for doubles with "if then" statements, etc. As Bernd noted, the random() or "any" functions are the way to go, although I believe they give you sampling with replacement, and I suspect you want sampling without replacement until all pictures are exhausted. Is that correct? Regardless, given that you've cleverly named your images 1.png, 2.png, etc. you do *not* have to type everything out, but can change the names dynamically. I started working on code last night to show you, but have gotten distracted (twice!). I'll try again tomorrow and send you what I complete. I'm an applied cognitive psychologist working on a guide to using Revolution in psychology experiments, so I feel a moral obligation to help! In the meantime, I'd love to hear more about the particulars of your priming study.

Actually, if you could send me (off list) a more thorough description of your experiment method, it would help me. Here's my address:

pezzo at mail dot usf dot edu


Cheers,
Mark P.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu May 14, 2009 9:39 am

streamline,
I was first introduced to Revolution on Monday
What? Today is thursday, what were you doing all week long? :)

Since Mark is offering to help you I pull out of this. I guess when he gives you an example many things will be a lot clearer.
regards
bernd

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am

Post by acidjazz » Fri May 15, 2009 7:25 am

Streamline,
You there? I think I've got it all figured out, , but not sure how you feel about the FIRST image being repeated across trials. Say that you show a cat as the first Image on trial 1. If the same cat comes up randomly on, say, trial 68, is that a problem?

-- Mark

streamline
Posts: 10
Joined: Wed May 13, 2009 4:04 am

Post by streamline » Fri May 15, 2009 10:19 am

bn wrote:streamline,
I was first introduced to Revolution on Monday
What? Today is thursday, what were you doing all week long? :)
Actually I spent more time than I should have playing with Rev over the last few days, heheh.

I sent you an email Mark, thanks.

Post Reply