Skip to content
Browse files

enhance!

  • Loading branch information...
1 parent 98056e3 commit 6bb4f339815120b56ea5ecb57695321f47d8de2e @mojombo committed Jan 17, 2008
Showing with 53 additions and 13 deletions.
  1. +2 −2 bin/glowstick
  2. +32 −3 bin/graph
  3. +15 −7 lib/glowstick/glowstick.rb
  4. +4 −1 lib/glowstick/graph.rb
View
4 bin/glowstick
@@ -28,13 +28,13 @@ class Memo
end
def idle
- # sleep 0.1
+ sleep 0.1
mem = @process.memory
@graph.add(mem)
true
end
end
-memo = Memo.new(4871)
+memo = Memo.new(29344)
Glowstick.new(memo).start
View
35 bin/graph
@@ -4,8 +4,37 @@ $:.unshift(File.join(File.dirname(__FILE__), *%w[.. lib]))
require 'glowstick'
-graph = Glowstick::Graph.new
+class Handler
+ def draw
+ Glowstick.clear
+
+ graph = Glowstick::Graph.new
+ graph.color = [1, 0, 0]
+ File.read("/Users/tom/mem.5.log").split("\n").each { |x| graph.add(x.to_i) }
+
+ graph = Glowstick::Graph.new
+ graph.color = [0, 1, 0]
+ File.read("/Users/tom/mem.4.log").split("\n").each { |x| graph.add(x.to_i) }
-File.read("/Users/tom/mem.log").split("\n").each { |x| graph.add(x.to_i) }
+ graph = Glowstick::Graph.new
+ graph.color = [0.3, 0.3, 0.3]
+ File.read("/Users/tom/mem.6.log").split("\n").each { |x| graph.add(x.to_i) }
-Glowstick.new(nil).start
+ graph = Glowstick::Graph.new
+ graph.color = [1, 1, 1]
+ File.read("/Users/tom/mem.log").split("\n").each { |x| graph.add(x.to_i) }
+ end
+
+ # callbacks
+
+ def init
+ draw
+ end
+
+ def keyboard(key, x, y)
+ draw
+ true
+ end
+end
+
+Glowstick.new(Handler.new).start
View
22 lib/glowstick/glowstick.rb
@@ -13,6 +13,10 @@ def self.register(graph)
self.graphs << graph
end
+ def self.clear
+ self.graphs.clear
+ end
+
###########################################################################
# Instance
@@ -57,15 +61,17 @@ def reshape(w = @w, h = @h)
end
def keyboard(key, x, y)
- case (key)
- when ?r
- glutPostRedisplay()
+ # case (key)
+ # when ?r
+ # glutPostRedisplay()
+ # end
+ should_draw = @handler.keyboard(key, x, y)
+ if should_draw
+ glutPostRedisplay
end
end
def idle
- return unless @handler.respond_to?(:idle)
-
should_draw = @handler.idle
if should_draw
glutPostRedisplay
@@ -86,10 +92,12 @@ def start
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)
glShadeModel(GL_FLAT)
+ @handler.init if @handler.respond_to?(:init)
+
glutDisplayFunc(self.method(:display).to_proc)
glutReshapeFunc(self.method(:reshape).to_proc)
- glutKeyboardFunc(self.method(:keyboard).to_proc)
- glutIdleFunc(self.method(:idle).to_proc)
+ glutKeyboardFunc(self.method(:keyboard).to_proc) if @handler.respond_to?(:keyboard)
+ glutIdleFunc(self.method(:idle).to_proc) if @handler.respond_to?(:idle)
glutMainLoop()
end
View
5 lib/glowstick/graph.rb
@@ -1,10 +1,11 @@
class Glowstick
class Graph
- attr_accessor :data
+ attr_accessor :data, :color
def initialize
@data = []
+ @color = [1, 1, 1]
@box = Box.new(0, 1, 0, 1)
Glowstick.register(self)
end
@@ -26,6 +27,8 @@ def bounding_box
end
def draw
+ glColor3f(*@color)
+
i = 0
@data.each_cons(2) do |a|

0 comments on commit 6bb4f33

Please sign in to comment.
Something went wrong with that request. Please try again.