Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently January 22nd, 2025, 11:19 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: pictures appear at random on a page
PostPosted: March 21st, 2005, 5:21 pm 
Offline

Joined: November 27th, 2004, 12:35 am
Posts: 19
Location: London and Cambridge UK
Opus: Opus pro 9
OS: Windows 7
Hi
I want to make objects/pictures appear at random on a page.

I know the theory, set random x and y co-ordinates and then position the picture at those co-ordinates.
It's just how to actually do it that rather bothers me. I could do with a general plotting routine to start off.

I'm creating a series of touch screen activities for pupils with special educational needs.

I could also do with restricting where the things appear, and then animating them afterwards (which I can do using the normal Opus animation controls).

I'm using Opus pro

Richard Walter


Top
 Profile  
 
 Post subject:
PostPosted: March 22nd, 2005, 4:01 am 
Offline

Joined: October 26th, 2004, 1:26 pm
Posts: 262
Hi Richard,

See attached IMP which demonstrates what you are after. The image (vector in this case) is set off the page in the editor, so it does not 'flicker' on screen, as it is shown.

There is a non-script and script version. The script version uses the minimal requirements. It is easy to set the maximum limits so the image will not be trunctated on the edge of your sized page, but you'll need someone more knowledgable in script on how to get random() to be within a range.

Someone will help further I am sure. :wink:


You do not have the required permissions to view the files attached to this post.

_________________
Cheers,
Steve


Top
 Profile  
 
 Post subject:
PostPosted: March 22nd, 2005, 10:51 am 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
Hi,

Thank you for your enquiry.

The easiest way to produce a random integer within a certain range is to simply multiply the Math.random() function (which produces a random number between 0 and 1) by the maximum value in your range. So, for example, if you wanted to generate a random x co-ordinate between 0 and 800 (the width of your page), you would use the following script:

Code:
x = Math.random()*800


As this can produce numbers with lots of decimal places you may wish to round down or round up the value to the nearest whole number. To do this, simply use the following code:

Code:
x = Math.round(Math.random()*800)


Please note that the SetPosition() function dictates the mid-point of the target object, so you may wish to take the width of the object into account when generating the random number. Otherwise, your image may end up positioned too close to the edges of the page, truncating the image. The following script should ensure that the random number falls within the correct range:

Code:
pagewidth = 800 //change this value if your page is a different size
imagewidth = Image.GetWidth()
x = Math.round(Math.random()*(pagewidth-imagewidth))+(imagewidth/2)
Image.SetXPosition(x)


I hope this helps. Please do not hesitate to contact me if you have any further queries.

Kind regards,

_________________
Robin Garrett
Digital Workshop Technical Support


Top
 Profile Visit website  
 
 Post subject:
PostPosted: March 23rd, 2005, 5:17 pm 
Offline

Joined: November 27th, 2004, 12:35 am
Posts: 19
Location: London and Cambridge UK
Opus: Opus pro 9
OS: Windows 7
Thanks Robin and Steve,
I've never noticed the script section in the animation section of actions,
which just goes to show.
I've made a little something based on the example that Steve sent, the non-script version.
I also recently discovered the move object to cursor action that is making it much easier to create programs to help develop mouse control with our students.
I put the example of the random pictures and mouse control on the school website:
http://atschool.eduweb.co.uk/meldreth/t ... p/Powp.htm
it's at the bottom of the Activities in Opus section.

thanks
Richard Walter


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group