Skip to content

Commit a9bf2e8

Browse files
committed
net examples
1 parent 02f21dd commit a9bf2e8

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

processing_app/library/dxf/simple_export.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
# Press the 'R' key to export a DXF file.
88
class DXFExport < Propane::App
99
load_library :dxf
10-
include_package 'processing.dxf'
11-
1210
attr_reader :recording
1311

1412
def setup

processing_app/library/net/HTTPClient.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setup
2828

2929
def draw
3030
return unless client.available > 0
31-
data = client.read_string # ...then grab it and print it
31+
@data = client.read_string # ...then grab it and print it
3232
puts data
3333
end
3434

processing_app/library/net/shared_canvas_client.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,22 @@ def draw
3131
# Draw our line
3232
stroke(255)
3333
line(pmouse_x, pmouse_y, mouse_x, mouse_y)
34-
# Send mouse coords to other person
35-
c.write(format("%d %d %d %d\n", pmouse_x, pmouse_y, mouse_x, mouse_y))
34+
# Send mouse coords to other person as spc separated string
35+
c.write(format("%f %f %f %f\n", pmouse_x, pmouse_y, mouse_x, mouse_y))
3636
end
3737
# Receive data from server
3838
return unless c.available > 0
39+
stroke 255, 0, 0
3940
input = c.read_string
40-
# Split values into an array and convert to int
41-
data = input.split(' ').map(&:to_i)
42-
# Draw line using received coords
43-
stroke(0)
44-
line(*data)
41+
# Split input into an array of lines
42+
data = input.split("\n")
43+
data.each do |str|
44+
# Split each line to array of string and convert to array of java float
45+
coords = str.split(' ').map(&:to_f).to_java(:float)
46+
# Draw line using received coords
47+
line(*coords)
48+
end
4549
end
4650
end
51+
4752
SimpleClient.new

processing_app/library/net/shared_canvas_server.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,24 @@ def setup
3131
def draw
3232
if mouse_pressed?
3333
# Draw our line
34-
stroke(255)
34+
stroke 255
3535
line(pmouse_x, pmouse_y, mouse_x, mouse_y)
3636
# Send mouse coords to other person
37-
s.write(format("%d %d %d %d\n", pmouse_x, pmouse_y, mouse_x, mouse_y))
37+
s.write(format("%f %f %f %f\n", pmouse_x, pmouse_y, mouse_x, mouse_y))
3838
end
3939
# Receive data from client
4040
c = s.available
4141
return if c.nil?
42+
stroke 255, 0, 0
4243
input = c.read_string
43-
# Split values into an array and convert to int
44-
data = input.split(' ').map(&:to_f).to_java(:float)
45-
# Draw line using received coords
46-
line(*data)
44+
# Split input into an array of lines
45+
data = input.split("\n")
46+
data.each do |str|
47+
# Split each line to array of string and convert to array of java float
48+
coords = str.split(' ').map(&:to_f).to_java(:float)
49+
# Draw line using received coords
50+
line(*coords)
51+
end
4752
end
4853
end
4954

0 commit comments

Comments
 (0)