# Changeset 1112

Ignore:
Timestamp:
03/17/21 22:36:57 (3 years ago)
Message:

Added an example of sampling a 3D Model using the ModelGeometry? class

File:
1 edited

Unmodified
Added
Removed
• ## framspy/frams-test.py

 r1103 print(json.loads(serialized_dict._string())) # sampling a Model in 3D geno = "RXX(X,CXXX)" print("\nNow build a Model from the genotype '%s' and sample it in 3D, then print a 2D projection" % geno) import numpy as np matrix = np.zeros((20, 20, 20), dtype=int)  # 3D matrix, "voxels" m = frams.ModelGeometry.forModel(frams.Model.newFromString(geno)); m.geom_density = 20; for p in m.voxels(): # print('%f %f %f ' % (p.x._value(), p.y._value(), p.z._value())) 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 matrix = np.sum(matrix, axis=1)  # sum along axis, make 2D from 3D ("projection") 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 print(matrix) np.set_printoptions()  # avoids straange python errors: frams.py, line 48, in __del__ AttributeError: 'NoneType' object has no attribute 'extFree' # # # Note that implementing a complete expdef, especially a complex one, entirely in python may be inconvenient or impractical # 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.