No random color

Next
 From:  Frenchy Pilou (PILOU)
4517.1 
Hello
I have this script of random colors by Michael
script: /* Randomize style colors */ var styles = moi.geometryDatabase.getObjectStyles(); for ( var i = 0; i < styles.length; ++i ) { var style = styles.item(i); var red = Math.random() * 255; var green = Math.random() * 255; var blue = Math.random() * 255; style.color = (red << 16) | (green << 8) | blue; }

How to change it for have for example var blue= 13, then var blue = 15, then var blue = 17 etc for have no random color
and of course same for red and green for make some controled gradients :)

Surely very easy but as I don't know very well this language, i will make maybe some days before to find something with the good syntax! :)

Thx by advance :)

PS A script who create 100 styles ? for avoid to type some keys :)

And something for load a palette of color?

EDITED: 17 Sep 2011 by PILOU

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
4517.2 In reply to 4517.1 
Hi Pilou,

> How to change it for have for example var blue= 13, then
> var blue = 15, then var blue = 17 etc for have no random color
> and of course same for red and green for make some controled gradients :)

Well, that particular script that you showed there assigns random colors to every existing style.

Meanwhile what you are describing here is pretty different from that - if you want to create a gradient or something that kind of means that you would be working on some particular number of styles, I guess maybe creating some specific number of new styles rather than manipulating the existing list of them?

Anyway I would need more exact information on what you would want such a script to do.


> PS A script who create 100 styles ? for avoid to type some keys :)

Here's one that will do that:

script: /* Add 100 styles */ for ( var i = 0; i < 100; ++i ) { var style = moi.geometryDatabase.addStyle(); style.name = 'Style ' + (i+1); }> And something for load a palette of color?

Load a palette of colors from where - from an image? From a text file? This may be getting to a level of detail where I won't be able to create it for you directly, but I could try to help you if you want to write some more complex scripts like this yourself.


One thing that would help a lot though is if you were much more detailed in planning exactly what the script should do.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
4517.3 In reply to 4517.2 
More precision :)
100 existing objects = selection

Style 1 to style 100 are a gradient that we can easy manage if
we can make something like this
of course increment can be anything, and start color anything following wish of the artist :)

pseudo code
/start colors
red=12
green=15
blue=20

for i= 1 to 100
Style i = red, green, blue
object i =Style i
/increment
red=red+2
green=green+3
blue=blue+7
end i

of course if 255 is the max for each Red, Green, Blue we take another increments and/or start colors :)

EDITED: 17 Sep 2011 by PILOU

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
4517.4 
About the palette
something from a 2d prog like toshop who gives a palette of 100 colors (if 100 colors are needing)
---
Pilou
Is beautiful that please without concept!
My Gallery
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
4517.5 
If there are more objects than the palette colors
these are using the palette in cyclic mode (so no random mode)
---
Pilou
Is beautiful that please without concept!
My Gallery
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
4517.6 In reply to 4517.3 
Hi Pilou,

re: pseudo code - that translated to actual code is like this:

script: /* Make gradient styles */ var red = 12, green = 15, blue = 20; for ( var i = 1; i <= 100; ++i ) { var style = moi.geometryDatabase.addStyle(); style.name = 'Gradient ' + i; style.color = ((red%256)<<16) | ((green%256)<<8) | (blue%256); red += 2; green += 3; blue += 7; }

If you run that script it will create 100 styles that are assigned a gradient by the same increments as your pseudo code.

If you want to vary it, change the start values where it says:
var red = 12, green = 15, blue = 20;

or change the increment part at the end where it says:
red += 2; green += 3; blue += 7;

In this one when a value is incremented more than a value of 255 it will "wrap around" back to 0 and continue from there.

Note that this one creates 100 styles as part of the process, don't create 100 blank styles before running it unless you want to have 200 styles total.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
4517.7 In reply to 4517.4 
Hi Pilou,

> About the palette
> something from a 2d prog like toshop who gives a palette of
> 100 colors (if 100 colors are needing)

Unfortunately that takes quite a bit of work to produce a UI for that kind of full Photoshop color palette management.

