How can I apply color to certain regions of a plane with a python script? Is there a tutorial on how to apply textures and materials to an object through python?
For example, say I wanted to set everything inside two parabolas in the x-y plane to blue. the plane will be 1000 x 1000 units long.
for i in range(1000):
for j in range(1000):
y1 = (i - 500)**2/(-100) + 800 #parabola 1
y2 = (i - 500)**2/(-150) + 999 #parabola 2
if (j < y1 and j > y2) or (j > y1 and j < y2): #if [i][j] is inside the two parabolas
##this is where I would want the command to paint a 1x1 square at [i][j] blue
##this is where i wouldn’t want anything painted
I don’t think you can paint partial faces this way unless you use a texture. (Not sure if the UV Paint functionality is accessible through Python)
You seem to have the maths down though, so what you might be able to do is (and you’re going to hate me for this):
Start with a well subdivided plane. (I’m going to call this a “Grid” otherwise I’ll get ambiguous in the next sentence)
Work out the path of your parabola and have python subdivide the segments of the Grid at the points where they intersect. Then you’ll be able to construct separate faces and assign different materials to them.
Through Python? Not sure (My Python’s not up to scratch, just my Blending!)
If you can pin down the co-ordinates of the verteces closest to the parabola line, (ie: solve for x= and round up!) you should be able to see which faces each vertex is associated with and assign them to a new material index.
I’ll try to explain what I think it means, and then could someone tell me what it actually means?
me = Mesh.Get(‘some mesh’)
for f in me.faces:
for col in f.col:
col.r = 255
col.g = 128
col.b = 0
Line 1, creates a new mesh object named ‘some mesh’
line 2, starts a for loop beginning at f = 0 and ending at
f = (# of faces in the mesh)
line 3, starts another loop beginning at col = 0 and ending at col = (I’m not sure what f.col means, please explain)
lines 4-6 are just setting the red green and blue values, but is col a variable or does it actually make the face adopt that certain color value?
from Blender import *
scn = Scene.GetCurrent() # blender can have multiple scenes, we only care about the current one.
ob = scn.objects.active # the active object (last selected)
me = ob.getData(mesh=1) # the objects mesh data- assuming teh object is mesh
for f in me.faces: # go through each face
for col in f.col:
col.r, col.g, col.b = 255,255,255 # set the rgb for the corner of the face