Selecting a random image / tips on making my idea

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Selecting a random image / tips on making my idea

Post by calmrr3 » Tue Nov 05, 2013 5:10 pm

Hi,
I have an idea for a small project, and as I am new to LiveCode I would be grateful for some help/tips etc.

Basically I have 4 images and each image has been cut into 20 strips.
I want to be able to build an image made up of 20 random strips from the 80 strips from the 4 images. (By clicking the 'Random All' button).

This part is more complicated:

I'd also like to be able to select an empty strip and then use the two sliders to select an image and then a strip from the chosen image to be displayed in that strip (then repeat for all 20 strips to build image).
I also want to have a 'random strip button' so that the user can select a strip and then either do the above or just click the 'random strip button' and let the computer choose one at random for you.

I've attempted to sketch this so that it makes more sense (i've only drawn 8 strips but I will require 20).
Image

Thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Selecting a random image / tips on making my idea

Post by dunbarx » Tue Nov 05, 2013 5:42 pm

Hi.

So do you have the 80 "strips" as individual images?

Certainly you can arrange random groups of 20 images side by side. Does each image have a name, like "img2c (third image of the second group)?

Think about this:

Code: Select all

on mouseUp
   repeat with y = 1 to 20
      put y into line y of tList
   end repeat
   sort tList by random(10000)
end mouseUp
Can you use this as a hint to generate your strips? Write back if not.

As for the slider, I am not exactly sure what you want. Is that slider "A" runs from 1 to 4, and slider "B" runs from 1 to 20, and the combination of the two selects an image from the bank of 80? If so, very simple in LC. Can you do this at all? Write back if not.

There will be a few wrinkles in all this, for example, I assume you do not want duplicates when selecting from the sliders, which may happen.

Without mentioning again that you can always write back, let us know if this is enough to get you started. For example, do you know how to place objects side to side? How new to LC are you? Have you ever made anything on your own?

Craig Newman

EDIT: Hmmm. Is it that the sliders only load a single strip based on the position of the thumbs? If so this is much easier, and there would be no duplication problems like I mentioned.

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Selecting a random image / tips on making my idea

Post by calmrr3 » Tue Nov 05, 2013 6:05 pm

Hi,

Each image is named A1-A20 B1-B20 ... all the way up to D20.
As for the slider, I am not exactly sure what you want. Is that slider "A" runs from 1 to 4, and slider "B" runs from 1 to 20, and the combination of the two selects an image from the bank of 80? If so, very simple in LC. Can you do this at all?
- Yes, that is what I am trying to do.

2 Things I am struggling with are:

Regarding your piece of code, what do I apply that script to?

&

When I open the card no strips will have been selected, this means there will be nothing to display. Should I just use rectangles to show the location of each strip so that the user knows where to click to select the location of the strip before choosing the image to go there.

I am completely new to LiveCode hence my lack of knowledge! Thanks for your help!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Selecting a random image / tips on making my idea

Post by dunbarx » Tue Nov 05, 2013 8:12 pm

OK.

This will be a great learning project. But do you know about messages, handlers, the message path, commands, etc.? Can you step through a handler in debug mode? I am going to assume that you already have just a little experience, in that you can create an object, load its script and debug. If not, we need to stop and rethink.

But if so, make a button and put that mouseUp handler into its script. Set a breakpoint at "end MouseUp". The list you get is a random set of numbers from 1-20. My question was this: can you take that list and set the locs of, say, your "A" group so that they lay side by side in your display space? You would map the numbers to some reference to each strip. A million ways to do this, and that is both good news and bad news for you.

As for the slider portion, it might indeed be good to create a grid, perhaps with rectangular graphics or whatever, and name them "g1, g2, etc." Then when you click on one of them, you might set its border thicker or focus on it or whatever, and then the slider would know where to load a strip.

Make a slider and put this into its script:

Code: Select all

on scrollBarDrag
   put the thumbPosition of me
end scrollBarDrag
Can you use this number to locate the proper strip? Can you find the graphic which is selected? You have hints, but no answers. Can you start with these? Do write back if not, but focus on one task at a time.

Craig

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Selecting a random image / tips on making my idea

Post by calmrr3 » Wed Nov 06, 2013 3:21 pm

Hi,
This is probably not the most efficient way of doing this but I have created 20 buttons with the following script:

Code: Select all

on mouseUp
   repeat with y = 1 to 60
      put y into line y of tList
   end repeat
   sort tList by random(10000)
if y = 1 then set the blendLevel of img "a1.jpg" to 0
end mouseUp
Would it work if I just assigned an image to a value?
i.e

Code: Select all

if y = 1 then set the blendLevel of img "a1.jpg" to 0
- reapeat this line for value 1-80 and assign a value to each? And then change the blendLevel to hide/show each image?


EDIT: Just realized that this method will just keep pilling up images and not resetting the blend value to 100 when a new image is chosen

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Selecting a random image / tips on making my idea

Post by dunbarx » Wed Nov 06, 2013 5:48 pm

Do you need to set the blendLevel? Couldn't you just hide and show the images? A reason to use the blendLevel would be if you wanted to have the image fade in and out of its location, instead of just popping in and out. This is another small project in and of itself.

I do not see what the "y=1" thing is doing. The point of making that randomized list was to allow you to place the images in a random way: (pseudocode)

repeat with y = 1 to the number of lines of randomList
set the loc of image (line y of randomList) to the loc of graphicArea y
end repeat

Provided that "graphicArea" was one of those shapes that would contain a strip, and that both the images and those shapes were ordered in some way. These are all hints. Keep at it. When you are ready for the slider part, let us know.

Craig

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Selecting a random image / tips on making my idea

Post by calmrr3 » Wed Nov 06, 2013 8:23 pm

Oh yes, ignore that blendLevel bit.

This is what I have so far (one strip):
I've "imported as control" all 80 images and then made the location of these the same so that they are piled up one on top of the other. On top of this pile of images is a button (blendLevel is at 100 so that it doesn't hide the image(s)).
The script for the button is:

Code: Select all

on mouseUp
   repeat with y = 1 to the number of lines of randomList
set the loc of image (line y of randomList) to the loc of graphicArea y
end repeat
   sort tList by random(10000)
end mouseUp
I feel like im at a dead end due to my lack of LiveCode understanding,
Am I right in thinking that what I want to make is a series of 20 buttons lined up to represent the strips of the image. Each time a button is pressed it will find a random number between 1 and 80 and then show the corresponding image strip?

I am really struggling with this one! LiveCode is very different to html etc! Thanks again for your help!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Selecting a random image / tips on making my idea

Post by dunbarx » Wed Nov 06, 2013 9:17 pm

OK.

Simon will kill me.

You already have the 80 images stacked up, and I see you have named them as you said, "A1", "A2", etc.

The pseudocode I gave you requires some work. It is a concept only, in that you have to make sure your object references are real. Since you already have your randomList, the next step is to place 20 of those images onto their target strips. Have you named those target strips? What did you make them out of? Anyway, I will assume they are graphics, and use their numbers. I hope they are the only graphics on the card, at least for now.

Now your button would read:

Code: Select all

on mouseUp
   repeat with y = 1 to 20
      put y into line y of temp
   end repeat
   sort temp by random(10000) --gets your randomized list from 1 - 20. This process is finished.
   
   repeat with y = 1 to 20
      set the loc of image ("A" & y) to the loc of grc (line y of temp) --see the "a & y" thing? See how this works? Same with the "line y of temp"?
   end repeat
end mouseUp
Please read this, and even step through it, watching the variables. Write back...

Craig

Post Reply