Showing posts with label #python #povray #pysanky. Show all posts
Showing posts with label #python #povray #pysanky. Show all posts

Saturday, February 5, 2011

More POV-ray and Pysanky

Continuing with the series of pysanky eggs I've been working on with Python and POV-ray - another week, another egg.  This one is a Lemko design.  The dots, I believe, represent stars.

Getting the crown and base was relatively easy, as it just required the correct positioning of a single stroke, then rotating it:

def makecrown(baseobj):
    crownstrokes = [baseobj]
    theta = STEP
    while theta < 360.0:
        crownstrokes.append(pov.Object(baseobj,
                            rotate = (0.0, theta, 0.0)))
        theta += STEP
    return pov.Union(*crownstrokes)

In this case, step = 360.0/24.0.

Likewise, I have a function for the dots that made them easier to place:

def movedot(basedot, xtheta, ytheta):
    dot = pov.Object(basedot, rotate = (xtheta, ytheta, 0.0))
    return pov.Object(dot, translate = (0.0, 1.0, 0.0))

Ultimately, I'd like to get enough egg designs coded to put together some sort of scene in POV-ray dedicated to the eggs.  The following two scenes show what I have so far:

If I can identify a few more attractive, computationally friendly designs, I should be able to come up with enough eggs for a decent POV-ray egg scene.  In the meantime, thanks for having a look.

Tuesday, December 21, 2010

Coding POV-ray in Python

My past two posts were basically on the same topic as this one.  The difference now is that I was able to write Python code as I would normally write it with functions, dictionaries, and loops and still come out with valid POV-ray code on the other end.  It's about a third of the length of the equivalent POV-ray code and, for me at least, easier to understand and read.

Here is the last part of the code that resulted in the scene of the three eggs below:

file = pov.File('test4.pov', 'colors.inc')
cam = pov.Camera(location = (-2, 3, -12), look_at = (0, 0, 2))
sorokolines = makesorokolines()testblock = makeredwedges()
testblockred = pov.Object(testblock, RED)
testblock = makeblackwedges()
testblockblack = pov.Object(testblock, BLACK)
test = pov.Union(testblockred, testblockblack, sorokolines)
test1 = pov.Object(test, translate = (2, 2, 0))
test2 = pov.Object(test, translate = (-2, -2, 0))
test3 = pov.Object(test, translate = (-6, 2, 0))
file.write(cam, test1, test2, test3, light1, light2, light3, light4, light5)

Now that I've proven to myself that I can code this in Python, I'd like to try something more involved like putting the eggs on a surface with a texture.

Thanks for having a look.