PDA

View Full Version : Linear spread of object


Nicool
05-18-2003, 09:17 AM
Hye,
I'm working on a script to spread object linearly... As if a ramp existed. It's a bit as the probality in maths, the chance for the object to be spread in the white is very low, in the black, very high.

How to code it? And how to make a thresold, to make the white concept : x=20 (in axis).

Note : I don't want use ramptexture as possible.

X-Tender
05-18-2003, 09:50 AM
do you want to use it for particles? .. then you can give every particle a random lifetime when it get emitted .. the random number is your max threasold.

Nicool
05-18-2003, 10:10 AM
It's object like mesh. Notice : no animation.

Look at the script i've now. Follow the comments, I'm working on the part 3 "manipulate" (here translate ramdomly lineary)


int $nbLetters = 10; //Integral value sat by the user.


for ($n = 0; $n < $nbLetters; $n++) {

// Choose randomly the letter.
string $alpha[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
int $randomLetter = `rand 0 25`;
string $letter = $alpha[$randomLetter];


// Choose randomly the font.
string $fontList[] = `fontDialog -FontList`;
int $nbFonts = `size $fontList`;
int $randomFont = `rand 0 $nbFonts`;
string $font = $fontList[$randomFont];


// Build and manipulate the letter object.
string $letterObject[] = `textCurves -t $letter -font $font`;

float $randMoveX = `rand 0 20`;
float $randMoveY = `rand -5 5`;
move $randMoveX $randMoveY 0 $letterObject;

float $randRotate = `rand 0 360`;
rotate 0 0 $randRotate $letterObject;

float $randScale = `rand 0.5 1.5`;
move 0 $randScale $randScale $letterObject;

}

X-Tender
05-18-2003, 10:24 AM
try this. i dont know if it work .. its early in the moring an the night was long ;) ...


$max_x = 4234; //your maximum x value

float $random = rand(100); // get a random value ..

float $sqr = sqrt $random; //make a sqare root of the randowm number
$sqr /= 100; // divide it by 100 to get a value between 0 and 1
$final_x_pos = $sqr * $max_x; //mutiply it with your max_x value the get the final possition


put thw whole shit into an loop to create for every object a rand x pos ..

Nicool
05-20-2003, 03:14 PM
It doesn't work :(
So I'm obliged to show what I want obtain for this grraphic project. It's to get 2d images, and if I use mel, it's because I've not illustrator, and people say scripting in illustrator isn't powerful :rolleyes:

So help me to h ad the line I need in the third part of my script

1001 thanks

X-Tender
05-20-2003, 06:01 PM
k .. i used thic code


int $nbLetters = 5000; //Integral value sat by the user.

for ($n = 0; $n < $nbLetters; $n++) {
string $alpha[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
int $randomLetter = `rand 0 25`;
string $letter = $alpha[$randomLetter];

string $fontList[] = `fontDialog -FontList`;
int $nbFonts = `size $fontList`;
int $randomFont = `rand 0 $nbFonts`;
string $font = $fontList[0];


select -r (`textCurves -t $letter -font $font`);
string $chart[] = (`ls -sl`);

$max_x = 5000;

float $random = rand(100);

float $sqr = `sqrt $random`;
$sqr /= 100;
$final_x_pos = ($sqr * $max_x);
float $randMoveY = `rand -100 100`;
move -r $final_x_pos $randMoveY 0;
};


to get this:
|
V

Nicool
05-20-2003, 06:29 PM
It's exactly what I need! Right done! You've coded it as a master!

X-Tender
05-20-2003, 07:09 PM
:thumbsup: No Prob!

Nicool
05-21-2003, 02:36 PM
Thanks again to X-tender.
This is evidently an application I needed for a graphic project. Imagine the time to build this type of image.

Use it as code example !


int $nbLetters = 50; //Integral value sat by the user.

for ($n = 0; $n < $nbLetters; $n++) {

// Choose randomly the letter.
string $alpha[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",

"q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
int $randomLetter = `rand 0 25`;
string $letter = $alpha[$randomLetter];


// Choose randomly the font.
string $fontList[] = `fontDialog -FontList`;
int $nbFonts = `size $fontList`;
int $randomFont = `rand 0 $nbFonts`;
string $font = $fontList[$randomFont];


// Build and manipulate the letter object.
string $letterObject[] = `textCurves -t $letter -font $font`;
select -r $letterObject;

int $maxXMoveValue = 1000;
float $sqrt = `sqrt(rand(100))`;
$sqrt /= 100;
float $randMoveX = ($sqrt * $maxXMoveValue);
float $randMoveY = `rand -10 10`;
move $randMoveX $randMoveY 0;

float $randScale = `rand 1 3`;
scale $randScale $randScale 1;

float $randRotate = `rand 0 360`;
rotate 0 0 $randRotate;

planarSrf $letterObject;
delete $letterObject;

print ("Letter randomly chosen : " + $letter + " | Font randomly chosen : " + $font + "\n");
}

alexx
05-21-2003, 03:44 PM
just one thing:

you will never select the letter "z" in your scripts - at least very very very seldom, since your random range has to hit 25 exactely to see the letter..
i think, that a rand will even never hit its upper limit (unfortunately that is not clear after reading the manuals).
(after testing a bit i am quite sure about it)..

so you should set your range of rand from 0 to 26 to get return int values from 0 to 25

cheers

alexx

btw.. nice one x-tender :)

Nicool
05-21-2003, 04:01 PM
ok, it's true :) Thanks.

CGTalk Moderation
01-15-2006, 04:03 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.