# Random Theme Generator (Unified Version)

**URL:** <https://blenderartists.org/t/random-theme-generator-unified-version/431848>\
**Category:** Python Support\
**Created:** [November 3, 2008, 3:12am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848 "2008-11-03T03:12:06Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loadus](https://blenderartists.org/user_avatar/blenderartists.org/loadus/32/6268_2.png) [@Loadus](https://blenderartists.org/u/Loadus)\
**Post date:** [November 3, 2008, 3:12am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/1 "2008-11-03T03:12:06Z")

</div>

![http://www.loadusfx.net/blender/b_ui.jpeg](http://www.loadusfx.net/blender/b_ui.jpeg)

**Random Theme Generator**

I was tweaking a script by Kevin Morgan (forTe) - the random theme generator. The script had all the color functions, but it randomized everything, so the interface looked a bit scary afterwards.

I took some time with it to make a ‘unified’ version, that randomizes the colors, but makes them the same for every window. I made mad calculations to it to make different variations but with similar hues.

The calculations are a bit goofy, since I’m no programmer, it might crash because of bad boundaries etc etc. And this kind of script might already be available and be better but I was merely learning the syntax of the Blender python … ^^

The script [Updated with GUI and code-cleanup (thx hiower + dfelinto!)]:  
[http://www.loadusfx.net/blender/randtheme-uni-gui.py](http://www.loadusfx.net/blender/randtheme-uni-gui.py)

Have fun with it - if you optimize it, change it, improve it etc then post it here so everyone can enjoy it. 🙂

Tweak the settings to see how it changes the mood. Expect hallucinations. 😛

---

<div class="post-metadata">

**Author:** ![Meta-Androcto](https://blenderartists.org/user_avatar/blenderartists.org/meta-androcto/32/3989_2.png) [@Meta-Androcto](https://blenderartists.org/u/Meta-Androcto)\
**Post date:** [November 3, 2008, 3:18am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/2 "2008-11-03T03:18:07Z")

</div>

ha, nice one.

---

<div class="post-metadata">

**Author:** ![andrew-101](https://blenderartists.org/user_avatar/blenderartists.org/andrew-101/32/5549_2.png) [@andrew-101](https://blenderartists.org/u/andrew-101)\
**Post date:** [November 3, 2008, 3:31am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/3 "2008-11-03T03:31:01Z")

</div>

That was kinda freaky, I loaded up the script and my computer started beeping at me and all this gibberish appeared in the console. I tried it three times and it happened every time.

Here is a screenshot of the console:  
 ![http://i135.photobucket.com/albums/q146/andrew-101/_JPG.jpg](http://i135.photobucket.com/albums/q146/andrew-101/_JPG.jpg)

I actually really want to try this script out so if anyone has any ideas on what to do then thanks.

I’m running Window’s XP Home with Blender 2.48 and Python 2.5 if it helps

P.S, add:

```auto
# """
# Name: 'Random Theme Generator'
# Blender: 248
# Group: 'Theme'
# Tooltip: 'Make random themes!'
# """

```

under the ‘#!BPY’ to add it to the themes section of the scripts menu in the scripts window (file has to be placed in scripts first)

---

<div class="post-metadata">

**Author:** ![Loadus](https://blenderartists.org/user_avatar/blenderartists.org/loadus/32/6268_2.png) [@Loadus](https://blenderartists.org/u/Loadus)\
**Post date:** [November 3, 2008, 3:49am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/4 "2008-11-03T03:49:29Z")

</div>

> [@andrew-101](#):
>
> That was kinda freaky, I loaded up the script and my computer started beeping at me and all this gibberish appeared in the console. I tried it three times and it happened every time.

Yes, there are some missing int() tags in the script, but it shouldn’t throw that much stuff on you … I run it without errors, but then again I’m in Linux … 😛

I can add the description on the file if someone wants to install it … it needs a GUI first though. You should load the script into the texteditor and press ALT+P (Play script).

EDIT:  
added the description for the menu …

---

<div class="post-metadata">

**Author:** ![hiower](https://blenderartists.org/user_avatar/blenderartists.org/hiower/32/3073_2.png) [@hiower](https://blenderartists.org/u/hiower)\
**Post date:** [November 3, 2008, 5:16am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/5 "2008-11-03T05:16:36Z")

</div>

Cool script. I added the missing int(), so now it shouldn’t spit out any gibberish. I made it spit out the color values instead though, to help with debugging.  
[edit: forgot i commented these out. It shouldn’t spit out anything to the console now.]  
It seems that it is vertex and text\_hi that makes it break, namely because:int(power + random() \* power)  
can produce values larger than 255. So i changed it to:int(power + random() \* power \* (1-power/255.))  
Try it out, works 100% of the time for me now.  
[randtheme-uni\_debugged.py](http://users.tkk.fi/%7Enparo/pub/randtheme-uni_debugged.py)

Anyone has anywere to host this?

---

<div class="post-metadata">

**Author:** ![forTe](https://blenderartists.org/user_avatar/blenderartists.org/forte/32/867_2.png) [@forTe](https://blenderartists.org/u/forTe)\
**Post date:** [November 3, 2008, 5:19am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/6 "2008-11-03T05:19:17Z")

</div>

Hey, That’s pretty cool that somebody took my acid trip machine and made it generate really nice themes!

Perhaps I should have posted the script that actually generated my original script, though, to make it easier to modify. Perhaps I should also add my information to the original script too, so people can find me from it…

---

<div class="post-metadata">

**Author:** ![hiower](https://blenderartists.org/user_avatar/blenderartists.org/hiower/32/3073_2.png) [@hiower](https://blenderartists.org/u/hiower)\
**Post date:** [November 3, 2008, 5:30am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/7 "2008-11-03T05:30:39Z")

</div>

> [@hiower](#):
>
> Cool script. I added the missing int(), so now it shouldn’t spit out any gibberish. I made it spit out the color values instead though, to help with debugging.[edit: forgot i commented these out. It shouldn’t spit out anything to the console now.]

Scratch that. Uncommented the print lines again, as it still sometimes fails.  
\*Sometimes fails with hue values over 100  
\*Seems lamp and textc can get values below 0

---

<div class="post-metadata">

**Author:** ![hiower](https://blenderartists.org/user_avatar/blenderartists.org/hiower/32/3073_2.png) [@hiower](https://blenderartists.org/u/hiower)\
**Post date:** [November 3, 2008, 5:36am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/8 "2008-11-03T05:36:00Z")

</div>

As it is, i think coloring of vertices and faces need some work

---

<div class="post-metadata">

**Author:** ![Meta-Androcto](https://blenderartists.org/user_avatar/blenderartists.org/meta-androcto/32/3989_2.png) [@Meta-Androcto](https://blenderartists.org/u/Meta-Androcto)\
**Post date:** [November 3, 2008, 5:38am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/9 "2008-11-03T05:38:39Z")

</div>

> Perhaps I should also add my information to the original script too, so people can find me from it

the link in your sig helps too.  
thanks, I thought I had seen that somewhere before.

---

<div class="post-metadata">

**Author:** ![Loadus](https://blenderartists.org/user_avatar/blenderartists.org/loadus/32/6268_2.png) [@Loadus](https://blenderartists.org/u/Loadus)\
**Post date:** [November 3, 2008, 6:27am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/10 "2008-11-03T06:27:30Z")

</div>

Excellent, I can host the debugged version. I was about to attach the code to an UI I did on the Python GUI creator, but I have no understanding how the variables change from the slider controls. I just keep getting error after error (I don’t know the Python syntax properly yet).

Here’s the GUI imported into the file (uncorrected one, though), but the variables are not hooked in yet (I don’t know how). Anyone care to assist? ^^  
[http://www.loadusfx.net/blender/randtheme-uni-gui.py](http://www.loadusfx.net/blender/randtheme-uni-gui.py)

And yes, it was from forTe’s original script \<------ credit to who credit is due 🙂

---

<div class="post-metadata">

**Author:** ![dfelinto](https://blenderartists.org/user_avatar/blenderartists.org/dfelinto/32/2095_2.png) [@dfelinto](https://blenderartists.org/u/dfelinto)\
**Post date:** [November 3, 2008, 7:26am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/11 "2008-11-03T07:26:11Z")

</div>

Nice script.

I would suggest that instead of load it from the menu, run it as a ScriptLink activated on FrameChanged

And if you add this in the top:

```auto
#from Blender.noise import random ### I think is better to use the random below, can delete this line in fact :::
from random import random
from random import seed

seed(Blender.Get("curframe"))

```

You have a new theme each frame, and because of the seed you can produce the same theme again. 🙂 Press Alt+A and pick your theme 😃

And I would only suggest that you always avoid to set the same color for the text editor background and foreground.

EDIT::

And if you create a:  
[DEBUG = 0] in the top

and use [if DEBUG:] before all the print statements you run it (way) faster 🙂

---

<div class="post-metadata">

**Author:** ![hiower](https://blenderartists.org/user_avatar/blenderartists.org/hiower/32/3073_2.png) [@hiower](https://blenderartists.org/u/hiower)\
**Post date:** [November 3, 2008, 7:29am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/12 "2008-11-03T07:29:03Z")

</div>

Took my debugged version and put it into your gui, and hooked up the variables and stuff. Fixed the hue bug as well i think (implemented a check, if lamp or textc created color values below 0, it became 0 instead) I think it was because of multiple int().

[randtheme-uni-gui\_02.py](http://users.tkk.fi/%7Enparo/pub/randtheme-uni-gui_02.py)

Cheers

---

<div class="post-metadata">

**Author:** ![hiower](https://blenderartists.org/user_avatar/blenderartists.org/hiower/32/3073_2.png) [@hiower](https://blenderartists.org/u/hiower)\
**Post date:** [November 3, 2008, 8:19am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/13 "2008-11-03T08:19:26Z")

</div>

Ok, I don’t think this can be called random anymore 😃

[randtheme-uni-gui\_03.py](http://users.tkk.fi/%7Enparo/pub/randtheme-uni-gui_03.py)

[edit: cleaned up the code slightly + added debug mode]

---

<div class="post-metadata">

**Author:** ![hiower](https://blenderartists.org/user_avatar/blenderartists.org/hiower/32/3073_2.png) [@hiower](https://blenderartists.org/u/hiower)\
**Post date:** [November 3, 2008, 10:06am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/14 "2008-11-03T10:06:30Z")

</div>

Latest version. The script now:  
\*Have a gui  
\*Uses seed, so lets you change the different values independently + you can regenerate the same theme if you know its values  
\*Updates automatically when values change  
\*Catches any rgba values that are outside 0-255  
\*Has a working randomize function

[randtheme-uni-gui\_04.py](http://users.tkk.fi/%7Enparo/pub/randtheme-uni-gui_04.py)

---

<div class="post-metadata">

**Author:** ![Loadus](https://blenderartists.org/user_avatar/blenderartists.org/loadus/32/6268_2.png) [@Loadus](https://blenderartists.org/u/Loadus)\
**Post date:** [November 3, 2008, 10:27am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/15 "2008-11-03T10:27:47Z")

</div>

> [@hiower](#):
>
> Latest version. The script now:  
> \*Have a gui  
> \*Uses seed, so lets you change the different values independently + you can regenerate the same theme if you know its values  
> \*Updates automatically when values change  
> \*Catches any rgba values that are outside 0-255  
> \*Has a working randomize function
> 
> [randtheme-uni-gui\_04.py](http://users.tkk.fi/%7Enparo/pub/randtheme-uni-gui_04.py)

Wicked mon!  
I’ll host this from my server, if it’s ok. The code must’ve been messy, I did it for about 5h and at the last few minutes I couldn’t see line from the other. And my math sucks worse than ever. :D:D

I’d better stick to the graphics side …

---

<div class="post-metadata">

**Author:** ![hiower](https://blenderartists.org/user_avatar/blenderartists.org/hiower/32/3073_2.png) [@hiower](https://blenderartists.org/u/hiower)\
**Post date:** [November 3, 2008, 11:06am UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/16 "2008-11-03T11:06:22Z")

</div>

Well, I didnt bother much with the math to be honest, and those were the messy lines :rolleyes:  
I think it works quite nicely, there are still some things that could be improved though i think…  
\*if dark \> bright, text doesnt do anything sometimes.  
\*It’s difficult to generate a usable theme with light text on dark

[edit: and of course it’s ok that you host it]

---

<div class="post-metadata">

**Author:** ![andrew-101](https://blenderartists.org/user_avatar/blenderartists.org/andrew-101/32/5549_2.png) [@andrew-101](https://blenderartists.org/u/andrew-101)\
**Post date:** [November 3, 2008, 8:04pm UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/17 "2008-11-03T20:04:26Z")

</div>

This script is great, you should try getting it into the trunk.

---

<div class="post-metadata">

**Author:** ![dfelinto](https://blenderartists.org/user_avatar/blenderartists.org/dfelinto/32/2095_2.png) [@dfelinto](https://blenderartists.org/u/dfelinto)\
**Post date:** [November 3, 2008, 8:44pm UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/18 "2008-11-03T20:44:07Z")

</div>

I like the GUI thing, however I still think that this is more useful running as a ScriptLink. There is a way to run the GUI once, configure the parameters and load the parameters from a ScriptLink?

I think it is just a matter of store the parameters in Blender module or something similar.

And if it is to make all the generation through GUI, I would suggest a button to randomly create a new seed and a new theme. That way you can recreate the theme, but don’t need to change parameters all the time to have a different, random, theme.

---

<div class="post-metadata">

**Author:** ![hiower](https://blenderartists.org/user_avatar/blenderartists.org/hiower/32/3073_2.png) [@hiower](https://blenderartists.org/u/hiower)\
**Post date:** [November 3, 2008, 11:38pm UTC](https://blenderartists.org/t/random-theme-generator-unified-version/431848/19 "2008-11-03T23:38:19Z")

</div>

> [@dfelinto](#):
>
> I like the GUI thing, however I still think that this is more useful running as a ScriptLink. There is a way to run the GUI once, configure the parameters and load the parameters from a ScriptLink?
> 
> I think it is just a matter of store the parameters in Blender module or something similar.

I was thinking about the same thing after your script link idea. I think one needs 2 different scripts though, one with gui and one without. But saving parameters should be possible.

> [@dfelinto](#):
>
> And if it is to make all the generation through GUI, I would suggest a button to randomly create a new seed and a new theme. That way you can recreate the theme, but don’t need to change parameters all the time to have a different, random, theme.

That would be the “randomize” button 😕
