Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit b5bc0042971e6df91163f9bf3f521cd27a28e30d @mojombo committed Jan 16, 2008
Showing with 226 additions and 0 deletions.
  1. +5 −0 History.txt
  2. +7 −0 Manifest.txt
  3. +48 −0 README.txt
  4. +17 −0 Rakefile
  5. 0 bin/glowstick
  6. +142 −0 lib/glowstick.rb
  7. +7 −0 lib/glowstick/graph.rb
  8. 0 test/test_glowstick.rb
@@ -0,0 +1,5 @@
+== 1.0.0 / 2008-01-16
+
+* 1 major enhancement
+ * Birthday!
+
@@ -0,0 +1,7 @@
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+bin/glowstick
+lib/glowstick.rb
+test/test_glowstick.rb
@@ -0,0 +1,48 @@
+glowstick
+ by FIX (your name)
+ FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2008 FIX
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+require './lib/glowstick.rb'
+
+Hoe.new('glowstick', Glowstick::VERSION) do |p|
+ p.rubyforge_name = 'glowstick'
+ # p.author = 'FIX'
+ # p.email = 'FIX'
+ # p.summary = 'FIX'
+ # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
+ # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
+end
+
+# vim: syntax=Ruby
No changes.
@@ -0,0 +1,142 @@
+require 'rubygems'
+require 'opengl'
+# require 'mathn'
+require 'enumerator'
+include Gl, Glu, Glut
+
+class Box
+ attr_accessor :l, :r, :b, :t
+
+ def initialize(l, r, b, t)
+ @l = l
+ @r = r
+ @b = b
+ @t = t
+ end
+
+ def inset_percent(p)
+ @l -= (r - l) * (p / 100.0)
+ @r += (r - l) * (p / 100.0)
+ @b -= (t - b) * (p / 100.0)
+ @t += (t - b) * (p / 100.0)
+ end
+end
+
+module Glowstick
+ VERSION = '1.0.0'
+
+ def self.start
+ @window = Box.new(0, 500, 0, 20000)
+
+ @w = 800
+ @h = 400
+
+ read
+ calculate_domain_and_range
+ main
+ end
+
+ def self.init
+ glClearColor(0.0, 0.0, 0.0, 0.0)
+
+ glEnable(GL_LINE_SMOOTH)
+ glEnable(GL_BLEND)
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+ glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)
+
+ glShadeModel(GL_FLAT)
+ end
+
+ def self.read
+ @data = File.read(ARGV[0]).split("\n").map { |x| x.to_i }
+ puts @data.size
+
+ temp = []
+ @data.each_with_index do |x, i|
+ temp << x if i % 15 == 0
+ end
+ @data = temp
+ end
+
+ def self.calculate_domain_and_range
+ a = @data.sort
+
+ @window.b = a.first
+ @window.t = a.last
+ @window.l = 0
+ @window.r = a.size
+
+ @window.inset_percent(10)
+ end
+
+ def self.plot
+ i = 0
+
+ @data.each_cons(2) do |a|
+ line(i, a[0], i + 1, a[1])
+ i += 1
+ end
+ end
+
+ def self.display
+ glClear(GL_COLOR_BUFFER_BIT)
+
+ plot
+
+ print("Hello Stroke", 2, 0, 10)
+
+ glutSwapBuffers()
+ end
+
+ def self.print(text, size, x, y)
+ view_size = (@window.r - @window.l).to_f
+ window_size = @w.to_f
+ xscale = 8 / (window_size / view_size) * (size / 100.0)
+
+ GL.Translate(@window.l, @window.b + 100, 0)
+ GL.Scale(xscale, 2, 1)
+ text.each_byte { |x| glutStrokeCharacter(GLUT_STROKE_ROMAN, x) }
+ end
+
+ def self.reshape(w = @w, h = @h)
+ @w = w
+ @h = h
+
+ glViewport(0, 0, w, h)
+ glMatrixMode(GL_PROJECTION)
+ glLoadIdentity()
+ GLU.Ortho2D(@window.l, @window.r, @window.b, @window.t)
+ end
+
+ def self.keyboard(key, x, y)
+ case (key)
+ when ?l
+ nil
+ when ?r
+ glutPostRedisplay()
+ end
+ end
+
+ def self.main
+ glutInit
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)
+ glutInitWindowSize(@w, @h)
+ glutInitWindowPosition(100, 100)
+ glutCreateWindow("Glowstick")
+ init()
+ glutDisplayFunc(self.method(:display).to_proc)
+ glutReshapeFunc(self.method(:reshape).to_proc)
+ glutKeyboardFunc(self.method(:keyboard).to_proc)
+ glutMainLoop()
+ end
+
+ def self.line(x1, y1, x2, y2)
+ glBegin(GL_LINES)
+ glVertex((x1),(y1))
+ glVertex((x2),(y2))
+ glEnd()
+ end
+end
+
+ARGV[0] = "/Users/tom/memlog2.log"
+Glowstick.start
@@ -0,0 +1,7 @@
+module Glowstick
+
+ class Graph
+
+ end # Graph
+
+end # Glowstick
No changes.

0 comments on commit b5bc004

Please sign in to comment.