All Projects → thomasp85 → Particles

thomasp85 / Particles

Licence: other
A particle simulation engine based on a port of d3-force

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Particles

Force Graph
Force-directed graph rendered on HTML5 canvas
Stars: ✭ 462 (+344.23%)
Mutual labels:  simulation, d3js
Scapy
Scapy: the Python-based interactive packet manipulation program & library. Supports Python 2 & Python 3.
Stars: ✭ 6,932 (+6565.38%)
Mutual labels:  network, network-visualization
React D3 Graph
Interactive and configurable graphs with react and d3 effortlessly
Stars: ✭ 541 (+420.19%)
Mutual labels:  network-visualization, d3js
Gl Water2d
2D liquid simulation in WebGL
Stars: ✭ 260 (+150%)
Mutual labels:  particles, simulation
Sigmajs
Σ sigma.js for R
Stars: ✭ 58 (-44.23%)
Mutual labels:  rstats, network-visualization
Nxviz
Visualization Package for NetworkX
Stars: ✭ 307 (+195.19%)
Mutual labels:  network, network-visualization
Webgl Wind
Wind power visualization with WebGL particles
Stars: ✭ 601 (+477.88%)
Mutual labels:  particles, simulation
Deepgraph
Analyze Data with Pandas-based Networks. Documentation:
Stars: ✭ 232 (+123.08%)
Mutual labels:  network, network-visualization
Chirp
🔬Visualise Twitter Interactions
Stars: ✭ 40 (-61.54%)
Mutual labels:  network, rstats
Phpnetmap
Web application for ethernet network mapping. PHP Software for network device monitoring with SNMP v(1/2c/3) protocol.
Stars: ✭ 20 (-80.77%)
Mutual labels:  network, d3js
orkid
Orkid Media Engine (C++/Lua/Python3/Linux/MacOs/OpenVR/Qt5)
Stars: ✭ 20 (-80.77%)
Mutual labels:  simulation, particles
Grapher
✍️ Large interactive graphs
Stars: ✭ 84 (-19.23%)
Mutual labels:  network, rstats
graph-explorer
Graph Explorer
Stars: ✭ 27 (-74.04%)
Mutual labels:  network-visualization, d3js
Graphpath
Graphpath generates an ASCII network diagram from the route table of a Unix/Linux
Stars: ✭ 321 (+208.65%)
Mutual labels:  network, network-visualization
Toxy
Hackable HTTP proxy for resiliency testing and simulated network conditions
Stars: ✭ 2,698 (+2494.23%)
Mutual labels:  network, simulation
Networkd3
D3 JavaScript Network Graphs from R
Stars: ✭ 562 (+440.38%)
Mutual labels:  rstats, d3js
Workbase
Grakn Workbase (Knowledge IDE)
Stars: ✭ 106 (+1.92%)
Mutual labels:  network, network-visualization
Ns3 Mmwave
ns-3 module for simulating mmWave-based cellular systems. See https://ieeexplore.ieee.org/document/8344116/ (open access) as a reference.
Stars: ✭ 169 (+62.5%)
Mutual labels:  network, simulation
Metta
An information security preparedness tool to do adversarial simulation.
Stars: ✭ 867 (+733.65%)
Mutual labels:  network, simulation
Pynms
A vendor-agnostic NMS for carrier-grade network simulation and automation
Stars: ✭ 73 (-29.81%)
Mutual labels:  network, network-visualization

particles

R build status Codecov test coverage CRAN_Release_Badge CRAN_Download_Badge

This package implements the d3-force algorithm developed by Mike Bostock in R, thus providing a way to run many types of particle simulations using its versatile interface.

While the first goal is to provide feature parity with its JavaScript origin, the intentions is to add more forces, constraints, etc. down the line. While d3-force is most well-known as a layout engine for visualising networks, it is capable of much more. Therefore, particles is provided as a very open framework to play with. Eventually ggraph will provide some shortcut layouts based on particles with the aim of facilitating network visualisation.

Usage

particles builds upon the framework provided by tidygraph and adds a set of verbs that defines the simulation:

  • simulate() : Creates a simulation based on the input graph, global parameters, and a genesis function that sets up the initial conditions of the simulation.
  • wield() : Adds a force to the simulation. All forces implemented in d3-force are available as well as some additionals.
  • impose() : Adds a constraint to the simulation. This function is a departure from d3-force, as d3-force only allowed for simple fixing of x and/or y coordinates through the use of the fx and fy accessors. particles formalises the use of simulation constraints and adds new functionalities.
  • evolve() : Progresses the simulation, either a predefined number of steps, or until the simulated annealing has cooled down.

Example

A recreation of the Les Miserable network in https://bl.ocks.org/mbostock/4062045

library(tidyverse)
library(ggraph)
library(tidygraph)
library(particles)

# Data preparation
d3_col <- c(
  '0' = "#98df8a",
  '1' = "#1f77b4",
  '2' = "#aec7e8",
  '3' = "#ff7f0e",
  '4' = "#ffbb78",
  '5' = "#2ca02c",
  '6' = "#d62728",
  '7' = "#ff9896",
  '8' = "#9467bd",
  '9' = "#c5b0d5",
  '10' =  "#8c564b"
)

raw_data <- 'https://gist.githubusercontent.com/mbostock/4062045/raw/5916d145c8c048a6e3086915a6be464467391c62/miserables.json'
miserable_data <- jsonlite::read_json(raw_data, simplifyVector = TRUE)
miserable_data$nodes$group <- as.factor(miserable_data$nodes$group)
miserable_data$links <- miserable_data$links %>% 
  mutate(from = match(source, miserable_data$nodes$id),
         to = match(target, miserable_data$nodes$id))

# Actual particles part
mis_graph <- miserable_data %>% 
  simulate() %>% 
  wield(link_force) %>% 
  wield(manybody_force) %>% 
  wield(center_force) %>% 
  evolve() %>% 
  as_tbl_graph()

# Plotting with ggraph
ggraph(mis_graph, 'nicely') + 
  geom_edge_link(aes(width = sqrt(value)), colour = '#999999', alpha = 0.6) + 
  geom_node_point(aes(fill = group), shape = 21, colour = 'white', size = 4, 
                  stroke = 1.5) + 
  scale_fill_manual('Group', values = d3_col) + 
  scale_edge_width('Value', range = c(0.5, 3)) + 
  coord_fixed() +
  theme_graph()

If you intend to follow the steps of the simulation it is possible to attach an event handler that gets called ofter each generation of the simulation. If the handler produces a plot the result will be an animation of the simulation:

# Random overlapping circles
graph <- as_tbl_graph(igraph::erdos.renyi.game(100, 0)) %>% 
  mutate(x = runif(100) - 0.5, 
         y = runif(100) - 0.5, 
         radius = runif(100, min = 0.1, 0.2))

# Plotting function
graph_plot <- . %>% {
  gr <- as_tbl_graph(.)
  p <- ggraph(gr, 'manual', node.position = as_tibble(gr)) +
    geom_node_circle(aes(r = radius), fill = 'forestgreen', alpha = 0.5) + 
    coord_fixed(xlim = c(-2.5, 2.5), ylim = c(-2.5, 2.5)) + 
    theme_graph()
  plot(p)
}

# Simulation
graph %>% simulate(velocity_decay = 0.7, setup = predefined_genesis(x, y)) %>% 
  wield(collision_force, radius = radius, n_iter = 2) %>% 
  wield(x_force, x = 0, strength = 0.002) %>% 
  wield(y_force, y = 0, strength = 0.002) %>% 
  evolve(on_generation = graph_plot)

Click here for resulting animation (GitHub don’t allow big gifs in readme)

Installation

You can install particles from CRAN using install.packages("particles") or alternatively install the development version from github with:

# install.packages("devtools")
devtools::install_github("thomasp85/particles")

Immense Thanks

  • A huge “Thank You” to Mike Bostock is in place. Without d3-force, particles wouldn’t exist and without d3 in general the world would be a sadder place.
  • The C++ quad tree implementation that powers manbody_force and collision_force is a modification of the implementation made by Andrei Kashcha and made available under MIT license. Big thanks to Andrei as well.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].