Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'ruby-processing'
- require 'open-uri'
- class ReadLog
- attr_accessor :mx, :my, :left,:top,:width,:height, :articleHeader, :wwidth, :wheight
- def initialize(url)
- @url = url
- @object
- self.update
- end
- def update
- @logData = open(@url) {|io| data = io.read}
- @object = JSON.parse(@logData)
- @mx = @object['mx'].to_i.abs
- @my = @object['my'].to_i.abs
- @left = @object['left'].to_i.abs
- @top = @object['top'].to_i.abs
- @width = @object['width'].to_i.abs
- @height = @object['height'].to_i.abs
- @wwidth = @object['wwidth'].to_i.abs
- @wheight = @object['wheight'].to_i.abs
- @articleHeader = @object['articleHeader']
- end
- end
- def viewportCalculation(reader, multiplier)
- w = reader.width.to_f
- h = reader.height.to_f
- ww = reader.wwidth.to_f
- wh = reader.wheight.to_f
- t = reader.top.to_f
- l = reader.left.to_f
- x = l / w * w
- y = t / h * h
- r={}
- r[:w] = w * multiplier
- r[:h] = h * multiplier
- r[:ww] = ww * multiplier
- r[:wh] = wh * multiplier
- r[:x] = x * multiplier
- r[:y] = y * multiplier
- r[:m] = (x + ww/2) * multiplier
- return r
- end
- $column = PImage.new
- $backrop = PImage.new
- class Debug < Processing::App
- # attr_accessor :column
- load_libraries :json
- def setup
- frame.setResizable(true)
- frame.setTitle("ignore")
- @reader = ReadLog.new('http://localhost/_inc/server.php')
- @reader.update
- @ratio = 0.2
- backgroundPath = "assets/full_on_level4.jpg"
- @bcg = loadImage(backgroundPath)
- @bcg.loadPixels()
- noFill
- stroke 255,100,120
- end
- def draw
- image @bcg,0,0,width,height
- begin
- @reader.update
- @viewport = viewportCalculation(@reader, @ratio);
- frame.setSize(@reader.width * @ratio, @reader.height * @ratio)
- frame.setLocation(1364-width,15)
- begin
- $column = get @viewport[:m], @viewport[:y], 3, @viewport[:y]+@viewport[:wh]
- rescue java.lang.NegativeArraySizeException
- end
- line @viewport[:m], @viewport[:y], @viewport[:m], @viewport[:y]+@viewport[:wh]
- rect @viewport[:x], @viewport[:y], @viewport[:ww], @viewport[:wh]
- rescue NilClass
- end
- sleep 1
- end
- end
- class Sketch < Processing::App
- def setup()
- size 302,203
- noStroke
- end
- def draw()
- frame.setLocation(1364-width,780-height)
- image $column, width-1, 0, $column.width, $column.height
- $backdrop = get 0, 0, width, height
- image $backdrop, -1, 0, width, height
- end
- end
- Debug.new()
- Sketch.new()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement