JRubyArt (Code as Art) JRubyArt is a ruby implementation of processing (approximates to version 4.0). https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/ Thu, 20 Jan 2022 13:41:49 +0000 Thu, 20 Jan 2022 13:41:49 +0000 Jekyll v3.9.0 Getting Started On Windows <h3 id="getting-started-with-jrubyart">Getting Started With JRubyArt</h3> <p>If you love to code because it is a creative process, then you should give JRubyArt a try because it can be used to create music, art, animations, videos and much more. Also since it is based on the latest <a href="https://processing.org/">Processing</a> you can access a vast range of libraries to make the difficult things easier.</p> <h3 id="why-jrubyart">Why JRubyArt?</h3> <p>Since Processing already comes wrapped in an easy-to-use package, you may ask: “why should I bother with JRubyArt?”</p> <p>The answer: if you know how to write Ruby, you can use Processing as a visual presentation layer of a much more complex program. Games, interactive art exhibits, innovative music projects, anything you can imagine; it’s all at your fingertips.</p> <p>Additionally, you don’t have to declare types, voids, or understand the differences between floats and ints to get started, as you do in pure Processing.</p> <p>Although there are some drawbacks to using the Ruby version Processing (slower start up time, and sometimes performance), having Ruby’s API available to translate your ideas into sketches more than makes up for them.</p> <h3 id="setup">Setup</h3> <p>Setting JRubyArt since JRubyArt-2.0 does not require a vanilla processing install, but still requires some configuration to point to your libraries folder.</p> <p>Install <a href="http://gnuwin32.sourceforge.net/packages/wget.htm">wget</a> which is also available as <a href="https://www.cygwin.com/">cygwin</a> package, openjdk (17.01+), and some version of ruby-2.6+ preferably jruby-9.3+. If you encounter linkage problems it might be worth looking at <a href="https://adoptium.net/">Eclipse Temurin</a> distribution or OpenJ9.</p> <h3 id="jruby">JRuby</h3> <p>It might actually be simpler to just install <a href="https://github.com/jruby/jruby/wiki/GettingStarted">jruby</a> on Windows rather than struggle with MRI ruby, but you may also want to install <a href="https://www.cygwin.com/">cygwin</a> or similar in any case (cygwin has a wget package).</p> <p>If you’ve already installed MRI ruby is also possible to run JRubyArt without a system install of jruby. But a jruby install might be needed to use JRubyArt with other gems eg toxiclibs.</p> <p>Possibly the simplest way to get MRI ruby on windows is via <a href="https://rubyinstaller.org/downloads/">rubyinstaller</a>, uses MinGW. Alternatively you can install <a href="https://www.cygwin.com/">cygwin</a> and use <a href="https://blog.developwithpassion.com/2012/03/30/installing-rvm-with-cygwin-on-windows/">rvm</a> to install MRI ruby.</p> <h3 id="jrubyart">JRubyArt</h3> <p>Installing JRubyArt assumes you have installed a recent version of ruby (which can be either MRI ruby (preferably 2.5.* and not 2.7.* or safer JRuby-9.3.3.0)</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gem <span class="nb">install </span>jruby_art </code></pre></div></div> <p>If you <strong>haven’t</strong> installed JRubyArt before, the simplest way to set the configuration, and to install samples is:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--install</span> <span class="c"># no arguments</span> </code></pre></div></div> <p>this also installs <code class="language-plaintext highlighter-rouge">jruby-complete</code></p> <p>If you <strong>have</strong> installed JRubyArt before, the simplest way to set the configuration is:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-if</span> config </code></pre></div></div> <p>Using <code class="language-plaintext highlighter-rouge">-f</code> or <code class="language-plaintext highlighter-rouge">--force</code> flag forces the removal of the previous configuration.</p> <p>To check your configuration:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--check</span> <span class="c"># or -?</span> </code></pre></div></div> <p>The config file is <code class="language-plaintext highlighter-rouge">config.yml</code> in the <code class="language-plaintext highlighter-rouge">~/.jruby_art folder</code>, which you should edit if required.</p> <p>To explore command line options:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--help</span> <span class="c"># or k9 -h</span> </code></pre></div></div> <h4 id="running-examples">Running examples</h4> <p>To explore the installed examples:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> ~/k9_samples rake <span class="c"># to run examples randomly as a demo</span> <span class="c"># or check available tasks with</span> rake <span class="nt">--tasks</span> <span class="c"># use a task to randomly run a group of sketches eg</span> rake shaders <span class="c"># runs the shader examples</span> </code></pre></div></div> <h4 id="create-your-own-sketches">Create your own sketches</h4> <p>To create a simple sketch:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-c</span> fred 200 200 <span class="c"># sketch name=Fred width=200 height=200 mode=default</span> k9 <span class="nt">-c</span> my_sketch 300 300 p2d <span class="c"># sketch name=MySketch width=300 height=300 mode=P2D</span> </code></pre></div></div> <p>Edit <code class="language-plaintext highlighter-rouge">fred.rb</code> or <code class="language-plaintext highlighter-rouge">my_sketch.rb</code> with your favourite editor preferably <code class="language-plaintext highlighter-rouge">vim</code>, <code class="language-plaintext highlighter-rouge">emacs</code> or <code class="language-plaintext highlighter-rouge">atom</code>.</p> <p>To run sketch using the command line</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-r</span> fred.rb </code></pre></div></div> <p>To run a sketch from editor see <a href="https://ruby-processing.github.io/JRubyArt/started/">editors</a></p> <p>Read more about using the <a href="https://ruby-processing.github.io/JRubyArt/methods/processing_api">processing api here</a></p> <h4 id="processing">Processing</h4> <p>Installing processing is optional but you could us it download the processing.org and contributed libraries. You can check to see what platforms are supported <a href="https://github.com/processing/processing/wiki/Supported-Platforms">here</a>.</p> <p>Read more about using the <a href="https://ruby-processing.github.io/JRubyArt/methods/processing_api">processing api here</a></p> Sat, 28 Sep 2019 06:00:00 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/windows_start/ https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/windows_start/ jruby_art update Getting Started on Linux <h3 id="getting-started-with-jrubyart">Getting Started With JRubyArt</h3> <p>If you love to code because it is a creative process, then you should give JRubyArt a try because it can be used to create music, art, animations, videos and much more. Also since it is based on the latest <a href="https://processing.org/">Processing</a> you can access a vast range of libraries to make the difficult things easier.</p> <h3 id="why-jrubyart">Why JRubyArt?</h3> <p>Since Processing already comes wrapped in an easy-to-use package, you may ask: “why should I bother with JRubyArt?”</p> <p>The answer: if you know how to write Ruby, you can use Processing as a visual presentation layer of a much more complex program. Games, interactive art exhibits, innovative music projects, anything you can imagine; it’s all at your fingertips.</p> <p>Additionally, you don’t have to declare types, voids, or understand the differences between floats and ints to get started, as you do in pure Processing.</p> <p>Although there are some drawbacks to using the Ruby version Processing (slower start up time, and sometimes performance), having Ruby’s API available to translate your ideas into sketches more than makes up for them.</p> <h3 id="pure-jruby-setup-archlinux">Pure JRuby Setup Archlinux</h3> <p>Install Software as required:-</p> <p>It is probably OK to use default OpenJDK but if you encounter problems install <a href="https://adoptium.net/">Eclipse Temurin</a> instead. You can if you like use latest OpenJ9, or even <a href="https://www.graalvm.org/">graalvm</a></p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>pacman <span class="nt">-S</span> ruby <span class="c"># installs ruby-2.6</span> <span class="nb">sudo </span>pacman <span class="nt">-S</span> jruby <span class="c"># installs jruby-9.2.14.0</span> </code></pre></div></div> <p>Install gems as required</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gem <span class="nb">install </span>jruby_art gem <span class="nb">install </span>toxiclibs <span class="c"># optional</span> gem <span class="nb">install </span>pbox2d <span class="c"># optional</span> gem <span class="nb">install </span>geomerative <span class="c"># optional</span> </code></pre></div></div> <p>If you wish install vanilla processing, but it is not required since JRubyArt-2.0.</p> <p>If you <strong>haven’t</strong> installed JRubyArt before you should:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--install</span> <span class="c"># no arguments</span> </code></pre></div></div> <p>To configure JRubyArt, install samples, and also install jruby-complete</p> <p>If you <strong>have</strong> installed JRubyArt before you should:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-fi</span> config <span class="c"># -f or --force flags force removal of previous configuration</span> </code></pre></div></div> <p>Use:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--help</span> <span class="c"># or -h to show command line options</span> <span class="c"># or</span> k9 <span class="nt">--check</span> <span class="c"># or -? to check configuration</span> </code></pre></div></div> <h3 id="pure-jruby-setup-debian-mint-ubuntu">Pure JRuby Setup Debian (Mint, Ubuntu)</h3> <h4 id="java">Java</h4> <p>It should be possible to current default-jdk on Debian (openjdk 11.0.9.1 on Linux Mint when I last checked) only if you encounter problems should you install <a href="https://adoptium.net/">Eclipse Temurin</a> version which is available as a deb package.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt <span class="nb">install </span>default-jdk <span class="c"># On Mint probably similar on other Debian distros</span> </code></pre></div></div> <p>This will set up update-alternatives for you, which you can use to switch between jdk versions see below</p> <p>To install adoptopenjdk you can do following:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>wget <span class="nt">-qO</span> - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | <span class="nb">sudo </span>apt-key add - <span class="nb">sudo </span>add-apt-repository <span class="nt">--yes</span> https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ <span class="nb">sudo </span>apt-get <span class="nb">install</span> <span class="nt">-y</span> software-properties-common <span class="nb">sudo </span>apt-get update <span class="nb">sudo </span>apt-get <span class="nb">install </span>adoptopenjdk <span class="c"># only if you have linker issues.</span> </code></pre></div></div> <p>Use debian <code class="language-plaintext highlighter-rouge">update-alternatives</code> tool to manage configuration for java:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>update-alternatives <span class="nt">--config</span> java <span class="c"># to configure if required</span> <span class="nb">sudo </span>update-alternatives <span class="nt">--config</span> javac <span class="c"># to configure if required</span> <span class="nb">sudo </span>update-alternatives <span class="nt">--config</span> jar <span class="c"># to configure if required</span> </code></pre></div></div> <h4 id="mri-ruby">MRI Ruby</h4> <p>Install MRI ruby, if you are not using <code class="language-plaintext highlighter-rouge">rvm</code> or <code class="language-plaintext highlighter-rouge">rbenv</code>, then you should create a home in a local folder to store your gems eg <code class="language-plaintext highlighter-rouge">~/.gem/ruby/2.6.0</code> to store your gems:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">mkdir</span> <span class="nt">-p</span> ~/.gem/ruby/2.6.0.0 </code></pre></div></div> <p>To get <code class="language-plaintext highlighter-rouge">gem</code> command to use this location set <code class="language-plaintext highlighter-rouge">GEM_HOME</code> and <code class="language-plaintext highlighter-rouge">GEM_PATH</code> in <code class="language-plaintext highlighter-rouge">~/.profile</code> and add the <code class="language-plaintext highlighter-rouge">GEM_PATH/bin</code> to <code class="language-plaintext highlighter-rouge">PATH</code> as below:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">export </span><span class="nv">GEM_HOME</span><span class="o">=</span><span class="s2">"</span><span class="nv">$HOME</span><span class="s2">/.gem/ruby/2.6.0"</span> <span class="nb">export </span><span class="nv">GEM_PATH</span><span class="o">=</span><span class="s2">"</span><span class="nv">$HOME</span><span class="s2">/.gem/ruby/2.6.0"</span> <span class="c"># set PATH so it includes user's private bin directories</span> <span class="nb">export </span><span class="nv">PATH</span><span class="o">=</span><span class="s2">"</span><span class="nv">$HOME</span><span class="s2">/bin:</span><span class="nv">$HOME</span><span class="s2">/.local/bin:</span><span class="nv">$GEM_PATH</span><span class="s2">/bin:</span><span class="nv">$PATH</span><span class="s2">"</span> </code></pre></div></div> <h4 id="jruby">JRuby</h4> <p>Download and install latest jruby (in the <code class="language-plaintext highlighter-rouge">/opt</code> folder makes sense)</p> <p>Use <code class="language-plaintext highlighter-rouge">update-alternatives</code> to install and maintain configuration eg for jruby:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>update-alternatives <span class="nt">--install</span> /usr/bin/jruby jruby /opt/jruby-9.3.1.0/bin/jruby 100 <span class="nb">sudo </span>update-alternatives <span class="nt">--config</span> jruby <span class="c"># to configure if required</span> </code></pre></div></div> <h4 id="jrubyart">JRubyArt</h4> <p>Install gems as required</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gem <span class="nb">install </span>jruby_art gem <span class="nb">install </span>toxiclibs <span class="c"># optional</span> gem <span class="nb">install </span>pbox2d <span class="c"># optional</span> gem <span class="nb">install </span>geomerative <span class="c"># optional</span> </code></pre></div></div> <p>If you wish install vanilla processing, but it is not required since JRubyArt-2.0.</p> <p>If you <strong>haven’t</strong> installed JRubyArt before you should:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--install</span> <span class="c"># no arguments</span> </code></pre></div></div> <p>To configure JRubyArt, install samples, and also install jruby-complete</p> <p>If you <strong>have</strong> installed JRubyArt before you should:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-fi</span> config <span class="c"># -f or --force flags force removal of previous configuration</span> </code></pre></div></div> <p>Use:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--help</span> <span class="c"># or -h to show command line options</span> <span class="c"># or</span> k9 <span class="nt">--check</span> <span class="c"># or -? to check configuration</span> </code></pre></div></div> <p>Installing JRubyArt assumes you have installed a recent version of ruby (which can be either MRI ruby or JRuby)</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gem <span class="nb">install </span>jruby_art </code></pre></div></div> <p>If you <strong>haven’t</strong> installed JRubyArt before, the simplest way to set the configuration, and to install samples is:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--install</span> <span class="c"># no arguments</span> </code></pre></div></div> <p>this also installs <code class="language-plaintext highlighter-rouge">jruby-complete</code></p> <p>If you <strong>have</strong> installed JRubyArt before, the simplest way to set the configuration is:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-if</span> config </code></pre></div></div> <p>Using <code class="language-plaintext highlighter-rouge">-f</code> or <code class="language-plaintext highlighter-rouge">--force</code> flag forces the removal of the previous configuration.</p> <p>To check your configuration:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--check</span> <span class="c"># or -?</span> </code></pre></div></div> <p>The config file is <code class="language-plaintext highlighter-rouge">config.yml</code> in the <code class="language-plaintext highlighter-rouge">~/.jruby_art folder</code>, which you should edit if required.</p> <p>To explore command line options:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--help</span> <span class="c"># or k9 -h</span> </code></pre></div></div> <p>To explore the installed examples:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> ~/k9_samples rake <span class="c"># to run examples randomly as a demo</span> <span class="c"># or check available tasks with</span> rake <span class="nt">--tasks</span> <span class="c"># use a task to randomly run a group of sketches eg</span> rake shaders <span class="c"># runs the shader examples</span> </code></pre></div></div> <p>To create a simple sketch:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-c</span> fred 200 200 <span class="c"># sketch name=Fred width=200 height=200 mode=default</span> k9 <span class="nt">-c</span> my_sketch 300 300 p2d <span class="c"># sketch name=MySketch width=300 height=300 mode=P2D</span> </code></pre></div></div> <p>Edit <code class="language-plaintext highlighter-rouge">fred.rb</code> or <code class="language-plaintext highlighter-rouge">my_sketch.rb</code> with your favourite editor preferably <code class="language-plaintext highlighter-rouge">vim</code>, <code class="language-plaintext highlighter-rouge">emacs</code> or <code class="language-plaintext highlighter-rouge">atom</code>.</p> <p>To run sketch using the command line</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-r</span> fred.rb </code></pre></div></div> <p>To run a sketch from editor see [editors][editors]</p> <h4 id="processing">Processing</h4> <p>Installing processing is optional but you could us it download the processing.org and contributed libraries. You can check to see what platforms are supported <a href="https://github.com/processing/processing/wiki/Supported-Platforms">here</a>.</p> <h4 id="running-examples">Running examples</h4> <p>To explore the installed examples:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> ~/k9_samples rake <span class="c"># to run examples randomly as a demo</span> <span class="c"># or check available tasks with</span> rake <span class="nt">--tasks</span> <span class="c"># use a task to randomly run a group of sketches eg</span> rake shaders <span class="c"># runs the shader examples</span> </code></pre></div></div> <h4 id="create-your-own-sketches">Create your own sketches</h4> <p>To create a simple sketch:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-c</span> fred 200 200 <span class="c"># sketch name=Fred width=200 height=200 mode=default</span> k9 <span class="nt">-c</span> my_sketch 300 300 p2d <span class="c"># sketch name=MySketch width=300 height=300 mode=P2D</span> </code></pre></div></div> <p>Edit <code class="language-plaintext highlighter-rouge">fred.rb</code> or <code class="language-plaintext highlighter-rouge">my_sketch.rb</code> with your favourite editor preferably <code class="language-plaintext highlighter-rouge">vim</code>, <code class="language-plaintext highlighter-rouge">emacs</code> or <code class="language-plaintext highlighter-rouge">atom</code>.</p> <p>To run sketch using the command line</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-r</span> fred.rb </code></pre></div></div> <p>To run a sketch from editor see [editors][editors]</p> <p>Read more about using the <a href="https://ruby-processing.github.io/JRubyArt/methods/processing_api">processing api here</a></p> Sat, 28 Sep 2019 06:00:00 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/linux_started/ https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/linux_started/ jruby_art update Getting Started on MacOS <h3 id="getting-started-with-jrubyart">Getting Started With JRubyArt</h3> <p>If you love to code because it is a creative process, then you should give JRubyArt a try because it can be used to create music, art, animations, videos and much more. Also since it is based on the latest <a href="https://processing.org/">Processing</a> you can access a vast range of libraries to make the difficult things easier.</p> <h3 id="why-jrubyart">Why JRubyArt?</h3> <p>Since Processing already comes wrapped in an easy-to-use package, you may ask: “why should I bother with JRubyArt?”</p> <p>The answer: if you know how to write Ruby, you can use Processing as a visual presentation layer of a much more complex program. Games, interactive art exhibits, innovative music projects, anything you can imagine; it’s all at your fingertips.</p> <p>Additionally, you don’t have to declare types, voids, or understand the differences between floats and ints to get started, as you do in pure Processing.</p> <p>Although there are some drawbacks to using the Ruby version Processing (slower start up time, and sometimes performance), having Ruby’s API available to translate your ideas into sketches more than makes up for them.</p> <h4 id="java">Java</h4> <p>Most OpenJDK builds 17+ seem to be ok now including ibm and graal versions if you have any difficulties then try <a href="https://adoptium.net/">Eclipse Temurin</a>.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>brew <span class="nb">install </span>wget <span class="c"># yes!!! you do need wget, curl won't work</span> brew cask <span class="nb">install </span>adoptopenjdk <span class="c"># or openJ9 which may require manual install</span> </code></pre></div></div> <h4 id="jruby">JRuby</h4> <p>It is possible to get away without doing system install of JRuby (using <code class="language-plaintext highlighter-rouge">jruby-complete</code> instead) but the default configuration assumes a JRuby install. There is homebrew script for this too.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>brew <span class="nb">install </span>jruby <span class="c"># installs latest JRubyArt</span> </code></pre></div></div> <p>You don’t need <code class="language-plaintext highlighter-rouge">rvm</code> or <code class="language-plaintext highlighter-rouge">rbenv</code> for JRubyArt since we call <code class="language-plaintext highlighter-rouge">jruby</code> directly when needed, in fact you may find a combination of MRI for regular <code class="language-plaintext highlighter-rouge">ruby</code> commands and <code class="language-plaintext highlighter-rouge">jruby</code> only when needed (called internally to run a sketch) works for you. MRI gem command installs jruby_art far quicker than <code class="language-plaintext highlighter-rouge">jgem</code>, but <code class="language-plaintext highlighter-rouge">jgem</code> install is a lot safer.</p> <h4 id="jrubyart">JRubyArt</h4> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gem <span class="nb">install </span>jruby_art </code></pre></div></div> <p>Install other gems as required</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>jgem <span class="nb">install </span>toxiclibs <span class="c"># optional</span> jgem <span class="nb">install </span>pbox2d <span class="c"># optional</span> jgem <span class="nb">install </span>geomerative <span class="c"># optional</span> jgem <span class="nb">install </span>wordcram <span class="c"># optional</span> </code></pre></div></div> <p>If you wish install vanilla processing, but it is not required since JRubyArt-2.0.</p> <p>If you <strong>haven’t</strong> installed JRubyArt before you should:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--install</span> <span class="c"># no arguments</span> </code></pre></div></div> <p>To configure JRubyArt, install samples, and also install jruby-complete</p> <p>If you <strong>have</strong> installed JRubyArt before you should:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-fi</span> config <span class="c"># -f or --force flags force removal of previous configuration</span> </code></pre></div></div> <p>Use:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">--help</span> <span class="c"># or -h to show command line options</span> <span class="c"># or</span> k9 <span class="nt">--check</span> <span class="c"># or -? to check configuration</span> </code></pre></div></div> <h3 id="running-examples">Running examples</h3> <p>To explore the installed examples:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> ~/k9_samples rake <span class="c"># to run examples randomly as a demo</span> <span class="c"># or check available tasks with</span> rake <span class="nt">--tasks</span> <span class="c"># use a task to randomly run a group of sketches eg</span> rake shaders <span class="c"># runs the shader examples</span> </code></pre></div></div> <h4 id="create-your-own-sketches">Create your own sketches</h4> <p>To create a simple sketch:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-c</span> fred 200 200 <span class="c"># sketch name=Fred width=200 height=200 mode=default</span> k9 <span class="nt">-c</span> my_sketch 300 300 p2d <span class="c"># sketch name=MySketch width=300 height=300 mode=P2D</span> </code></pre></div></div> <p>Edit <code class="language-plaintext highlighter-rouge">fred.rb</code> or <code class="language-plaintext highlighter-rouge">my_sketch.rb</code> with your favourite editor preferably <code class="language-plaintext highlighter-rouge">vim</code>, <code class="language-plaintext highlighter-rouge">emacs</code> or <code class="language-plaintext highlighter-rouge">atom</code>.</p> <p>To run sketch using the command line</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-r</span> fred.rb </code></pre></div></div> <p>To run a sketch from editor see <a href="http://ruby-processing.github.io/JRubyArt/editors.html">editors</a></p> <p>Read more about using the <a href="https://ruby-processing.github.io/JRubyArt/methods/processing_api">processing api here</a></p> <p>Read more about using the <a href="https://ruby-processing.github.io/JRubyArt/methods/processing_api">processing api here</a></p> Sat, 28 Sep 2019 06:00:00 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/mac_start/ https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/mac_start/ jruby_art update Welcome to JRubyArt! <p>Check out:-</p> <ol> <li><a href="https://ruby-processing.github.io/JRubyArt/linux_started/">Getting started on linux</a></li> <li><a href="https://ruby-processing.github.io/JRubyArt/mac_start/">Getting started on MacOS</a></li> <li><a href="https://ruby-processing.github.io/JRubyArt/windows_start/">Getting started on Windows</a></li> </ol> <p>For more info on how to get the most out of JRubyArt see the <a href="https://ruby-processing.github.io/JRubyArt/">JRubyArt WebSite</a> and my <a href="https://monkstone.github.io/">JRubyArt blog</a>. File all bugs/feature requests at <a href="https://github.com/ruby-processing/JRubyArt/issues">JRubyArt issues</a>.</p> <div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">setup</span> <span class="n">sketch_title</span> <span class="s1">'Sketch Title'</span> <span class="k">end</span> <span class="k">def</span> <span class="nf">draw</span> <span class="c1"># the sketch loop</span> <span class="k">end</span> <span class="k">def</span> <span class="nf">settings</span> <span class="n">size</span> <span class="mi">200</span><span class="p">,</span> <span class="mi">200</span> <span class="c1"># full_screen # replaces size for full screen sketches</span> <span class="c1"># smooth </span> <span class="k">end</span> </code></pre></div></div> <p>Example Sketches:-</p> <p>see <a href="https://github.com/ruby-processing/JRubyArt-examples">installed sketches</a> and book examples <a href="https://github.com/ruby-processing/The-Nature-of-Code-for-JRubyArt">The Nature of Code Sketches</a></p> Sat, 28 Sep 2019 06:00:00 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/jruby_art/update/2019/09/28/welcome.html https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/jruby_art/update/2019/09/28/welcome.html jruby_art update Installing Contributed Java Libraries for JRubyArt <h3 id="listing-libraries-and-their-urls">Listing Libraries and their urls</h3> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>wget http://download.processing.org/contribs/contribs.txt </code></pre></div></div> <p>NB <code class="language-plaintext highlighter-rouge">toxiclibs</code>, <code class="language-plaintext highlighter-rouge">pbox2d</code>, <code class="language-plaintext highlighter-rouge">joonsrenderer</code>, <code class="language-plaintext highlighter-rouge">wordcram</code> and <code class="language-plaintext highlighter-rouge">geomerative libraries</code> are available as rubygems, further the libraries in the contributed list only contains libraries curated (<em>filtered</em>) by Prisoner John, there are many more that are available out there eg Joshua Davis <code class="language-plaintext highlighter-rouge">hype</code>.</p> <p>An example library listing in contribs.txt:-</p> <pre> library minRevision=228 name=gicentreUtils maxRevision=0 sentence=Assists creation of data visualization sketches. url=http://www.gicentre.org/utils/ prettyVersion=3.4.0 paragraph=Includes color utilities, statistical graphics, morphing classes, spatial utilities and map projections, force-directed layouts and text input/output. Together these make the task of creating data visualization sketches much faster by providing code for commonly repeated tasks such as zooming in and out of a sketch, setting up color tables etc. For documentation and examples, see the [gicentreUtils pages](http://www.gicentre.org/utils/). version=14 authors=[Jo Wood](http://gicentre.org/) and [Aidan Slingsby](http://gicentre.org/) download=http://staff.city.ac.uk/~jwo/giCentre/utils/gicentreUtils.zip type=library id=004 </pre> <h3 id="installing-a-library">Installing a library</h3> <p>Install libraries to your <code class="language-plaintext highlighter-rouge">~/.jruby_art/libraries</code> folder. NB: this created for you when you install the <code class="language-plaintext highlighter-rouge">video</code> or <code class="language-plaintext highlighter-rouge">sound</code> libraries.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>jruby_art <span class="nt">-i</span> Sound jruby_art <span class="nt">-i</span> Video </code></pre></div></div> <p>It can make sense to convert the library names and jars from <code class="language-plaintext highlighter-rouge">camelcase</code> to <code class="language-plaintext highlighter-rouge">snakecase</code>, (<em>ie when library creators have messed up</em>) you just need to be consistent, see below</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> ~/.jruby_art/libraries wget http://staff.city.ac.uk/~jwo/giCentre/utils/gicentreUtils.zip unzip gicentreUtils.zip <span class="c"># NB: British English spelling of centre</span> <span class="nb">mv </span>gicentreUtils gicenter_utils <span class="c"># Use snake case, and convert spelling</span> <span class="nb">cd </span>gicenter_utils/library <span class="nb">mv </span>gicentreUtils.jar gicenter_utils.jar </code></pre></div></div> <p>Here is an example sketch translated to JRubyArt, main differences are how we load libraries and access package namespace in JRubyArt. Also note the use of the data_path wrapper to access sketch data folder. Another twist is the need to cast array of ruby Numbers to java float.</p> <div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Sketch to demonstrate the use of the BarChart class to draw simple bar charts.</span> <span class="c1"># Version 1.3, 6th February, 2016.</span> <span class="c1"># Author Jo Wood, giCentre.</span> <span class="n">load_library</span> <span class="ss">:gicenter_utils</span> <span class="n">include_package</span> <span class="s1">'org.gicentre.utils.stat'</span> <span class="c1"># British spelling</span> <span class="k">def</span> <span class="nf">settings</span> <span class="n">size</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span> <span class="mi">300</span><span class="p">)</span> <span class="n">smooth</span> <span class="k">end</span> <span class="k">def</span> <span class="nf">setup</span> <span class="c1"># a static sketch no need for draw loop</span> <span class="n">sketch_title</span> <span class="s1">'Bar Chart Sketch'</span> <span class="n">title_font</span> <span class="o">=</span> <span class="n">load_font</span><span class="p">(</span><span class="n">data_path</span><span class="p">(</span><span class="s1">'Helvetica-22.vlw'</span><span class="p">))</span> <span class="n">small_font</span> <span class="o">=</span> <span class="n">load_font</span><span class="p">(</span><span class="n">data_path</span><span class="p">(</span><span class="s1">'Helvetica-12.vlw'</span><span class="p">))</span> <span class="n">text_font</span><span class="p">(</span><span class="n">small_font</span><span class="p">)</span> <span class="n">bar_chart</span> <span class="o">=</span> <span class="no">BarChart</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="nb">self</span><span class="p">)</span> <span class="n">data_float</span> <span class="o">=</span> <span class="p">[</span> <span class="mi">2_462</span><span class="p">,</span> <span class="mi">2_801</span><span class="p">,</span> <span class="mi">3_280</span><span class="p">,</span> <span class="mi">3_983</span><span class="p">,</span> <span class="mi">4_490</span><span class="p">,</span> <span class="mi">4_894</span><span class="p">,</span> <span class="mi">5_642</span><span class="p">,</span> <span class="mi">6_322</span><span class="p">,</span> <span class="mi">6_489</span><span class="p">,</span> <span class="mi">6_401</span><span class="p">,</span> <span class="mi">7_657</span><span class="p">,</span> <span class="mi">9_649</span><span class="p">,</span> <span class="mi">9_767</span><span class="p">,</span> <span class="mi">12_167</span><span class="p">,</span> <span class="mi">15_154</span><span class="p">,</span> <span class="mi">18_200</span><span class="p">,</span> <span class="mi">23_124</span><span class="p">,</span> <span class="mi">28_645</span><span class="p">,</span> <span class="mi">39_471</span> <span class="p">]</span> <span class="n">bar_chart</span><span class="p">.</span><span class="nf">setData</span><span class="p">(</span><span class="n">data_float</span><span class="p">.</span><span class="nf">to_java</span><span class="p">(</span><span class="ss">:float</span><span class="p">))</span> <span class="n">data_label</span> <span class="o">=</span> <span class="sx">%w(1830 1840 1850 1860 1870 1880 1890 1900 1910 1920 1930 1940 1950 1960 1970 1980 1990 2000 2010)</span> <span class="n">bar_chart</span><span class="p">.</span><span class="nf">setBarLabels</span><span class="p">(</span><span class="n">data_label</span><span class="p">)</span> <span class="n">bar_chart</span><span class="p">.</span><span class="nf">setBarColour</span><span class="p">(</span><span class="n">color</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">100</span><span class="p">))</span> <span class="n">bar_chart</span><span class="p">.</span><span class="nf">setBarGap</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="n">bar_chart</span><span class="p">.</span><span class="nf">setValueFormat</span><span class="p">(</span><span class="s1">'$###,###'</span><span class="p">)</span> <span class="n">bar_chart</span><span class="p">.</span><span class="nf">showValueAxis</span><span class="p">(</span><span class="kp">true</span><span class="p">)</span> <span class="n">bar_chart</span><span class="p">.</span><span class="nf">showCategoryAxis</span><span class="p">(</span><span class="kp">true</span><span class="p">)</span> <span class="n">background</span><span class="p">(</span><span class="mi">255</span><span class="p">)</span> <span class="n">bar_chart</span><span class="p">.</span><span class="nf">draw</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="n">width</span> <span class="o">-</span> <span class="mi">20</span><span class="p">,</span> <span class="n">height</span> <span class="o">-</span> <span class="mi">20</span><span class="p">)</span> <span class="n">fill</span><span class="p">(</span><span class="mi">120</span><span class="p">)</span> <span class="n">text_font</span><span class="p">(</span><span class="n">title_font</span><span class="p">)</span> <span class="n">text</span><span class="p">(</span><span class="s1">'Income per person, United Kingdom'</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span> <span class="mi">30</span><span class="p">)</span> <span class="n">text_height</span> <span class="o">=</span> <span class="n">text_ascent</span> <span class="c1"># of title font</span> <span class="n">text_font</span><span class="p">(</span><span class="n">small_font</span><span class="p">)</span> <span class="n">text</span><span class="p">(</span><span class="s1">'Gross domestic product measured in inflation-corrected $US'</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span> <span class="mi">30</span> <span class="o">+</span> <span class="n">text_height</span><span class="p">)</span> <span class="k">end</span> </code></pre></div></div> Mon, 23 Sep 2019 06:00:00 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/contributed https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/contributed Watching Sketches <h3 id="any-editor">Any editor</h3> <p>From console:-</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">mkdir</span> <span class="s1">'any_name'</span> <span class="nb">cd</span> <span class="s1">'any_name'</span> <span class="nb">touch</span> <span class="s1">'fred.rb'</span> </code></pre></div></div> <h3 id="vim">Vim</h3> <p>Open new console</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> <span class="s1">'any_name'</span> vim fred.rb </code></pre></div></div> <p>In 1st console</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-w</span> fred.rb <span class="c"># A bare sketch is displayed with a default size, background etc.</span> </code></pre></div></div> <p>Edit sketch in vim eg</p> <div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">background</span> <span class="mi">0</span> <span class="c1"># Sketch reloads on `:w` save with a black background</span> <span class="c1"># PS: in processing this is a so called static sketch (ie no draw loop)</span> <span class="c1"># no interaction is possible via mouse etc</span> </code></pre></div></div> <h3 id="other-editors-eg-atom">Other editors eg atom</h3> <p>From console</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>atom fred.rb # opens sketch for editing in atom </code></pre></div></div> <p>From same console</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-w</span> fred.rb <span class="c"># As above a bare sketch is displayed with default background</span> </code></pre></div></div> <p>Edit sketch in atom, on save sketch will reload</p> <h3 id="normal-sketches-ie-with-draw-loop-sketch_title-etc">Normal sketches (ie with draw loop, sketch_title etc)</h3> <p>Use the JRubyArt sketch creator facility to create an outline sketch as follows</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>k9 <span class="nt">-c</span> fred 200 200 <span class="c"># creates fred.rb, with `size 200, 200` you can do interesting</span> <span class="c"># things with code in the draw loop</span> </code></pre></div></div> <p>Then <code class="language-plaintext highlighter-rouge">watch</code>, and <code class="language-plaintext highlighter-rouge">edit</code> as above (with editor of choice, preferably vim for console, or atom for gui, with <code class="language-plaintext highlighter-rouge">language-jruby-art package</code>).</p> <p>Suggested exercises:-</p> <ol> <li>set background and fill in the draw loop, draw ellipse (or rect) in fixed location, then substitute <code class="language-plaintext highlighter-rouge">mouse_x</code> or <code class="language-plaintext highlighter-rouge">mouse_y</code> for <code class="language-plaintext highlighter-rouge">x</code> or <code class="language-plaintext highlighter-rouge">y</code> coordinates…</li> <li>Experiment with no background, semi transparent background, or semi transparent fill eg <code class="language-plaintext highlighter-rouge">background(color(200, 0, 0, 50))</code> or <code class="language-plaintext highlighter-rouge">fill(200, 100)</code></li> </ol> Sun, 07 Jan 2018 05:15:13 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/watch/ https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/watch/ jruby_art update Vector Classes and Duck Typing <h2 id="duck-typing-and-vector-classes">Duck Typing and Vector classes</h2> <p>Since JRubyArt-1.4.5, Vec2D and Vec3D classes support duck-typing copy constructors. This means that the source vector need only supply accessor methods for <code class="language-plaintext highlighter-rouge">:x</code> and <code class="language-plaintext highlighter-rouge">:y</code> (that return either float or fixnum). Note <code class="language-plaintext highlighter-rouge">:z</code> can be supplied for Vec3D constructor, else <code class="language-plaintext highlighter-rouge">z</code> is set to zero, however supply <code class="language-plaintext highlighter-rouge">z</code> to Vec2D constructor it will be ignored see below:-</p> <div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="no">Vector</span> <span class="o">=</span> <span class="no">Struct</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="ss">:x</span><span class="p">,</span> <span class="ss">:y</span><span class="p">)</span> <span class="c1"># simple valid duck-type</span> <span class="n">fred</span> <span class="o">=</span> <span class="no">Vector</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span> <span class="n">ted</span> <span class="o">=</span> <span class="no">Vec2D</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">fred</span><span class="p">)</span> <span class="n">ted</span><span class="p">.</span><span class="nf">inspect</span> <span class="c1"># "Vec2D(x = 1.0000, y = 4.0000)"</span> <span class="n">ted3</span> <span class="o">=</span> <span class="no">Vec3D</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">fred</span><span class="p">)</span> <span class="n">ted3</span><span class="p">.</span><span class="nf">inspect</span> <span class="c1"># "Vec3D(x = 1.0000, y = 4.0000, z = 0.0000)"</span> <span class="n">bob</span> <span class="o">=</span> <span class="no">Vec2D</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">ted3</span><span class="p">)</span> <span class="n">bob</span><span class="p">.</span><span class="nf">inspect</span> <span class="c1"># Vec2D(x = 1.0000, y = 4.0000)</span> <span class="no">Vector3</span> <span class="o">=</span> <span class="no">Struct</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="ss">:x</span><span class="p">,</span> <span class="ss">:y</span><span class="p">,</span> <span class="ss">:z</span><span class="p">)</span> <span class="c1"># simple valid duck-type</span> <span class="n">fred3</span> <span class="o">=</span> <span class="no">Vector</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="mf">8.0</span><span class="p">,</span> <span class="mf">7.0</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span> <span class="n">bob3</span> <span class="o">=</span> <span class="no">Vec3D</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">fred3</span><span class="p">)</span> <span class="n">bob3</span><span class="p">.</span><span class="nf">inspect</span> <span class="c1"># Vec3D(x = 8.0000, y = 7.0000, z = 10.0000)</span> </code></pre></div></div> <p>Note despite fixnum entry Vec2D and Vec3D values are stored as float (well actually as a java double, but that’s an implementation detail)</p> Sun, 07 Jan 2018 05:15:13 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/duck_type/ https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/duck_type/ jruby_art update Installing Ruby <h2 id="installing-ruby">Installing ruby</h2> <p>There may be problems using the latest MRI ruby releases (should work OK with ruby-2.6), default setup is to use most recent JRuby, rather than a combination of MRI ruby and JRuby-Complete.</p> <h3 id="managers">Managers</h3> <p>Many Rubyists use Ruby managers to manage multiple Rubies. They confer various advantages but are not officially supported. Their respective communities are very helpful, however do not use them unless you absolutely must, they are generally an absolute pain and not needed for JRubyArt (which ultimately runs directly from <code class="language-plaintext highlighter-rouge">java</code> when using <code class="language-plaintext highlighter-rouge">jruby-complete</code> or from an installed <code class="language-plaintext highlighter-rouge">jruby</code> over which rvm and rbenv have no control over, you have been warned)</p> <h2 id="installing-jruby">Installing jruby</h2> <p>For windows see <a href="https://github.com/jruby/jruby/wiki/GettingStarted">JRuby wiki</a></p> <p>For Arch Linux</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">sudo </span>pacman <span class="nt">-S</span> jruby </code></pre></div></div> <p>This should install the latest stable JRuby version.</p> <p>For Debian linux</p> <p>Get the latest version from <a href="http://jruby.org/download">http://jruby.org/download</a></p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> /opt <span class="nb">tar </span>xzvf /pathToDownload/jruby-bin-9.3.x.x.tar.gz </code></pre></div></div> <p>You could the use the excellent update-alternatives to provide symbolic links to ruby, jruby, jirb jgem etc.</p> <p>For MacOS user using the Homebrew as a package manager.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>brew <span class="nb">install </span>jruby </code></pre></div></div> <p>This will again generally install the the latest jruby for you.</p> <h3 id="managers-1">Managers</h3> <p>As far as I know rvm and rbenv are completely useless with jruby (further bundler is also as good as useless for JRubyArt)</p> Wed, 08 Feb 2017 05:15:13 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/installing_ruby/ https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/installing_ruby/ jruby_art update The processing api <p>JRubyArt is the closest thing to a ruby DSL for vanilla processing, it supports <code class="language-plaintext highlighter-rouge">bare</code> sketches, and <code class="language-plaintext highlighter-rouge">static</code> sketches, and most of the processing-api see below:-</p> <h3 id="the-processing-api">The processing-api</h3> <p>Most of the processing methods, as explained in the <a href="https://processing.org/reference/">Processing Language API</a>, are available as instance methods on your Processing::App. (frame_rate, ellipse, and the 158 others.) This makes it easy as pie to use them within your sketch, but you should prefer snake case to camel case and there are some caveats. Here is an example of a <code class="language-plaintext highlighter-rouge">bare</code> sketch (you can if you wish create a class wrapped sketch), the main difference with vanilla processing (from the processing ide) is that you need to explicitly create a <a href="https://processing.org/reference/settings_.html">settings</a> method to set the size and sketch mode.</p> <div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">settings</span> <span class="n">size</span> <span class="mi">200</span><span class="p">,</span> <span class="mi">200</span> <span class="n">smooth</span> <span class="mi">8</span> <span class="k">end</span> <span class="k">def</span> <span class="nf">setup</span> <span class="n">sketch_title</span> <span class="s1">'Triangles Gone Wild'</span> <span class="c1"># JRubyArt &amp; propane</span> <span class="n">color_mode</span> <span class="no">RGB</span><span class="p">,</span> <span class="mf">1.0</span> <span class="n">frame_rate</span> <span class="mi">30</span> <span class="n">fill</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.4</span> <span class="k">end</span> <span class="k">def</span> <span class="nf">draw</span> <span class="n">triangle</span><span class="p">(</span><span class="nb">rand</span><span class="p">(</span><span class="n">width</span><span class="p">),</span> <span class="nb">rand</span><span class="p">(</span><span class="n">height</span><span class="p">),</span> <span class="nb">rand</span><span class="p">(</span><span class="n">width</span><span class="p">),</span> <span class="nb">rand</span><span class="p">(</span><span class="n">height</span><span class="p">),</span> <span class="nb">rand</span><span class="p">(</span><span class="n">width</span><span class="p">),</span> <span class="nb">rand</span><span class="p">(</span><span class="n">height</span><span class="p">))</span> <span class="k">end</span> </code></pre></div></div> <h3 id="caveats">Caveats</h3> <p>Here are some the main differences moving from vanilla processing to JRubyArt:-</p> <ol> <li> <p>You do not declare types in ruby <code class="language-plaintext highlighter-rouge">vec = PVector.new</code> instead of <code class="language-plaintext highlighter-rouge">PVector vec = new PVector()</code> for example, however in this case you should use <a href="https://ruby-processing.github.io/JRubyArt/classes.html">Vec2D and Vec3D</a>, which are alternatives to PVector (but with methods that are much more ruby-like, and have extended functionality).</p> </li> <li> <p>There are no void methods (what’s evaluated gets returned without needing an explicit return)</p> </li> <li>Everything is an object (this includes primitive types float, integer etc cf. java) <a href="https://www.ruby-lang.org/en/about/">see more</a></li> <li> <p>Confusing for beginners and especially pythonistas there is often more than one way to do it</p> </li> <li> <p>Processing makes heavy use of java <code class="language-plaintext highlighter-rouge">inner</code> classes (to make methods and values somewhat globally available) JRubyArt provides the <code class="language-plaintext highlighter-rouge">Processing::Proxy</code> mixin to somewhat mimic this behaviour see <a href="https://github.com/ruby-processing/JRubyArt-examples/blob/master/contributed/circle_collision.rb">Ball</a>. An alternative to consider is to use delegator methods using <code class="language-plaintext highlighter-rouge">extend Forwardable</code>, requires <code class="language-plaintext highlighter-rouge">require 'forwardable'</code> see JRubyArt <a href="https://github.com/ruby-processing/JRubyArt-examples/blob/master/external_library/gem/toxiclibs/soft_body/library/blanket/lib/particle.rb">example</a>.</p> </li> <li>Use <code class="language-plaintext highlighter-rouge">mouse_pressed?</code> and <code class="language-plaintext highlighter-rouge">key_pressed?</code> to access mouse_pressed and key_pressed as variables (ruby can’t cope with overloading the <code class="language-plaintext highlighter-rouge">mouse_pressed</code> and <code class="language-plaintext highlighter-rouge">key_pressed</code> methods like java) <a href="https://github.com/ruby-processing/JrubyArt-examples/blob/master/contributed/re_sample.rb">see example</a>.</li> </ol> <p>In general you should try and code in regular ruby (in JRubyArt), only using processing short-cuts / methods when you need to (ie when ruby alternatives don’t exist, many processing short-cuts just aren’t needed in ruby). From 3. above you should use:-</p> <ul> <li><code class="language-plaintext highlighter-rouge">a**b</code> for <code class="language-plaintext highlighter-rouge">pow(a, b)</code></li> <li><code class="language-plaintext highlighter-rouge">theta.degrees</code> for <code class="language-plaintext highlighter-rouge">degrees(theta)</code></li> <li><code class="language-plaintext highlighter-rouge">theta.radians</code> for <code class="language-plaintext highlighter-rouge">radians(theta)</code></li> <li><code class="language-plaintext highlighter-rouge">x.abs</code> for <code class="language-plaintext highlighter-rouge">abs(x)</code></li> <li><code class="language-plaintext highlighter-rouge">x.ceil</code> for <code class="language-plaintext highlighter-rouge">ceil(x)</code></li> <li><code class="language-plaintext highlighter-rouge">x.round</code> for <code class="language-plaintext highlighter-rouge">round(x)</code></li> <li><code class="language-plaintext highlighter-rouge">str.strip</code> for <code class="language-plaintext highlighter-rouge">trim(str)</code></li> <li><code class="language-plaintext highlighter-rouge">str.hex</code> for <code class="language-plaintext highlighter-rouge">hex(str)</code></li> <li><code class="language-plaintext highlighter-rouge">string.to_i(base=16)</code> for <code class="language-plaintext highlighter-rouge">unhex(str)</code></li> </ul> <p>Other ruby methods to prefer are:-</p> <ul> <li><code class="language-plaintext highlighter-rouge">rand(x)</code> to <code class="language-plaintext highlighter-rouge">random(x)</code></li> <li><code class="language-plaintext highlighter-rouge">rand(lo..hi)</code> to <code class="language-plaintext highlighter-rouge">random(lo, hi)</code></li> <li><code class="language-plaintext highlighter-rouge">puts val</code> (or even just <code class="language-plaintext highlighter-rouge">p val</code>) to <code class="language-plaintext highlighter-rouge">println(val)</code></li> <li><code class="language-plaintext highlighter-rouge">map1d(val, (range1), (range2))</code> to <code class="language-plaintext highlighter-rouge">map(value, start1, stop1, start2, stop2)</code></li> <li><code class="language-plaintext highlighter-rouge">(lo..hi).clip(amt)</code> to <code class="language-plaintext highlighter-rouge">constrain(amt, lo, hi)</code> <em>it is how it is implemented</em></li> </ul> <p>To avoid confusion use with ruby <code class="language-plaintext highlighter-rouge">map</code> use <code class="language-plaintext highlighter-rouge">map1d</code> for processing <code class="language-plaintext highlighter-rouge">map</code> function see <a href="https://github.com/ruby-processing/JRubyArt-examples/blob/master/contributed/circles.rb">example</a>.</p> Sat, 21 Jan 2017 06:24:13 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/processing-api/ https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/processing-api/ Comparison JRubyArt-2.6 and JRubyArt-1.7 <p>JRubyArt is actively being developed, ruby-processing should be considered to be deprecated and is no-longer actively maintained. The only possible justification to prefer to use ruby-processing is to be compatible with processing-2.2.1. So since January 2017 table below has been modified to address what you need to know, now that you have decided to switch from ruby-processing to JRubyArt</p> <style> table{ border-collapse: collapse; border-spacing: 0; border:2px solid #0000FF; } th{ border:2px solid #0000FF; } </style> <table> <thead> <tr> <th>feature</th> <th>JRubyArt-1.7</th> <th>JRubyArt-2.6</th> </tr> </thead> <tbody> <tr> <td>binary</td> <td>k9</td> <td>k9</td> </tr> <tr> <td>run opts</td> <td>-r, -w, -l</td> <td>-r, -w, -l</td> </tr> <tr> <td>jruby version</td> <td>9.2.14.0 (2.5.7)</td> <td>9.3.0.0+ (2.6.8)</td> </tr> <tr> <td>jdk version</td> <td>jdk8</td> <td>jdk11+</td> </tr> <tr> <td>config</td> <td>PROCESSING_ROOT</td> <td>not required</td> </tr> </tbody> </table> <p>The <code class="language-plaintext highlighter-rouge">settings</code> method was introduced to vanilla processing since processing-3.0. However this is hidden for users of the <a href="https://processing.org/reference/settings_.html">processing ide</a> but required by Eclipse users. The <code class="language-plaintext highlighter-rouge">settings</code> method is where <code class="language-plaintext highlighter-rouge">size</code> belongs or <code class="language-plaintext highlighter-rouge">full_screen</code>, also you should set <code class="language-plaintext highlighter-rouge">smooth</code> and <code class="language-plaintext highlighter-rouge">pixel_density</code> here. Retina users can make use of their hi-dpi display by setting <code class="language-plaintext highlighter-rouge">pixel_density(2)</code>, NB: size should be first line of <code class="language-plaintext highlighter-rouge">settings</code>, and if used <code class="language-plaintext highlighter-rouge">pixel_density(2)</code> should be next.</p> <p>In JRubyArt use the <code class="language-plaintext highlighter-rouge">data_path</code> wrapper to return the absolute path for the <code class="language-plaintext highlighter-rouge">data</code> folder <a href="https://ruby-processing.github.io/JRubyArt/data_path/">see here</a> (this means <code class="language-plaintext highlighter-rouge">--nojruby</code> flag is obsolete since even shader sketches should now run with an installed jruby). Set <code class="language-plaintext highlighter-rouge">JRUBY: false</code> in config.yml to use jruby-complete instead of an installed jruby (crucial if you haven’t installed jruby on your system).</p> Mon, 28 Sep 2015 06:24:13 +0000 https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/jruby_art/update/2015/09/28/comparison.html https://ruby-processing.github.io/JRubyArthttps://ruby-processing.github.io/JRubyArt/jruby_art/update/2015/09/28/comparison.html jruby_art update