Tutorial: Making interactive CPMs in the browser with Artistoo
Artistoo tips
Looping over the cellIDs currently in the model:
// Given a CPM C
for( let cid of C.cellIDs() ){
// do something with this cell
}
Finding current cellID at position:
// Given a CPM C
// array coordinate:
const p = [50,50]
C.pixt(p)
// index coordinate:
const i = C.grid.p2i(p)
C.pixti(i)
Finding the cellKind of cells:
// Given a CPM C
for( let cid of C.cellIDs() ){
console.log( C.cellKind( cid ) )
}
Grid info:
// Given a CPM C
C.grid.extents // field dimensions [x,y]
C.extents // shorthand that also works
C.midpoint // like the name suggests
Access to constraints in the model
// Given a CPM C
C.getConstraint( "ActivityConstraint" )
// this allows you to extract/modify parameters:
C.getConstraint( "ActivityConstraint" ).conf.LAMBDA_ACT
Statistics
// Given a CPM C
C.getStat( CPM.PixelsByCell ) // we need the "CPM." if we are getting it from the library
By default, Artistoo caches statistics during an MCS for efficiency reasons. If you want to make sure a statistic is computed anew:
// Given a CPM C
C.stat_values = {}