Advertisement
Guest User

Untitled

a guest
Jun 6th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.53 KB | None | 0 0
  1. require 'ruby-processing'
  2. require 'open-uri'
  3.  
  4. class ReadLog
  5.   attr_accessor :mx, :my, :left,:top,:width,:height, :articleHeader, :wwidth, :wheight
  6.  
  7.   def initialize(url)
  8.     @url =  url
  9.     @object
  10.     self.update
  11.   end
  12.  
  13.   def update
  14.     @logData = open(@url) {|io| data = io.read}
  15.     @object = JSON.parse(@logData)
  16.     @mx = @object['mx'].to_i.abs
  17.     @my = @object['my'].to_i.abs
  18.     @left = @object['left'].to_i.abs
  19.     @top = @object['top'].to_i.abs
  20.     @width = @object['width'].to_i.abs
  21.     @height = @object['height'].to_i.abs
  22.     @wwidth = @object['wwidth'].to_i.abs
  23.     @wheight = @object['wheight'].to_i.abs
  24.     @articleHeader = @object['articleHeader']
  25.   end
  26. end
  27.  
  28.  
  29. def viewportCalculation(reader, multiplier)
  30.   w = reader.width.to_f
  31.   h = reader.height.to_f
  32.   ww = reader.wwidth.to_f
  33.   wh = reader.wheight.to_f
  34.   t = reader.top.to_f
  35.   l = reader.left.to_f
  36.  
  37.   x = l / w * w
  38.   y = t / h * h
  39.  
  40.   r={}
  41.   r[:w] = w * multiplier
  42.   r[:h] = h * multiplier
  43.  
  44.   r[:ww] = ww * multiplier
  45.   r[:wh] = wh * multiplier
  46.  
  47.   r[:x] = x * multiplier
  48.   r[:y] = y * multiplier
  49.  
  50.   r[:m] = (x + ww/2) * multiplier
  51.   return r
  52. end
  53. $column = PImage.new
  54. $backrop = PImage.new
  55.  
  56. class Debug < Processing::App
  57.   # attr_accessor :column
  58.   load_libraries :json
  59.   def setup
  60.     frame.setResizable(true)
  61.     frame.setTitle("ignore")
  62.  
  63.     @reader = ReadLog.new('http://localhost/_inc/server.php')
  64.     @reader.update
  65.     @ratio = 0.2
  66.  
  67.     backgroundPath = "assets/full_on_level4.jpg"
  68.     @bcg = loadImage(backgroundPath)
  69.     @bcg.loadPixels()
  70.     noFill
  71.     stroke 255,100,120
  72.   end
  73.  
  74.   def draw
  75.     image @bcg,0,0,width,height
  76.     begin
  77.       @reader.update
  78.     @viewport = viewportCalculation(@reader, @ratio);
  79.  
  80.     frame.setSize(@reader.width * @ratio, @reader.height * @ratio)
  81.     frame.setLocation(1364-width,15)
  82.      
  83.     begin
  84.       $column = get @viewport[:m], @viewport[:y], 3,  @viewport[:y]+@viewport[:wh]
  85.     rescue java.lang.NegativeArraySizeException
  86.     end
  87.  
  88.     line @viewport[:m], @viewport[:y], @viewport[:m],  @viewport[:y]+@viewport[:wh]
  89.     rect @viewport[:x], @viewport[:y], @viewport[:ww], @viewport[:wh]  
  90.     rescue NilClass
  91.     end
  92.     sleep 1
  93.   end
  94. end
  95.  
  96. class Sketch < Processing::App
  97.   def setup()
  98.     size 302,203
  99.     noStroke
  100.   end
  101.   def draw()
  102.     frame.setLocation(1364-width,780-height)
  103.     image $column, width-1, 0, $column.width, $column.height
  104.     $backdrop = get 0, 0, width, height
  105.     image $backdrop, -1, 0, width, height
  106.   end
  107. end
  108.  
  109. Debug.new()
  110. Sketch.new()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement