Permalink
Browse files

Added Gallery 13: Mandelbrot Set

  • Loading branch information...
1 parent 7667bbb commit 1d74ec8f9c5112f8169bfd374e8fcaf9f2c9fd47 @ashbb ashbb committed Jul 11, 2009
View
@@ -2,7 +2,7 @@ Shoes Tutorial Note
===================
**- For the Shoes App Rookie Creators -**
-July 2nd, 2009 by ashbb (Satoshi Asakawa), citizen428 (Michael Kohl), kotp (Victor H. Goff III)
+July 12th, 2009 by ashbb (Satoshi Asakawa), citizen428 (Michael Kohl), kotp (Victor H. Goff III)
Table of contents
-----------------
@@ -87,7 +87,7 @@ Table of contents
11. Fancy Gallery
- [01110 Fancy Gallery 1-5 (gallery1.rb, gallery1-1.rb, gallery2.rb, gallery2-1.rb, gallery3.rb, gallery4.rb, gallery4-1.rb, gallery5.rb)](http://github.com/ashbb/shoes_tutorial_html/tree/master/mdowns/01110_Fancy_Gallery_1-5.mdown)
- [01120 Fancy Gallery 6-10 (gallery6.rb, gallery7.rb, gallery8.rb, gallery9.rb, gallery10.rb, gallery10-rules.rb, gallery10-image.rb)](http://github.com/ashbb/shoes_tutorial_html/tree/master/mdowns/01120_Fancy_Gallery_6-10.mdown)
- - [01130 Fancy Gallery 11-15 (gallery11.rb, gallery12.rb, gallery12-flickr.rb)](http://github.com/ashbb/shoes_tutorial_html/tree/master/mdowns/01130_Fancy_Gallery_11-15.mdown)
+ - [01130 Fancy Gallery 11-15 (gallery11.rb, gallery12.rb, gallery12-flickr.rb, gallery13.rb)](http://github.com/ashbb/shoes_tutorial_html/tree/master/mdowns/01130_Fancy_Gallery_11-15.mdown)
12. Built-in Samples
- [01201 simple-accordion (simple-accordion.rb)](http://github.com/ashbb/shoes_tutorial_html/tree/master/mdowns/01201_simple-accordion.mdown)
View
@@ -1,5 +1,6 @@
Change log:
-----------
+Jul 12th, 2009: Added gallery 13.
Jul 02nd, 2009: Added gallery 12.
Jun 28th, 2009: Added a Paul's tip for gallery 11.
Jun 27th, 2009: Added a new chapter 001130 and gallery 11.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -192,6 +192,58 @@ You can replace `********` to search words like this: `dog+cat`.
![gallery12.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/gallery12.png)
+<br>
+
+Gallery No.13
+-------------
+
+[Mandelbrot Set](http://en.wikipedia.org/wiki/Mandelbrot_set)
+
+What a mysterious pattern! Impossible drawing by hand.
+
+**Note**: the following snippet is so heavy to run. Need big power of cpu.
+
+ # gallery13.rb
+ # Mandelbrot Set No.007
+
+ Shoes.app :width => 300, :height => 302, :title => 'Mandelbrot v0.1' do
+ MAX, W, H = 200, 300, 300
+ x0, y0, w = 1.768606, -0.002229, 0.0000014
+ a0, a1 = x0 - w, x0 + w
+ b0, b1 = y0 - w, y0 + w
+
+ def mandelbrot a, b
+ x, y = 0.0, 0.0
+ MAX.times do |i|
+ x, y = x * x - y * y - a, 2.0 * x * y - b
+ return [x, y, i] if (x * x + y * y) > 4.0
+ end
+ [x, y, false]
+ end
+
+ nostroke
+ image :width => W, :height => H do
+ H.times do |j|
+ W.times do |i|
+ a, b = a0 + i * (a1 - a0) / W, b0 + j * (b1 - b0) / H
+ x, y, diverged = mandelbrot(a, b)
+ #oval(i, j, 1) unless diverged
+ color = diverged ? rgb(255 - diverged, x.abs, y.abs) : black
+ oval i, j, 1, :fill => color
+ end
+ end
+ end
+ end
+
+**gallery13.png**
+![gallery13.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/gallery13.png)
+<br>
+
+References
+----------
+- [Mandelbrot on COCOA](http://hp.vector.co.jp/authors/VA026611/index_mac_e.html)
+- [Mandelbrot on Windows](http://hp.vector.co.jp/authors/VA026611/index_win_e.html)
+
View
@@ -0,0 +1,31 @@
+# gallery13.rb
+# Mandelbrot Set No.007
+
+Shoes.app :width => 300, :height => 302, :title => 'Mandelbrot v0.1' do
+ MAX, W, H = 200, 300, 300
+ x0, y0, w = 1.768606, -0.002229, 0.0000014
+ a0, a1 = x0 - w, x0 + w
+ b0, b1 = y0 - w, y0 + w
+
+ def mandelbrot a, b
+ x, y = 0.0, 0.0
+ MAX.times do |i|
+ x, y = x * x - y * y - a, 2.0 * x * y - b
+ return [x, y, i] if (x * x + y * y) > 4.0
+ end
+ [x, y, false]
+ end
+
+ nostroke
+ image :width => W, :height => H do
+ H.times do |j|
+ W.times do |i|
+ a, b = a0 + i * (a1 - a0) / W, b0 + j * (b1 - b0) / H
+ x, y, diverged = mandelbrot(a, b)
+ #oval(i, j, 1) unless diverged
+ color = diverged ? rgb(255 - diverged, x.abs, y.abs) : black
+ oval i, j, 1, :fill => color
+ end
+ end
+ end
+end
@@ -2,7 +2,7 @@ Shoes Tutorial Note
===================
**- For the Shoes App Rookie Creators -**
-July 2nd, 2009 by ashbb (Satoshi Asakawa), citizen428 (Michael Kohl), kotp (Victor H. Goff III)
+July 12th, 2009 by ashbb (Satoshi Asakawa), citizen428 (Michael Kohl), kotp (Victor H. Goff III)
Table of contents
-----------------

0 comments on commit 1d74ec8

Please sign in to comment.