Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 1:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Variable height of objects
PostPosted: December 30th, 2004, 12:06 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
The following code (compliments of Robin) randomises a list of same-sized objects down the page.

I have been trying to alter

eval("obj_" + count + ".SetPositionY(" + ((numberlist[picked]*30)+6) + ")")

by inserting the 'getHeight' command so that a list of objects of different heights rather than all being 30 pixel high, will be evenly spaced down the page when executed. Every variation I try throws up error messages - guess I have too many plusses, or brackets or just the wrong place or, - the possible variations are getting too much to handle!

Advice would be appreciated. 6 - is where the top edge of the first item is to be displayed.

John

-----------------

function RandomList(number) {
numberlist = new Array();
for (count = 1; count <= number; count++) {
numberlist[count] = count;
}
randomlist = new Array();
for (count = numberlist.length - 1; count > 0; count--) {
picked = Math.floor(Math.random()*count)+1;
randomlist[count-1] = numberlist[picked];
eval("obj_" + count + ".SetPositionY(" + ((numberlist[picked]*30)+6) + ")")
numberlist[picked] = numberlist[count];
}
}

-----------------------------------------------


Top
 Profile Visit website  
 
 Post subject:
PostPosted: December 31st, 2004, 11:32 am 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Have edited the code with two new lines as follows

function RandomList(number) {
numberlist = new Array();
for (count = 1; count <= number; count++) {
numberlist[count] = count;
}
randomlist = new Array();
for (count = numberlist.length - 1; count > 0; count--) {
picked = Math.floor(Math.random()*count)+1;
randomlist[count-1] = numberlist[picked];

var objheight = eval("obj_" + count).GetHeight()
var newheight = newheight + objheight

eval("obj_" + count + ".SetPositionY(" + ((numberlist[picked] + newheight)+6) + ")")
numberlist[picked] = numberlist[count];
}
}

I'm trying to put the height of each new object into variable 'objheight' and adding that to the last value held in 'newheight' then displaying each object at 'newheight' - the logic works (for me), but the code doesn't!!!

The code displays each object simply in reverse order rather than randomly down the page. If I remove the second line of my code 'var newheight = newheight + objheight' then all the objects overlay each other at top of the page!

Any help appreciated.

John


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 4th, 2005, 3:05 pm 
Offline

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

Your first script appears to work fine (please see attached), although I needed to modify the numberlist[picked] multiplier and offset to ensure that my objects did not overlap.

Please compare the supplied publication to your current project to see if you can determine the cause of the problem. If you are unable to identify a solution, please send me your current .imp file and I will be happy to investigate further.

Kind regards,


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

_________________
Robin Garrett
Digital Workshop Technical Support


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 4th, 2005, 3:26 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Hi Robin,

Many thanks for your response.

My (your!) original code works fine, as does the new code from you.

My problem is that each of my objects can be a different height - hence my attempts to evaluate each object's height and add that height to the previous object's height so that the displayed, randomised list, shows the objects neatly under each other.

Hope that makes sense!

John


Top
 Profile Visit website  
 
 Post subject: clarify
PostPosted: January 5th, 2005, 3:36 am 
Hi John,
To clarify -- Re: "neatly under each other"
do you want to space objects of varying heights so the gap between consecutive objects is always the same, or do you want the object centers evenly spaced so the objects will not overlap?
Paul


Top
   
 
 Post subject:
PostPosted: January 5th, 2005, 5:42 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Hi,

Thanks for your interest.

The code and sample produced by Robin spaces evenly down the page a number of same height objects, in random order.

I have a number of objects that are of differents heights, but that will all fit within about 500/550 pixels. What I want to do is to display them in random order down the page, so that the bottom of the first object is just above the top of the next object - and so on to the last one. I can see the benefit of having the option of having a space of n pixels between each object for future projects - but this isn't crucial at the moment.

You will note from my posts that I tried amending Robin's original code by creating two new publication variables 'objHeight' and 'newHeight' and inserting the lines

objheight = eval("obj_" + count).GetHeight()
newheight = newheight + objheight

in an attempt to space the objects down the page by their actual height rather than simply mutiplying the object count by 30 pixels that represented the height of each of the objects I previously used this code for.

Robin's code will neatly place same sized objects in random order down the page, but I now need to do more than this.

Any help is greatly appreciated. But I have a feeling I might be confusing the issue by my explanations!

All the best,

John


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 9th, 2005, 7:09 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Still struggling with my problem!

Attached .imp file shows a list of quotations that I want to randomly display down the page. They vary in height, and I want them to stack neatly one above the other, starting six pixels from the top of the page, whenever the page is reset.

At the moment their order is simply being reversed.

John


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


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 10th, 2005, 12:56 am 
Offline

Joined: November 28th, 2004, 6:05 am
Posts: 141
Location: USA
Hi John

your script is fixed
the reason the objects were simply being reversed is in line 16

---------------------------------------------------------------------------
eval("obj_" + count + ".SetPositionY(" + ((newHeight)+6) + ")")
---------------------------------------------------------------------------

The "count" variable just counts backward from 12 as it goes
through the loop

Should have been

-----------------------------------------------------------------------------------
eval("obj_" + randomlist[count -1] + ".SetPositionY(" + ((newHeight)+6) + ")")
-----------------------------------------------------------------------------------

Which would have placed the objects in the reverse order of "randomlist"

Second, the SetPositionY is oriented to the center of the object so
in order to place the objects evenly, you must hold the height of
the previously placed object to be used in placing the current object
on each pass through the loop.

I've attached the fixed script with comments added.

Cheers
Chris


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

_________________
Opus Resources and Services


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 10th, 2005, 1:45 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Hi Chris,

Very many thanks for your help - works a treat. And thanks for adding the comments - helps me understand what's going on!

John


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 31 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group