Game of life
It’s Alive
Decided to see if I could create a script that would use the rules from John Conway’s game of life into blender, thought process and code below.
Clear pre-existing objects
Create object grid
create_grid(width, length, height, collection)
Collection = name of collection
No output
Set all objects to 0 scale
zero_size(collection)
Collection = name of collection
No output
Create object pattern
object_locations(collection)
Collection = name of collection
Output:
Dict of (objectName : objectLocationVectors)
location_generation(target)
Target = string of object name
Output:
List of objectLocationVectors for objects surrounding the target
object_config_two(shell, objVectors)
Shell = output of location_generation
objVectors = output from object_locations
Removes some items from the shell(list)
For any remaining LocationVector in the list, if this value appears in objVectors then its corresponding key is used to select the object and re-set its scale to 1
No output
the variables ‘window’, ‘cross’, ‘vertline’, ‘pillers1’ and ‘pillers2’ are preset arrangements of a grid of 3 * 3 * 3 cubes that let me quickly switch between starting configurations of blocks, in the below code example the arrangement of ‘pillers2’ is being used.
For each object in collection get a scale value for surrounding objects
get_obj_scale(target, objVectors)
Target = string of object name
objVectors = output from object_locations
Generates a list of locationVectors surrounding the target
If these locationVectors are found in objVectors, the keys are added to a temp list
For each name in the temp list, the corresponding object is selected, its scale is recorded and added to a total
The Target : ScaleTotal are then added to a dictionary
Output dict of (objectName : scaleScore) - for single object
object_scale_values(objVectors)
objVectors = output from object_locations
For each key in objVectors, get_object_scale() is used to get the score for this object, the key and scaleScore are then added to a master dictionary
Output dict of (objectName :scaleScore) - for all objects
Based on the scale update the scale of each object in the collection
object_scale_action(objScores)
objScores = output from object_scale_values()
For each objectName/Target in objScores, select the object
Get its current scale
Based on this and its score value, either set its scale to 0 or 1
Output dict of actions, only used for debug, action is already taken in the function.
the object name ‘Cube.364’ passed to the loc_list variable is the central object / cube of the ‘pillers2’ configuration set above, and so is also the centre of the starting location from which the pattern evolves. In the above video and in this code example the centre object for the overall grid was chosen, though this is not a requirement.