# random size, keep proportions

For questions about using Classic.

### » Fri Jun 08, 2012 12:58 pm

hi guys!

i have a feeling this is a complete noob question, but i really didnt find anything about it:

i want to create object randomly on a layer, this works fine enough, no problems.
but i also want to randomly set the size of the object while keeping its proportions. now, i cant find a simple set size action anywhere, i can only find set width and set height, but if i try to randomly set those upon creation, it doesnt keep the sprites proportions, instead, it can make for example width 50pixels, height 90pixels. and id want to keep them both the same amount. is there any simple enough solution i just cant figure out, being noob and all?

also, to make things more interesting, how can i make a random value between two values?
for example if i want to give a sprite a random size between the sizes 50pixels and 90pixels?

small bonus question:

ive been tinkering around with physics hinges, and already made some pretty neat stuff with it, but i still cant figure the basic logic behind hinges.
for example, if i create hinge from sprite a to sprite b, how can i make it so that the sprite b is also stiff? meanin that it would keep the angle relative to what it is upon creating hinge?
do i have to make hinges for both, sprite a and b?
thats all right, but it could get rather tedious when doing alot of hinges together.

little example:

if you make a car, 3 parts:
one body, two wheels. you have to make hinges FROM the body to the wheels, and that kind of confuses me. somehow i think it would be the complete opposite.

the mass is also something that puzzles me. if i made a say, simple ragdoll, with torso having the biggest mass, so i could apply force to hands, without it affecting the movement of the torso too much, what happens is that when moving the torso, the limbs that have smaller mass start to sort of act erratic, the hinges wont keep their position locked and they act "rubbery" even though having 100 stiffness.

anyone care to educate me?
B
1
Posts: 12
Reputation: 249

### » Fri Jun 08, 2012 3:08 pm

A simple solution for your proportion problem would be to only make either the width or the height random and not both. For example, if the original sprite is 50px wide and 30px high you can make the width random and then make the height equal to Sprite.Width*0.6 This will keep it proportional.Gelidaer2012-06-08 15:20:13
B
13
S
4
G
1
Posts: 63
Reputation: 1,170

### » Sat Jun 09, 2012 1:41 am

[QUOTE=frogbull]also, to make things more interesting, how can i make a random value between two values?
for example if i want to give a sprite a random size between the sizes 50pixels and 90pixels?[/QUOTE] Just add the offset to random() and use the range+1 in random. For example:
50 + random(41) => creates a random number in range [50, 90]
23 + random(101) => creates a random number in range [23, 123]
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

### » Sat Jun 09, 2012 9:17 pm

set Var = Sprite.X / Sprite.Y (so you have proportions now)
Sprite.X = Random(whatyouprefer) + minimumwidth
Sprite.Width / Var
This will keep it proportional.

Can be a bit wrong (but i dont think so), anyway you've got the ideaNugMan2012-06-09 21:19:13
B
19
S
6
G
4
Posts: 171
Reputation: 2,507

Return to Help & Support using Construct Classic

### Who is online

Users browsing this forum: No registered users and 4 guests