Comments (3)
workaround: when the model is server side, use https://github.com/lukeapage/pngjs to load the PNG as data and copy the data to the terrain in the terrain init
var fs = require('fs'),
PNG = require('pngjs').PNG;
then the main. call back is necessary as the png io needs to finish before initializing the model
// Loads map resource from object in serial event async nodejs style
fs.createReadStream(model_params.map)
.pipe(new PNG({filterType: 4}))
.on("parsed", function () {
//save the terrain image data into globalThis scope
globalThis.terrainImage = this;
// now start the simulation
model.setup();
run();
});
then in the setup
// load the terrain image to the Terrain object
// works differently for browser vs nodejs
if(globalThis.isBrowser) {
modelStuff.terrain.load(model_params.map);
} else {
modelStuff.terrain.init((x,y) => {
var idx = ((width * y) + x) << 2;
var rv = globalThis.terrainImage.data[idx];
var gv = globalThis.terrainImage.data[idx + 1];
var bv = globalThis.terrainImage.data[idx + 2];
modelStuff.terrain.set(x,y,{r:rv,g:gv,b:bv,a:255});
});
}
from flocc.
Hi @derickson pardon my slow reply. While Flocc does attempt to be equally useful in both server and browser contexts, the visualization components really are more browser-focused. It seems like your workaround using pngjs
works nicely! One goal of Flocc is to be dependency-free, so I'd want to do a little more work on the Node side to remove that as a dependency, but it seems like that approach would work well.
from flocc.
no worries on slow reply, just trying to be a good open source community member. we are in the middle our our hackathon powered by flocc right now. really appreciate you making this project available.
from flocc.
Related Issues (17)
- Array methods, lambdas for rules HOT 1
- Cannot change color of agents HOT 5
- Histogram improvements HOT 1
- Difficulty in visualizing a simple basic netowork HOT 3
- Histogram buckets for discrete values HOT 1
- 0.3.14 ideas HOT 1
- CanvasRenderer + Network connection drawing issue HOT 1
- TypeScript improvements HOT 1
- KDTree bug HOT 1
- Network should safely handle `.neighbors(agent)` call when `agent` is not in network HOT 1
- Fix JSDoc declaration for `Terrain.neighbors` HOT 1
- Let's have Networks and Terrains automatically sync with all Agents in their Environment
- Histogram: Multiple Metrics HOT 1
- Heatmaps! HOT 1
- Calling environment.set(data) when subclassing doesn't set data
- developping locally HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flocc.