#----------------------------------------------------------------------- # Primitive tsxPython sample script # 3D Mandelbrot set # for tS5, tS6 # # $Id: mandel1c.py 37 2019-03-11 19:11:18Z 3DfromNULL $ #----------------------------------------------------------------------- import ptsxpy as p import ptsxgp import math import colorsys from time import * #x0, y0, inwidth_half = -0.52, -0.52, 0.02 #x0, y0, inwidth_half = -0.505, -0.520, 0.02 #x0, y0, inwidth_half = -1.0, -0.0, 0.1 x0, y0, inwidth_half = -0.5, -0.0, 1.2 prec = 100 #prec = 200 outwidth = 5. isz = outwidth / prec #d = inwidth_half / 100 n = 100 ###mate1 = [ 0 ] wk1p = ptsxgp.alloc_long( 1 ) ###p.MaterialCreate( mate1 ) p.MaterialCreate( wk1p ) mate1 = ptsxgp.loadptr( wk1p ) print( "(2) mate1=0x%08x" % mate1 ) # Create black base board col0 = Color( 0, 0, 0, 100 ) ###p.MaterialSetColor( mate1[ 0 ], col0.p ) ###p.MaterialSetActive( mate1[ 0 ] ) print( "(3)" ) p.MaterialSetColor( mate1, col0.p ) print( "(4)" ) p.MaterialSetActive( mate1 ) base1 = p.CreateCube( 1, outwidth, outwidth, 0.01 ) vec1 = Vec3f( outwidth / 2., outwidth / 2., -isz / 2. ) p.GNodeSetLocation( base1, vec1.p ) p.SceneAddObject( base1, e_tsxFALSE ) print( "(1)", ctime(time()) ) quit = 0 ix = 0 for k in range( prec ): iy = 0 x = x0 - inwidth_half + 2 * k * ( inwidth_half / prec ) for j in range( prec ): y = y0 - inwidth_half + 2 * j * ( inwidth_half / prec ) z0 = complex( x, y ) z = z0 for i in range( n ): if p.CheckAbort() == e_tsxTRUE: quit = 1 print( "aborted." ) break z = z * z + z0 if abs( z ) > 2.: rgb1 = colorsys.hsv_to_rgb( i / 100, 1., 1. ) col1 = Color( int( rgb1[ 0 ] * 255 ), int( rgb1[ 1 ] * 255 ), int( rgb1[ 2 ] * 255 ), 100 ) ###p.MaterialSetColor( mate1[ 0 ], col1.p ) ###p.MaterialSetActive( mate1[ 0 ] ) p.MaterialSetColor( mate1, col1.p ) p.MaterialSetActive( mate1 ) h = ( i / n ) * isz * 10. cb1 = p.CreateCube( 1, isz, isz, h ) p.SceneAddObject( cb1, e_tsxFALSE ) vec1 = Vec3f( ix + isz / 2., iy + isz / 2., h / 2. ) p.GNodeSetLocation( cb1, vec1.p ) break if quit: break iy = iy + isz if quit: break #x = x + d ix = ix + isz p.SceneDraw() print( "ended." ) print( "(2)", ctime(time()) )