Modeling randomness in Blender can be frustrating. But once I figured out I could use Python to generate random numbers, it got a lot easier.
For this week’s project, I made 200 lights around my little bug using a simple loop, some variables, and a Python module.
Hold up. What’s a Module?
A module is a present from Python—it contains prewritten variables and functions to make things happen. The random module makes random numbers happen. And all you have to do is type “import WhateverModule” (in this case “import random”) at the beginning of the script.
You can read about this particular module’s functions here: https://docs.python.org/2/library/random.html.
Because I’m not so particular, I picked out the simplest one:
#This will return a random number between the two values
Alright, What About the Blender Commands?
The bug scene above doesn’t actually have any Blender lamps. I opted for UV spheres with a strong emission material to look like little lights.
Here’s the bare-bones formula for adding one:
The beauty of this is that the x,y,z parameters can be assigned to variables, ones that can be reassigned to a random number at the end of each run of the loop.
Before running the script, just remember to activate a layer with nothing else in it. And change up the parameters below to fit your model.
If all has gone according to plan, you should see this:
Now it’s just a matter of creating a texture to make the spheres light up. Deselect all other layers, so you’re only interacting with the spheres. Then assign one a texture.
Now select all the spheres (either by pressing A or box selecting), and press CTRL + L to link the material to all of them.
That’ll get you here.
After that, you can mix in more looped lights for different effects.