Created
April 19, 2009 16:58
-
-
Save jashkenas/98128 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: If you've been using VMWare recently, it leaves some network | |
# services dangling. Kill the before you start the sketch: | |
# sudo killall vmnet-netifup | |
load_library 'carnivore' | |
require 'packet_listener' | |
include Java::PacketListener | |
def setup | |
@nodes = {} | |
@start_diameter = 150.0 | |
@min_diameter = 30.0 | |
@shrink_speed = 0.99 | |
smooth | |
size 800, 600 | |
ellipse_mode CENTER | |
@carnivore = org.rsg.carnivore.CarnivoreP5.new(self) | |
end | |
def draw | |
background 255 | |
@nodes.each do |ip, d| | |
# Use last two IP address bytes for x/y coords | |
x = ip.split('.')[2].to_i * width / 255.0 | |
y = ip.split('.')[3].to_i * height / 255.0 | |
stroke 0 | |
fill 100, 100, 100, 200 | |
ellipse x, y, d, d | |
no_stroke | |
fill 100, 100, 100, 50 | |
ellipse x, y, d + 20, d + 20 | |
@nodes[ip] = (d * @shrink_speed) if d > @min_diameter | |
end | |
end | |
def packetEvent(p) | |
@nodes[p.receiverAddress.ip.to_s] = @start_diameter | |
@nodes[p.senderAddress.ip.to_s] = @start_diameter | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment