• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

'random' rotation at specified angles?

Explorer ,
Mar 10, 2018 Mar 10, 2018

Copy link to clipboard

Copied

To elaborate...

I already have a script for randomly rotating objects, but for this particular project I don't want them to rotate randomly from range of degrees; I'm looking for a way to randomly rotate a group of objects at either 90, 180, 270, or 360 degrees only.

I approached an engineer friend about this, and her suggestion was this:

var randNum = random.(0,3); // pick random # in range

var degrees = [90, 180, 270, 360];

var myRandDegree = degrees[randNum];

At this point, I generally understand the general principle of mapping 1-4 to the degrees I want to rotate, but—as I am not a programmer—I'm looking for help in getting the syntax of the script straight. Any help will be greatly appreciated. 

Thanks in advance!

*Also, would there be a way of applying this concept to randomly coloring a group of objects with a specific color palette? That would also be very useful.

TOPICS
Scripting

Views

4.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Advocate ,
May 30, 2020 May 30, 2020

Copy link to clipboard

Copied

Bonjour m1b,

Nombre entier aléatoire  multiple de 72 situé entre [ 0 et 360]   (72*5)
L'analyse est juste, sauf que la fonction parseInt(string[, base]) ne te permettra pas d'obtenir 360,

de plus tu as de la chance que Javascript soit un langage très conciliant:
string
Valeur qu'on souhaite analyser et convertir. Si l'argument string n'est pas une chaîne de caractères, elle sera convertie en une chaîne (grâce à l'opération abstraite ToString) . Les blancs contenus au début de l'argument sont ignorés.

 

 

 

for (var j = 0; j < 10; j++) {
var randomAngle =  parseInt(Math.random() *5); // nombre entre 0 et 5
    randomAngle *= 72;  // nombres  multiple de 72 situé entre 0 et 72*5=360
$.write(randomAngle+"\r");  // alert(randomAngle+"\r");
}

 

 

Juste pour info

var randomAngle = Math.round(Math.random() *5); // nombre entre 0 et 5

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 30, 2020 May 30, 2020

Copy link to clipboard

Copied

LATEST

Thank you Rene, I see your point. I don't know why I used parseInt! That was silly of me. 🙂

 

I don't really want 360 degrees because 360° is the same as 0° rotation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines