/*Firefly behavior simulated based on 'Firefly-Inspired Sensor Network Synchronicity with Realistic Radio Effects ' Werner-Allen, et. al. and 'Synchronization of pulse-coupledbiological oscillators' R. Mirollo and S. Strogatz. by Kawandeep Virdee */ //its using this object that allows me to set the alpha for the bckgrnd PGraphics pg; float detection_radius = 70; float diameter = 10; //a list of objects that will contain the fireflies ArrayList fireflies; int number_fireflies = 200; //each firefly increments by this automatically float time_step = 1.0; //the threshold to produce a flash float period =100; //if you change the period you will want to change epsilon, since //epsilon affects how much the flash of a neighbor contributes //towards reaching the threshold>> check convergence condition //when there is a flash of a nearby firefly //epsilon * t gives delta t in the simple increment equation float epsilon = .1; //initialize the environment void setup(){ //canvas size size(500,500); //initialize list of objects fireflies = new ArrayList(); //add fireflies with random positions for(int i=0; i period){ f.draw(); //set time to zero // f.time_memory=0; f.time=0; f.flash = true; } else{ f.time +=1; f.flash = false; //check for neighbor flashing f.neighborsFlash(detection_radius); //increment if neighbor flashes f.time +=f.time_memory; f.time_memory=0; } } pg.endDraw(); image(pg, 0, 0); } //function that will make the canvas a torus, so we wrap around the the borders void wrap() { for(int i=0;i width) f.position.x -= width; if(f.position.y < 0) f.position.y += height; else if(f.position.y > height) f.position.y -= height; } } //firefly class class Firefly { PVector position; PVector velocity; float time; //current time level of the firefly float time_memory=0; //this will hold the delta t value float delta_t; //the change in t when a neighbor flashes boolean flash = false; //constructor Firefly(PVector _position, PVector _velocity, float _time){ position = _position; velocity = _velocity; time = _time; } //check the neighbors ArrayList neighbors(float detection_radius){ ArrayList neighbors = new ArrayList(); for(int i = 0; i