color change by rotation

hopefully this is in the correct place, but i have made a script in bge that changes the color of an object dependent on its rotation. the is script is as follows;

import bgefrom math import radians


def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner
    actu = cont.actuators['Motion']
    
    if not "rot" in own:
		own.color = [0.0,0.0,0.0,1]
        own["rot"] = 0
    
    scene = bge.logic.getCurrentScene()
    target = scene.objects["Cube"]
    dist = ( own.getDistanceTo(target) )
    
    rot_amount = 3
    
    if dist<0.4:
        if own["rot"] < 180:
            own["rot"] += rot_amount
            own.applyRotation([0,radians(rot_amount),0], 1)
            own.color[0] = 0.0
            own.color[1] = own["rot"]/180.0
            own.color[2] = own["rot"]/180.0
    else:
        if own["rot"] > 0:
            own["rot"] -= rot_amount
            own.applyRotation([0,radians(-rot_amount),0], 1)
            own.color[0] = 0.0
            own.color[1] = own["rot"]/180.0
            own.color[2] = own["rot"]/180.0
main()

this script rotates a tile when a cubes comes close to it and also changes the color from black to blue. the rotation is limited to 180 and rotates back when the cube moves out the the distance and the color will also go back to being black.
my problem now is that i want this to work in the render. i have saved the rotation animation as key frames but the color change does not save aswell.
is there a way to link the rotational value of the tile to its color value or save out the color changing itself.
the file i am using has over 300 ‘tiles’ in it and i would like not to have to hand animate the color changes for each manualy

*** Moderation ***
moved from: Materials and Textures
reason: belongs to Blender Python coding