Mirroring lists for symmetrical images

I am working on a sketch to generate symmetrical patterns consisting of 4 parts. Right now I am just using random values for testing. The way it works is that I generate an initial list of lists of random values. Each sub-list corresponds to one row in a segment. Then I use the built-in reverse() function and the custom deep_reverse function to generate mirrored lists of the initial list. Here is the code. It’s long but I think it’s necessary to see the whole thing to be clear here:

def settings():
    global total,side,cell
    cell = 100  # size of 1 cell in a segment
    side = 2  # number of cells for one side
    total = side**2  # total number of cells
    sizer = side * cell * 2 # calculate sketch size
def is_list(p): 
    return isinstance(p, list)

def deep_reverse(mylist):
    result = []
    for e in mylist:
        if isinstance(e, list):
    return result

def draw():
    tl,tr,bl,br = [],[],[],[]

    # generate list of values for the first segment, top-left
    val = 0
    for y in range(side):
        inter = []
        for x in range(side):
            rand = int(random(256))
            val = rand
    # draw top-left segment
    for y in range(side):
        for x in range(side):      
    # draw bottom-right segment
    br = deep_reverse(tl)
    for y in range(side):
        for x in range(side):
            rect(x*cell + width/2, y*cell + height/2, cell,cell)
    # draw bottom-left segment
    bl = tl
    for y in range(side):
        for x in range(side):
            rect(x*cell, y*cell + height/2, cell,cell)
    # draw top-right segment
    tr = deep_reverse(bl)
    for y in range(side):
        for x in range(side):
            rect(x*cell + width/2, y*cell, cell,cell)


Here’s an example image with the settings just as in the code posted:

Screenshot (654)
To clarify, I generate the top-left square first, which here consists of 4 cells with random fill() values. Then I derive the remaining squares from the initial one.

This all works fine but I would like to make this more flexible. It’s also a lot of code. Are there more concise ways for doing the same thing? I have a hunch it might be a good idea to separate the actual values from the list initiation process. Meaning that instead of generating 4 lists of fill values, I could just make 1 list of fill values and then iterate over them using a list of indices. For this I would need to generate a list of indices reversed and mirrored like the other ones.

Code for what I mean:

fills =[50,100,150,200] # fill values for the initial pattern
index = [0, 1, 1, 0, 2, 3, 3, 2, 2, 3, 3, 2, 0, 1, 1, 0] # index list for image generation
for i in index:

But I have trouble generating such a list of indices in order to be able to scale it up.
Any insight or different angle on this problem is greatly appreciated. thank you!

This doesn’t really answer your question, but –

Have you considered using Processing’s transformation functions to reflect the top-left corner?

size(200, 200)

def drawTriangle():
    triangle(0, 0, 100, 0, 0, 100)

# top-left triangle

# top-right triangle
translate(width, 0)
scale(-1, 1)

# bottom-right triangle
translate(0, height)
scale(1, -1)

AH thanks! Actually no, I hadn’t. i figured out a solution in the meantime but wasn’t aware of the functions you mentioned. Will be helpful in the future.