- Timestamp:
- 03/17/21 22:36:57 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/frams-test.py
r1103 r1112 100 100 print(json.loads(serialized_dict._string())) 101 101 102 # sampling a Model in 3D 103 geno = "RXX(X,CXXX)" 104 print("\nNow build a Model from the genotype '%s' and sample it in 3D, then print a 2D projection" % geno) 105 import numpy as np 106 107 matrix = np.zeros((20, 20, 20), dtype=int) # 3D matrix, "voxels" 108 m = frams.ModelGeometry.forModel(frams.Model.newFromString(geno)); 109 m.geom_density = 20; 110 for p in m.voxels(): 111 # print('%f %f %f ' % (p.x._value(), p.y._value(), p.z._value())) 112 matrix[int(p.x._value() * 5 + 2), int(p.y._value() * 5 + 5), int(p.z._value() * 5 + 6)] += 1 # scaling and offsets adjusted manually to fit the matrix nicely 113 matrix = np.sum(matrix, axis=1) # sum along axis, make 2D from 3D ("projection") 114 np.set_printoptions(formatter={'int': lambda x: ('.' if x == 0 else str(x // 18))}) # print zeros as dots, x//18 to fit a larger range into a single digit 115 print(matrix) 116 np.set_printoptions() # avoids straange python errors: frams.py, line 48, in __del__ AttributeError: 'NoneType' object has no attribute 'extFree' 117 118 # 119 # 102 120 # Note that implementing a complete expdef, especially a complex one, entirely in python may be inconvenient or impractical 103 121 # because you do not have access to "event handlers" like you have in FramScript - onStep(), onBorn(), onDied(), onCollision() etc.,
Note: See TracChangeset
for help on using the changeset viewer.