That's beyond what I can do in a few minutes with a script, you would need to develop something of that level of complexity on your own - I could try to help you out in some particular spots if you want to undertake it.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  BurrMan
4517.8 In reply to 4517.6 
Haaaaahahahaaa... That is cool!
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
4517.9 
Michael you rock again! Bravo!
I suppose there is no problem to give a negative increment
red - = 4 (if it's the syntax and take care of a last result less 0 :)

No problem about the toshop palette with your script i can yet make some crazzy gradients!

EDITED: 18 Sep 2011 by PILOU

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
4517.10 
And how apply these new gradients styles to the selection of Objects ? :)

I know for apply them as random mode but with these new gradients in normal mode?
(by Michael)
script: /* Assign random styles to solids */ var styles = moi.geometryDatabase.getObjectStyles(); var breps = moi.geometryDatabase.getObjects().getBReps(); for ( var i = 0; i < breps.length; ++i ) { var brep = breps.item(i); var style_index = Math.floor(Math.random() * styles.length); brep.styleIndex = style_index; }

Surely trivial but...
works only if number of objects <= numbers of styles
how make if numbers of object are bigger than the gradients and wanted cyclic result?
(of course i can reselect the no color objects and relaunch the script but... :)

something like this ? modification of the script above :)
script: /* Assign styles to solids */ var styles = moi.geometryDatabase.getObjectStyles(); var breps = moi.geometryDatabase.getObjects().getBReps(); for ( var i = 0; i < breps.length; ++i ) { var brep = breps.item(i); var style_index = i; brep.styleIndex = style_index; }

here nice result for the gradients'style!

EDITED: 18 Sep 2011 by PILOU

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
4517.11 In reply to 4517.9 
Hi Pilou,

> I suppose there is no problem to give a negative increment
> red - = 4 (if it's the syntax and take care of a last result less 0 :)

Hmmm, I don't think that script was expecting for the numbers to become negative. You may need to add in an additional Math.abs( ); call to take the absolute value for that case, something like:

script: /* Make gradient styles */ var red = 12, green = 15, blue = 20; for ( var i = 1; i <= 100; ++i ) { var style = moi.geometryDatabase.addStyle(); style.name = 'Gradient ' + i; style.color = (Math.abs(red%256)<<16) | (Math.abs(green%256)<<8) | Math.abs(blue%256); red += 2; green += 3; blue -= 7; }

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
4517.12 In reply to 4517.11 
Sorry for the complexification but now that is total control for generate gradient by hand ;)

EDITED: 18 Sep 2011 by PILOU

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
4517.13 In reply to 4517.10 
Hi Pilou,

> something like this ? modification of the script above :)

Yup, it looks like that works, except the only problem would be if you had more than 100 objects the ones that were above the last style index will end up with the default first style applied to them instead, since that would be trying to assign them a style that does not exist.

So maybe you would want to wrap around to avoid that, something like:

script: /* Assign styles to solids */ var styles = moi.geometryDatabase.getObjectStyles(); var breps = moi.geometryDatabase.getObjects().getBReps(); var style_index = 0; for ( var i = 0; i < breps.length; ++i, ++style_index ) { if ( style_index == styles.length ) { style_index = 0; } var brep = breps.item(i); brep.styleIndex = style_index; }

This one when it reaches the last style it will start over at 0 for the next style after that.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
4517.14 In reply to 4517.13 
Works like a charm!
Total success!
Bravo!
here test with the default Styles modified the black one in yellow ;)
The 2 orange red on the bottom left side are just the new beginning as 100 is not dividing by 7 :)

EDITED: 18 Sep 2011 by PILOU

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
4517.15 In reply to 4517.14 
Now you can create many candy models! :)

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
4517.16 
Hello Michael
does your plug accept value like this red -=5.7 ? or it's truncated to 5 or 6 ?



EDITED: 19 Sep 2011 by PILOU

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Mike K4ICY (MAJIKMIKE)
4517.17 In reply to 4517.16 
Neat spiral thing, Pilou... makes me hungry for gummmmy worms. :-)

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
4517.18 In reply to 4517.16 
Hi Pilou,

> does your plug accept value like this red -=5.7 ? or it's truncated to 5 or 6 ?

I think that should work - the actual color value used will automatically get truncated to an integer value. Let me know if it doesn't seem to work right.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Frenchy Pilou (PILOU)
4517.19 In reply to 4517.18 
All works fine when we enter decimal value so we have not to think when we make divide rgb color by number of styles :)

It's not very ergononomic but very efficient! :)

I have made a little tut ;)

EDITED: 19 Sep 2011 by PILOU

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All