PDA

View Full Version : Mandelbrot / custom rendering?


surreal-reality
10-12-2010, 12:11 AM
I'm not entirely sure what to call what it is I want to do, so I hope custom rendering wasn't misleading by any stretch.

Basically, I have a python script that plots points of the Mandelbrot set and creates particles in those respective places. This gets slow, and to get a decent sampling rate would be inefficient. I was wondering is there a way to render something like this straight to the render window, or maybe to a file using maya's paint functions?
This has no real practical purpose atm, it's mostly for practice / fun, but I'm stumped at this last issue.

Any ideas anyone?

Thanks in advance

ndeboar
10-12-2010, 02:58 AM
if you want to be a massive nerd about it (in a good way)

Check our renderman. You can write proceduals that generate rib at rendertime. Sure you can do the same for other renderers, that's my only reference point.

surreal-reality
10-12-2010, 03:02 AM
Thanks for the idea ndeboar, I was really hoping to achieve this with maya software, mr, or something of the sort. I will definitely check that out though too.

Thanks!

surreal-reality
10-12-2010, 07:37 PM
I'm having some luck finding a direction to go in, but currently I'm still as equally stumped as to how to do this with scripting.

If one hits the 8 key ,and goes into paint effects paint mode there's a mode under brush called single pixel paint.
This is exactly what I would want maya to do, but I can only seem to do this by hand. The script editor with echo all yields nothing, and as of now I'm not even sure what to search for.

Any ideas!!?

I'll post back here if I figure anything out, thanks again.

surreal-reality
11-05-2010, 02:33 AM
So it's been a while since I've updated this thread, but I managed to get this going via particle emission, and now giving faces a value. each face essentially "pixel" while it works, and technically I could have as many subdivisions as needed, It's still super slow. : /

just paste and run. sets everything u need up:


import maya.cmds as cmds
import maya.mel as mel
import math as math

mel.eval("DisplayShaded;")

geoRes = 100 #currently must be square, ex. 10x10, and must be an even number
if cmds.objExists('mandelPlane'):
pass
else:
cmds.polyPlane(n = 'mandelPlane', w = 24, h = 24, sx = geoRes, sy = geoRes, o = 1, ch = 0)
cmds.select(cl = 1)
#the almighty zee variable.
zee = 0

###---Edit xmin, xmax, ymin, ymax, pixelStep, and maxIter.---###
#min and max ranges to itterate throughq

xMin = -2
xMax = 2
yMin = -2
yMax = 2

#"Resolution" of sorts
pixelStep = .2
geoPixelStep = float((xMax - xMin)) / float(geoRes)
#how many times the tarjectory each "pixel" is iterated
maxIter = 25
iterCount = 0

#current coordinates being plugged into the equation
xCur = xMin
yCur = yMin

#colors each pixels trjectory either black, or white.
boolColor = -.05

#elevates the black particles a bit for easier viewing.
height = 0.01

# A bunch of variables used to create the mel string that emits particles into the particleShape.
# Could not use python here because cmds.emit crashes maya anytime more than position is used. : /

polyPlaneName = "mandelPlane"
frontAppend = "%s.f[" % (polyPlaneName)
backAppend = "]"
faceCoordToAppend = [0,0]
evalStr = ""
shortList = []
faceList = []
openingStr = "emit -object cool "
endingStr = "-attribute rgbPP -floatValue "
numberChunkStr = ""
closingStr = str(boolColor)
evalStr = ""

#converts our current coordinates being computed into a complex number
complexStr = complex(xCur, yCur)
print complexStr

#Loop through X first
while(xCur <= xMax):
yCur = yMin
cmds.refresh()
#loop through Y within X
while(yCur <= yMax):
#Do mandel Iterations on this level
complexStr = complex(xCur, yCur)
iterCount = 0
zee = 0
boolColor = -.05
height = 0.01
shortList = []
faceList = []
numberChunkStr = ""
evalStr = ""
while(iterCount < maxIter):
#the actual mandelbrot equation. Usually written as z = z^2 + c
zee = (zee * zee) + complexStr
#keeping it within the above specified ranges.
#If the trajectory goes outside of the "box" all the points belonging to that trjectory, or to that pixel
#are colored white. The ones that never make it out alive are black. Later, coloring it involves
# controlling rgb by how many iterations it takes the escapees to get out.
if(zee.real < xMax and zee.imag < xMax and zee.real > xMin and zee.imag > xMin):
faceCoordToAppend = [int(zee.real / geoPixelStep) + (int(geoRes / 2)), int(zee.imag / geoPixelStep) + (int(geoRes / 2))]
#print faceCoordToAppend
shortList.append(faceCoordToAppend)
iterCount = iterCount + 1
else:
boolColor = .05
height = 0.00
iterCount = maxIter
#print shortList
closingStr = str(boolColor)
#building the mel string, then executing it, creating one full trajectory, how ever long it is.
for item in shortList:
faceList.append(frontAppend + str((geoRes * item[1] + item[0]) - 1) + backAppend)
# numberChunkStr = numberChunkStr + "-position "
# numberChunkStr = numberChunkStr + str(item[0]) + " " + str(height) +" " + str(item[2]) + " "
#evalStr = openingStr + numberChunkStr + endingStr + closingStr + ";"
#mel.eval(evalStr)
#print faceList
if (len(faceList) > 0):
cmds.polyColorPerVertex(faceList, cla = 1, cdo = 1, nun = 1, rel = 1, r=boolColor,g=boolColor,b=boolColor)
cmds.flushUndo()
yCur = yCur + geoPixelStep
xCur = xCur + geoPixelStep

print "finished!"
#cmds.polyColorPerVertex('pPlane1.f[3]', r=0,g=0,b=0)

CGTalk Moderation
11-05-2010, 02:33 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.