Skip to content

Commit

Permalink
samll
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Apr 9, 2017
1 parent 19089d1 commit 03f822d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion processing_app/library/video/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
###README
### README

You will need to install the video library from processing.org (since it is no longer included in the vanilla processing distro), this is easiest done from the processing ide, see the [Dan Shiffman video][] on video capture.
[Dan Shiffman video]:http://vimeo.com/115436609
Expand Down
68 changes: 68 additions & 0 deletions processing_app/topics/advanced_data/load_save_nokogiri.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
# Loading doc Data
# by Daniel Shiffman.
#
# This example demonstrates how to use loaddoc
# to retrieve data from an doc file and make objects
# from that data.
#
# Here is what the doc looks like:
#
# <?doc version='1.0'?>
# <bubbles>
# <bubble>
# <position x='160' y='103'/>
# <diameter>43.19838</diameter>
# <label>Happy</label>
# </bubble>
# <bubble>
# <position x='372' y='137'/>
# <diameter>52.42526</diameter>
# <label>Sad</label>
# </bubble>
# </bubbles>
#
require 'nokogiri'
load_library 'bubble'

attr_reader :bubbles

def setup
sketch_title 'Load save Nokogiri'
load_data
end

def draw
background(255)
# Display all bubbles
bubbles.each do |b|
b.display
b.rollover(mouse_x, mouse_y)
end
text_align(LEFT)
fill(0)
text('Click to add bubbles.', 10, height - 10)
end

def load_data
# Load doc file
file = File.open(data_path('data.xml'), 'r')
doc = Nokogiri.XML(file)
sketch_title 'Load & Save doc'
# total doc elements named 'bubble'
@bubbles = []
doc.xpath("*[//bubble]").each do |b|
diameter = b.at_xpath("//diameter").content.to_f
label = b.at_xpath("//label").content
position = b.at_xpath("//position")
x = position['x'].value.to_f
y = position['y'].value.to_f
# Make a Bubble object out of the data read
bubbles << Bubble.new(x, y, diameter, label)
end
file.close
end

def settings
size(640, 360)
end

0 comments on commit 03f822d

Please sign in to comment.