need little help with my python script

Hello everyone.

I want to write a script that would arrange cubes in a way that there would be only one point of view from which this cubes would combine in a picture. And from any other point it wolud seem to be just a cubes mess =)

Here’s what I’ve wrote :

import Blender
import random

scn = Blender.Scene.GetCurrent()
ob_act = scn.objects.active
scn.objects.selected = []
ob_act.sel = 1

img = Blender.Image.GetCurrent()
imgSize = img.size

print 'imageSize : ', imgSize

total = imgSize[0] * imgSize[1]
per = total / 100

print ‘total’, total
print ‘per’, per

for x in range(imgSize[0]):
for y in range(imgSize[1]):
pixel = img.getPixelI(x,y)
if pixel[0] == 0:
Blender.Object.Duplicate(mesh = 1)
ob_act = scn.objects.active
ob_act.setLocation(x2, random.randint(0, imgSize[0]) * 2, y2)

Blender.Redraw()            
print x

But there’s a great problem. If you pick a picture of say 100 to 100 pixels script would be super slow. I assume it slows down because of the number of cubes grows.

Maybe it would be much faster if I just build geometry of single mesh instead of duplicating cube???

Would be greatfull for any help =) Code examples are highly appreciated =)

And here’s a link for what I’ve acctualy already done : www.technocat.ru/script.blend

[SOLVED]

The problem is solved. Adding geometry to a mesh is much faster then duplicating a mesh.

Heres what I wanted =)
http://img-fotki.yandex.ru/get/3208/shirokoff.d/0_26596_860f67df_orig