From 03f822de80318fa2b872c5309d52cca50eae58a1 Mon Sep 17 00:00:00 2001 From: monkstone Date: Sun, 9 Apr 2017 16:26:46 +0100 Subject: [PATCH] samll --- processing_app/library/video/README.md | 2 +- .../advanced_data/load_save_nokogiri.rb | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 processing_app/topics/advanced_data/load_save_nokogiri.rb diff --git a/processing_app/library/video/README.md b/processing_app/library/video/README.md index d8c2fb4..4c0c827 100644 --- a/processing_app/library/video/README.md +++ b/processing_app/library/video/README.md @@ -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 diff --git a/processing_app/topics/advanced_data/load_save_nokogiri.rb b/processing_app/topics/advanced_data/load_save_nokogiri.rb new file mode 100644 index 0000000..135e26d --- /dev/null +++ b/processing_app/topics/advanced_data/load_save_nokogiri.rb @@ -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: +# +# +# +# +# +# 43.19838 +# +# +# +# +# 52.42526 +# +# +# +# +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