Skip to content

Commit e199bad

Browse files
committed
Cleaned up samples 7, 8, and 9 for chapter 18
1 parent feb8569 commit e199bad

File tree

3 files changed

+23
-46
lines changed

3 files changed

+23
-46
lines changed

chapter_18/07_loading_a_url_with_simpleml.rb

+10-14
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ def draw
3131
@timer.start
3232
end
3333

34-
# When a request is finished the data the available
35-
# flag is set to true - and we get a chance to read
36-
# the data returned by the request
34+
# XXX: There are still issues related to events from imported library
35+
# so we call the net_event method ourselves
36+
# When a request is finished the data the available flag is set to true
37+
# and we get a chance to read the data returned by the request
3738
if @request.available?
38-
@html = @request.read_raw_source # Read the raw data
39-
@back = 255 # Reset background
40-
puts "Request completed!" # Print message
39+
net_event(@request)
4140
end
4241

4342
# Draw some lines with colors based on characters from data retrieved
@@ -57,16 +56,13 @@ def draw
5756
@back = constrain(@back - 1, 0, 255)
5857
end
5958

60-
# XXX: There are still issues related to events from imported library
61-
# so we're not implementing this yet.
6259
# When a request is finished the data is received in the netEvent()
6360
# function which is automatically called whenever data is ready.
64-
#def net_event(ml)
65-
# @html = ml.readRawSource # Read the raw data
66-
# @back = 255 # Reset background
67-
# # XXX: was println("Request completed!");
68-
# puts "Request completed!" # Print message
69-
#end
61+
def net_event(ml)
62+
@html = ml.readRawSource # Read the raw data
63+
@back = 255 # Reset background
64+
puts "Request completed!" # Print message
65+
end
7066

7167
#
7268
# Timer Class from Chapter 10

chapter_18/08_loading_xml_with_simpleml.rb

+13-17
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,22 @@ def setup
1515
end
1616

1717
def draw
18-
# When a request is finished the data the available
19-
# flag is set to true - and we get a chance to read
20-
# the data returned by the request
18+
# XXX: There are still issues related to events from imported library
19+
# so we call the net_event method ourselves
20+
# When a request is finished the data the available flag is set to true
21+
# and we get a chance to read the data returned by the request
2122
if @request.available?
22-
# Retrieving an array of all XML elements inside " title* " tags
23-
headlines = @request.get_element_array("title")
24-
# XXX: was println(headlines[i]);
25-
headlines.each {|line| puts line }
26-
no_loop # Nothing to see here
23+
net_event(@request)
24+
no_loop
2725
end
2826
end
2927

30-
# XXX: There are still issues related to events from imported library
31-
# so we're not implementing this yet.
3228
# When a request is finished the data is received in the netEvent()
3329
# function which is automatically called whenever data is ready.
34-
# def net_event(ml)
35-
# # Retrieving an array of all XML elements inside " title* " tags
36-
# headlines = ml.getElementArray("title")
37-
# headlines.each do |headline|
38-
# puts headline # XXX: was println(headlines[i]);
39-
# end
40-
# end
30+
def net_event(ml)
31+
# Retrieving an array of all XML elements inside " title* " tags
32+
headlines = ml.getElementArray("title")
33+
headlines.each do |headline|
34+
puts headline # XXX: was println(headlines[i]);
35+
end
36+
end

chapter_18/09_using_processings_xml_library.rb

-15
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,6 @@ def initialize(r, g, diameter)
5555
@diameter = diameter
5656
end
5757

58-
# XXX: Unused - probably best to remove instead
59-
# True or False if point is inside circle
60-
#def rollover(mx, my)
61-
# return $app.dist(mx, my, @x, @y) < @diameter / 2
62-
#end
63-
64-
65-
# XXX: Unused - probably best to remove instead
66-
# Change Bubble variables
67-
#def change
68-
# @r = $app.constrain(@r + $app.random(-10, 10), 0, 255)
69-
# @g = $app.constrain(@g + $app.random(-10, 10), 0, 255)
70-
# @diameter = $app.constrain(@diameter + $app.random(-2, 4), 4, 72)
71-
#end
72-
7358
# Display Bubble
7459
def display
7560
$app.stroke 0

0 commit comments

Comments
 (0)