Friday, 6 January 2012

3d extrusion from 2d silhouette V2

I was trying out my script on a logo for a friend and it failed!

The logo was just text characters in a fancy font but contained the letter n, the script when working out the y size on the box only checked the left and right hand side of the box to see if it was still within the silhouette, thus it turned the n into a solid cube.

I had been planning an updated version already as I knew it wouldn't handle an enclosed hole in the silhouette, this is the same issue.

Here is the new code, still alpha, still has the exponent colour bug.

-------------start of code ------------

import Image, random
def findbox (x,y):
    xlen = 0;
    ylen = 0;
    holeflag = 0;
#    print '(x,y) = '+str(x)+' '+ str(y)
#    print 'current (x,y) '+ str(pix[x,y])
#    print 'current (x+1,y) '+ str(pix[x+1,y])
    while (pix[x+xlen+1,y] != 0):
        xlen = xlen + 1
#        print 'xlen = ['+str(xlen)+']'
#        print 'current (x+xlen+1) '+ str(pix[x+xlen+1,y]);
        if x+xlen+2 >= im.size[0]:

#    print 'start y current (x,y) '+ str(pix[x,y])
#    print 'current (x+xlen,y+ylen+1) '+ str(pix[x+xlen,y+ylen+1])
    while (pix[x+xlen,y+ylen+1] != 0 and pix[x,y+ylen+1] != 0):
        ylen = ylen + 1

        for t in range(x,x+xlen):
            if (pix[t,y+ylen] == 0):
                ylen = ylen -1
                holeflag = 1;

#        print 'ylen = ['+str(ylen)+']'
#        print 'current (y+ylen+1) '+ str(pix[x+xlen,y+ylen+1]);

#        if (y+ylen)%((xlen+1)) == 0 :
#            break
        if holeflag == 1:
        if y+ylen+2 >= im.size[1]:

    print 'color(['+str(random.random())+','+str(random.random())+','+str(random.random())+']) translate(['+str(x)+','+str(y)+',0]) cube(['+str(xlen+1+0.
0001)+','+str(ylen+1+0.0001)+',2.5],center =false);'
#    print 'translate(['+str(x)+','+str(y)+',0]) cube(['+str(xlen+1+0.0001)+','+str(ylen+1+0.0001)+',10],center =false);'

im ="logo.bmp")
pix = im.load()
#print pix[0,0]
#print im.size

for y in xrange(im.size[1]-1):
    for x in xrange(im.size[0]-1):
        #print pix[x,y]
        if pix[x,y] != 0:
            findbox (x,y)

-----------------end of code-----------------

 I wish there was a way to add attachments to this blog...

No comments:

Post a Comment