Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 94 lines (65 sloc) 2.92 kb
12e918f @ashbb Added a new chapter 00610
authored
1 red equal blue???
2 -----------------
3 I'd like to create a tiny Shoes app which picks up the color values around the position mouse clicked. So, I wrote sample71.rb and found the following strange behavior. I'm using Shoes 2 (0.r1134) and Windows XP.
4
5 # sample71.rb
6 Shoes.app :width => 200, :height => 202 do
7 def around x, y, n
8 ret = []
9 return [[x, y]] if n < 1
10 [y - n, y + n].each{|j| ((x - n)..(x + n)).each{|i| ret << [i, j]}}
11 [x - n, x + n].each{|i| ((y - n + 1)..(y + n - 1)).each{|j| ret << [i, j]}}
12 ret
13 end
14
15 img = image :width => 200, :height => 200 do
16 oval 10, 10, 90, :fill => yellow
17 line 0, 60, 80, 60, :stroke => blue, :strokewidth => 10
18 oval 100, 70, 90, :fill => red
19 line 90, 130, 170, 130, :stroke => blue, :strokewidth => 10
20 end
21
22 color = edit_line 'black', :left => 5, :top => 170, :width => 100
23
24 click do
25 b, l, t = self.mouse
26 20.times do |n|
27 around(l, t, n).each do |x, y|
28 oval(x, y, 1, :stroke => green) if img[x, y] == eval(color.text)
29 end
30 oval l, t, 1, :stroke => black
31 end
32 end
33 end
34
35
36 **sample71.png**
37
38 ![sample71.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/sample71.png)
39 Expected behavior. Changed only background (black area) to green.
40
41 **sample71a.png**
42
43 ![sample71a.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/sample71a.png)
44 Expected behavior. Changed only yellow area to green.
45
46 **sample71b.png**
47
48 ![sample71b.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/sample71b.png)
49 Strange behavior. Changed not only red area but also blue area to green.
50
51 **sample71c.png**
52
53 ![sample71c.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/sample71c.png)
54 Expected behavior. Changed only pink area to green.
55
56 **sample71d.png**
57
58 ![sample71d.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/sample71d.png)
59 Strange behavior. Changed blue area to green.
60
61 **sample71e.png**
62
63 ![sample71e.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/sample71e.png)
64 Strange behavior. Changed not only red area but also blue area to green.
65
66 For more specifically. Look at sample71-1.rb
67
68 # sample71-1.rb
69 Shoes.app do
70 stack do
71 para "blue is #{blue.inspect}" if rgb(0, 0, 255) == blue
72 para "red is #{red.inspect}" if rgb(255, 0, 0) == red
73 para "yellow is #{yellow.inspect}" if rgb(255, 255, 0) == yellow
74 para "Umm... red equal blue???" if red == blue
75 para "Umm... blue equal yellow???" if blue == yellow
76 para "Umm... yellow equal red???" if yellow == red
77 end
78 end
79
80
81 **sample71-1.png**
82
83 ![sample71-1.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/sample71-1.png)
84
85 Why `Umm... red equal blue???` is shown?
a354880 @ashbb Confirmed 00533-01000 with Shoes-0.r1263. Finished 99 / 132 samples.
authored
86
87
88 Policeman
89 ---------
90
91 The sample71.rb and sample71-1.rb worked with Shoes-0.r1263. Although the behavior is the same as Raisins.
92
93
Something went wrong with that request. Please try again.