{"id":347,"date":"2007-10-19T02:00:53","date_gmt":"2007-10-19T07:00:53","guid":{"rendered":"http:\/\/www.juixe.com\/techknow\/index.php\/2007\/10\/19\/running-with-shoes-2d-examples\/"},"modified":"2007-10-19T02:00:53","modified_gmt":"2007-10-19T07:00:53","slug":"running-with-shoes-2d-examples","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2007\/10\/19\/running-with-shoes-2d-examples\/","title":{"rendered":"Running with Shoes &#8211; 2D Examples"},"content":{"rendered":"<p>I&#8217;ve already mentioned the <a href=\"http:\/\/www.juixe.com\/techknow\/index.php\/2007\/08\/27\/running-with-shoes-a-mini-gui\/\">Shoes,<\/a> the mini Ruby-based GUI Toolkit, and gone into detail about its <a href=\"http:\/\/www.juixe.com\/techknow\/index.php\/2007\/08\/27\/running-with-shoes-2d-graphics-and-animation\/\">2D graphics<\/a> capabilities.  In this post I will just provide some additional example of animated graphics developed with Shoes.<\/p>\n<p><b>Shoes Bubbles<\/b><br \/>\nThis sample application follows the mouse when it hovers around the application window and draws growing bubbles.  The bubbles have scan lines thanks to the mask method.<\/p>\n<p><span class=\"frame-outer  \"><span><span><span><span><img src='http:\/\/www.juixe.com\/techknow\/wp-content\/uploads\/2007\/10\/bubbles.png' alt='Shoes Bubble' \/><\/span><\/span><\/span><\/span><\/span><\/p>\n<p>Here is the source&#8230;<\/p>\n<p>[source:ruby]<br \/>\n# Array of x,y coordinates for bubbles<br \/>\nbubbles = [[0, 0]] * 30<\/p>\n<p># Bubbles Shoes application<br \/>\nShoes.app :width =&gt; 537, :height =&gt; 500 do<br \/>\n  # 24 frames\/second<br \/>\n  animate(24) do<br \/>\n    bubbles.shift<br \/>\n    bubbles &lt;&lt; self.mouse[1, 2]<br \/>\n    clear do<br \/>\n      # Create pinkish linescan<br \/>\n      (500\/5).times do |i|<br \/>\n        strokewidth 2<br \/>\n        stroke rgb(1.0, 0.5, 1.0, 1.0)<br \/>\n        line 0, i * 5, 537, i * 5<br \/>\n      end<br \/>\n      # Mask is expensive<br \/>\n      mask do<br \/>\n        # Create an oval bubble<br \/>\n        bubbles.each_with_index do |(x, y), i|<br \/>\n          oval x, y, 120 &#8211; (i * 5), 120 &#8211; (i * 5)<br \/>\n        end<br \/>\n      end<br \/>\n    end<br \/>\n  end<br \/>\nend<br \/>\n[\/source]<\/p>\n<p><b>Shoes Flower<\/b><br \/>\nThis is an animation of two concentric sets of circles moving in different directions.  As the circles move they change size and color.<\/p>\n<p><span class=\"frame-outer  \"><span><span><span><span><img src='http:\/\/www.juixe.com\/techknow\/wp-content\/uploads\/2007\/10\/flower.png' alt='Shoes Flower' \/><\/span><\/span><\/span><\/span><\/span><\/p>\n<p>Here is the code&#8230;<\/p>\n<p>[source:ruby]<br \/>\ndegree = 0<br \/>\ncolor = 0<br \/>\nsize = 0<\/p>\n<p>Shoes.app :width =&gt; 537, :height =&gt; 500 do<br \/>\n  mx, my = (500\/2).to_i, (537\/2).to_i<br \/>\n  animate(24) do<br \/>\n    clear do<br \/>\n      # Manage color<br \/>\n      nostroke<br \/>\n      background rgb(1.0, 0.5, 1.0, 1.0)<\/p>\n<p>      # Update some variables<br \/>\n      degree += 1<br \/>\n      size += 1<br \/>\n      degree = 0 if(degree &gt;= 360)<br \/>\n      size = 0 if(size &gt;= 100)<br \/>\n      color = 0.0 if(color &gt;= 1.0)<br \/>\n      color += 0.05 if(degree % 10 == 0)<\/p>\n<p>      # Draw inner circle<br \/>\n      fill red(color)<br \/>\n      10.times do |i|<br \/>\n        current_size = 100 + size<br \/>\n        d = to_radians(i * 60 + degree)<br \/>\n        rx = Math::cos(d) * 100<br \/>\n        ry = Math::sin(d) * 100<br \/>\n        center_x = -current_size\/2 + rx + mx<br \/>\n        center_y = -current_size\/2 + ry + my<br \/>\n        oval center_x, center_y, current_size, current_size<br \/>\n      end<\/p>\n<p>      # Draw outer circle<br \/>\n      fill blue(color)<br \/>\n      20.times do |i|<br \/>\n        current_size = 50 + size<br \/>\n        d = to_radians(i * 30 &#8211; degree)<br \/>\n        rx = Math::cos(d) * 150<br \/>\n        ry = Math::sin(d) * 150<br \/>\n        center_x = -current_size\/2 + rx + mx<br \/>\n        center_y = -current_size\/2 + ry + my<br \/>\n        oval center_x, center_y, current_size, current_size<br \/>\n      end<br \/>\n    end<br \/>\n  end<br \/>\nend<\/p>\n<p># Convert degrees to radians<br \/>\ndef to_radians(deg)<br \/>\n  deg * Math::PI \/ 180<br \/>\nend<br \/>\n[\/source]<\/p>\n<p>Technorati Tags: <a href=\"http:\/\/technorati.com\/tag\/ruby\" rel=\"tag\">ruby<\/a>, <a href=\"http:\/\/technorati.com\/tag\/shoes\" rel=\"tag\"> shoes<\/a>, <a href=\"http:\/\/technorati.com\/tag\/gui\" rel=\"tag\"> gui<\/a>, <a href=\"http:\/\/technorati.com\/tag\/toolkit\" rel=\"tag\"> toolkit<\/a>, <a href=\"http:\/\/technorati.com\/tag\/2d\" rel=\"tag\"> 2d<\/a>, <a href=\"http:\/\/technorati.com\/tag\/graphics\" rel=\"tag\"> graphics<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve already mentioned the Shoes, the mini Ruby-based GUI Toolkit, and gone into detail about its 2D graphics capabilities. In this post I will just provide some additional example of animated graphics developed with Shoes. Shoes Bubbles This sample application follows the mouse when it hovers around the application window and draws growing bubbles. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[19,22,3],"tags":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p902K-5B","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/347"}],"collection":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/comments?post=347"}],"version-history":[{"count":0,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/347\/revisions"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=347"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}