processing 0.5.29 → 0.5.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/release-gem.yml +6 -6
- data/.github/workflows/test-draw.yml +33 -0
- data/.github/workflows/test.yml +4 -2
- data/ChangeLog.md +18 -0
- data/Gemfile +4 -1
- data/Gemfile.lock +35 -0
- data/Rakefile +23 -0
- data/VERSION +1 -1
- data/lib/processing/all.rb +1 -0
- data/lib/processing/graphics_context.rb +240 -16
- data/lib/processing/shape.rb +183 -0
- data/lib/processing/vector.rb +3 -3
- data/processing.gemspec +4 -8
- data/test/helper.rb +100 -5
- data/test/p5.rb +76 -0
- data/test/test_graphics.rb +2 -8
- data/test/test_graphics_context.rb +451 -5
- data/test/test_shape.rb +387 -0
- data/test/test_vector.rb +1 -1
- metadata +17 -52
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f74daae97a7e307834facbc6eb147a08dbdc731afdb738674161db47eccd04ef
         | 
| 4 | 
            +
              data.tar.gz: 41324b1b967f4e3e5c11392ecf1a36beb82f9bbd4a2bb97dbc6d297b572bbe16
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: dace99fcdae4a94a38942d40327fe0e27251e4ea0cb5ba1c1b19683c45a92690124449b61fd47980389730350e8ccda180076e29cf99678a03a2a8408d0be03e
         | 
| 7 | 
            +
              data.tar.gz: a60cd201501e210f71ef6c163e0493877e6aed90ecae82c344d6f3e62238fa6091e3d1a17755098a3b7722b56f812fa6aa4ca1aa78de02560264f2fa30c41003
         | 
| @@ -17,19 +17,19 @@ jobs: | |
| 17 17 | 
             
                  - name: checkout
         | 
| 18 18 | 
             
                    uses: actions/checkout@v2
         | 
| 19 19 |  | 
| 20 | 
            +
                  - name: setup gems
         | 
| 21 | 
            +
                    run: bundle install
         | 
| 22 | 
            +
             | 
| 20 23 | 
             
                  - name: setup dependencies
         | 
| 21 24 | 
             
                    run: "ruby -I.github/workflows -rutils -e 'setup_dependencies'"
         | 
| 22 25 |  | 
| 23 | 
            -
                  - name: install gems
         | 
| 24 | 
            -
                    run: gem install yard
         | 
| 25 | 
            -
             | 
| 26 26 | 
             
                  - name: test
         | 
| 27 | 
            -
                    run: rake quiet test
         | 
| 27 | 
            +
                    run: bundle exec rake quiet test
         | 
| 28 28 |  | 
| 29 29 | 
             
                  - name: create gem
         | 
| 30 30 | 
             
                    id: gem
         | 
| 31 31 | 
             
                    run: |
         | 
| 32 | 
            -
                      rake gem
         | 
| 32 | 
            +
                      bundle exec rake gem
         | 
| 33 33 | 
             
                      echo path=$(ruby -e 'print Dir.glob("*.gem").first') >> $GITHUB_OUTPUT
         | 
| 34 34 |  | 
| 35 35 | 
             
                  - name: create github release
         | 
| @@ -59,4 +59,4 @@ jobs: | |
| 59 59 | 
             
                      touch $HOME/.gem/credentials
         | 
| 60 60 | 
             
                      chmod 0600 $HOME/.gem/credentials
         | 
| 61 61 | 
             
                      printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
         | 
| 62 | 
            -
                      rake upload
         | 
| 62 | 
            +
                      bundle exec rake upload
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            name: Test Draw
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            on:
         | 
| 4 | 
            +
              push:
         | 
| 5 | 
            +
                branches: [master]
         | 
| 6 | 
            +
              pull_request:
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            jobs:
         | 
| 9 | 
            +
              test:
         | 
| 10 | 
            +
                runs-on: macos-latest
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                steps:
         | 
| 13 | 
            +
                  - name: ruby 3.2
         | 
| 14 | 
            +
                    uses: ruby/setup-ruby@v1
         | 
| 15 | 
            +
                    with:
         | 
| 16 | 
            +
                      ruby-version: 3.2
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  - name: checkout
         | 
| 19 | 
            +
                    uses: actions/checkout@v2
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  - name: setup gems
         | 
| 22 | 
            +
                    run: bundle install
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  - name: setup dependencies
         | 
| 25 | 
            +
                    run: "ruby -I.github/workflows -rutils -e 'setup_dependencies'"
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  - name: setup chrome
         | 
| 28 | 
            +
                    uses: browser-actions/setup-chrome@latest
         | 
| 29 | 
            +
                    with:
         | 
| 30 | 
            +
                      chrome-version: stable
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  - name: test
         | 
| 33 | 
            +
                    run: rake test:draw
         | 
    
        data/.github/workflows/test.yml
    CHANGED
    
    | @@ -4,7 +4,6 @@ on: | |
| 4 4 | 
             
              push:
         | 
| 5 5 | 
             
                branches: [master]
         | 
| 6 6 | 
             
              pull_request:
         | 
| 7 | 
            -
                branches: [master]
         | 
| 8 7 |  | 
| 9 8 | 
             
            jobs:
         | 
| 10 9 | 
             
              test:
         | 
| @@ -19,8 +18,11 @@ jobs: | |
| 19 18 | 
             
                  - name: checkout
         | 
| 20 19 | 
             
                    uses: actions/checkout@v2
         | 
| 21 20 |  | 
| 21 | 
            +
                  - name: setup gems
         | 
| 22 | 
            +
                    run: bundle install
         | 
| 23 | 
            +
             | 
| 22 24 | 
             
                  - name: setup dependencies
         | 
| 23 25 | 
             
                    run: "ruby -I.github/workflows -rutils -e 'setup_dependencies'"
         | 
| 24 26 |  | 
| 25 27 | 
             
                  - name: test
         | 
| 26 | 
            -
                    run: rake test
         | 
| 28 | 
            +
                    run: bundle exec rake test
         | 
    
        data/ChangeLog.md
    CHANGED
    
    | @@ -1,6 +1,24 @@ | |
| 1 1 | 
             
            # processing ChangeLog
         | 
| 2 2 |  | 
| 3 3 |  | 
| 4 | 
            +
            ## [v0.5.31] - 2023-12-09
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            - Add Shape class
         | 
| 7 | 
            +
            - Add createShape(), shape(), shapeMode()
         | 
| 8 | 
            +
            - Add beginShape(), endShape(), and vertex(x, y)
         | 
| 9 | 
            +
            - Test with p5.rb
         | 
| 10 | 
            +
            - GraphicsContext#rotate() can take z parameter
         | 
| 11 | 
            +
            - Set default miter_limit to 10
         | 
| 12 | 
            +
            - Trigger github actions on all pull_request
         | 
| 13 | 
            +
             | 
| 14 | 
            +
             | 
| 15 | 
            +
            ## [v0.5.30] - 2023-11-09
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            - Test drawing methods with p5.rb
         | 
| 18 | 
            +
            - Add .github/workflows/test-draw.yml
         | 
| 19 | 
            +
            - Use Gemfile to install gems for development instead of add_development_dependency in gemspec
         | 
| 20 | 
            +
             | 
| 21 | 
            +
             | 
| 4 22 | 
             
            ## [v0.5.29] - 2023-10-29
         | 
| 5 23 |  | 
| 6 24 | 
             
            - Update dependencies
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            GEM
         | 
| 2 | 
            +
              remote: https://rubygems.org/
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                addressable (2.8.5)
         | 
| 5 | 
            +
                  public_suffix (>= 2.0.2, < 6.0)
         | 
| 6 | 
            +
                concurrent-ruby (1.2.2)
         | 
| 7 | 
            +
                ferrum (0.14)
         | 
| 8 | 
            +
                  addressable (~> 2.5)
         | 
| 9 | 
            +
                  concurrent-ruby (~> 1.1)
         | 
| 10 | 
            +
                  webrick (~> 1.7)
         | 
| 11 | 
            +
                  websocket-driver (>= 0.6, < 0.8)
         | 
| 12 | 
            +
                power_assert (2.0.3)
         | 
| 13 | 
            +
                public_suffix (5.0.3)
         | 
| 14 | 
            +
                rake (13.1.0)
         | 
| 15 | 
            +
                test-unit (3.6.1)
         | 
| 16 | 
            +
                  power_assert
         | 
| 17 | 
            +
                webrick (1.7.0)
         | 
| 18 | 
            +
                websocket-driver (0.7.6)
         | 
| 19 | 
            +
                  websocket-extensions (>= 0.1.0)
         | 
| 20 | 
            +
                websocket-extensions (0.1.5)
         | 
| 21 | 
            +
                yard (0.9.34)
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            PLATFORMS
         | 
| 24 | 
            +
              arm64-darwin-20
         | 
| 25 | 
            +
              arm64-darwin-21
         | 
| 26 | 
            +
              x86_64-darwin-20
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            DEPENDENCIES
         | 
| 29 | 
            +
              ferrum
         | 
| 30 | 
            +
              rake
         | 
| 31 | 
            +
              test-unit
         | 
| 32 | 
            +
              yard
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            BUNDLED WITH
         | 
| 35 | 
            +
               2.3.3
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -14,11 +14,34 @@ require 'reflex/extension' | |
| 14 14 | 
             
            require 'processing/extension'
         | 
| 15 15 |  | 
| 16 16 |  | 
| 17 | 
            +
            def test_with_p5()
         | 
| 18 | 
            +
              ENV['TEST_WITH_P5'] = '1'
         | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
| 17 21 | 
             
            EXTENSIONS = [Xot, Rucy, Rays, Reflex, Processing]
         | 
| 18 22 |  | 
| 19 23 | 
             
            ENV['RDOC'] = 'yardoc --no-private'
         | 
| 20 24 |  | 
| 25 | 
            +
            #test_with_p5 if ci?
         | 
| 26 | 
            +
             | 
| 21 27 | 
             
            default_tasks
         | 
| 28 | 
            +
            use_bundler
         | 
| 22 29 | 
             
            test_ruby_extension
         | 
| 23 30 | 
             
            generate_documents
         | 
| 24 31 | 
             
            build_ruby_gem
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            task :clean => 'test:clean'
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            namespace :test do
         | 
| 36 | 
            +
              task :clean do
         | 
| 37 | 
            +
                sh %( rm -rf test/.png/*.png )
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              task :with_p5 do
         | 
| 41 | 
            +
                test_with_p5
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              ::Rake::TestTask.new :draw do |t|
         | 
| 45 | 
            +
                t.test_files = FileList['test/test_*.rb']
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.5. | 
| 1 | 
            +
            0.5.31
         | 
    
        data/lib/processing/all.rb
    CHANGED
    
    
| @@ -45,15 +45,16 @@ module Processing | |
| 45 45 | 
             
                #
         | 
| 46 46 | 
             
                DEGREES = :degrees
         | 
| 47 47 |  | 
| 48 | 
            -
                # Mode for rectMode(), ellipseMode() and  | 
| 48 | 
            +
                # Mode for rectMode(), ellipseMode(), imageMode(), and shapeMode().
         | 
| 49 49 | 
             
                #
         | 
| 50 50 | 
             
                CORNER  = :corner
         | 
| 51 51 |  | 
| 52 | 
            -
                # Mode for rectMode(), ellipseMode() and  | 
| 52 | 
            +
                # Mode for rectMode(), ellipseMode(), imageMode(), and shapeMode().
         | 
| 53 53 | 
             
                #
         | 
| 54 54 | 
             
                CORNERS = :corners
         | 
| 55 55 |  | 
| 56 | 
            -
                # Mode for rectMode(), ellipseMode(), imageMode()  | 
| 56 | 
            +
                # Mode for rectMode(), ellipseMode(), imageMode(), shapeMode(),
         | 
| 57 | 
            +
                # and textAlign().
         | 
| 57 58 | 
             
                #
         | 
| 58 59 | 
             
                CENTER  = :center
         | 
| 59 60 |  | 
| @@ -140,6 +141,57 @@ module Processing | |
| 140 141 | 
             
                # Filter type for filter()
         | 
| 141 142 | 
             
                BLUR      = :blur
         | 
| 142 143 |  | 
| 144 | 
            +
                # Shape mode for createShape()
         | 
| 145 | 
            +
                LINE     = :line
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                # Shape mode for createShape()
         | 
| 148 | 
            +
                RECT     = :rect
         | 
| 149 | 
            +
             | 
| 150 | 
            +
                # Shape mode for createShape()
         | 
| 151 | 
            +
                ELLIPSE  = :ellipse
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                # Shape mode for createShape()
         | 
| 154 | 
            +
                ARC      = :arc
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                # Shape mode for createShape()
         | 
| 157 | 
            +
                TRIANGLE = :triangle
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                # Shape mode for createShape()
         | 
| 160 | 
            +
                QUAD     = :quad
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                # Shape mode for createShape()
         | 
| 163 | 
            +
                GROUP    = :group
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                # Shape mode for beginShape()
         | 
| 166 | 
            +
                POINTS         = :points
         | 
| 167 | 
            +
             | 
| 168 | 
            +
                # Shape mode for beginShape()
         | 
| 169 | 
            +
                LINES          = :lines
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                # Shape mode for beginShape()
         | 
| 172 | 
            +
                TRIANGLES      = :triangles
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                # Shape mode for beginShape()
         | 
| 175 | 
            +
                TRIANGLE_FAN   = :triangle_fan
         | 
| 176 | 
            +
             | 
| 177 | 
            +
                # Shape mode for beginShape()
         | 
| 178 | 
            +
                TRIANGLE_STRIP = :triangle_strip
         | 
| 179 | 
            +
             | 
| 180 | 
            +
                # Shape mode for beginShape()
         | 
| 181 | 
            +
                QUADS          = :quads
         | 
| 182 | 
            +
             | 
| 183 | 
            +
                # Shape mode for beginShape()
         | 
| 184 | 
            +
                QUAD_STRIP     = :quad_strip
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                # Shape mode for beginShape()
         | 
| 187 | 
            +
                TESS           = :tess
         | 
| 188 | 
            +
             | 
| 189 | 
            +
                # OPEN flag for endShape()
         | 
| 190 | 
            +
                OPEN           = :open
         | 
| 191 | 
            +
             | 
| 192 | 
            +
                # CLOSE flag for endShape()
         | 
| 193 | 
            +
                CLOSE          = :close
         | 
| 194 | 
            +
             | 
| 143 195 | 
             
                # Key codes.
         | 
| 144 196 | 
             
                ENTER     = :enter
         | 
| 145 197 | 
             
                SPACE     = :space
         | 
| @@ -206,6 +258,7 @@ module Processing | |
| 206 258 | 
             
                  @rectMode__    = nil
         | 
| 207 259 | 
             
                  @ellipseMode__ = nil
         | 
| 208 260 | 
             
                  @imageMode__   = nil
         | 
| 261 | 
            +
                  @shapeMode__   = nil
         | 
| 209 262 | 
             
                  @blendMode__   = nil
         | 
| 210 263 | 
             
                  @textAlignH__  = nil
         | 
| 211 264 | 
             
                  @textAlignV__  = nil
         | 
| @@ -222,6 +275,7 @@ module Processing | |
| 222 275 | 
             
                  rectMode    CORNER
         | 
| 223 276 | 
             
                  ellipseMode CENTER
         | 
| 224 277 | 
             
                  imageMode   CORNER
         | 
| 278 | 
            +
                  shapeMode   CORNER
         | 
| 225 279 | 
             
                  blendMode   BLEND
         | 
| 226 280 | 
             
                  strokeCap   ROUND
         | 
| 227 281 | 
             
                  strokeJoin  MITER
         | 
| @@ -235,7 +289,9 @@ module Processing | |
| 235 289 |  | 
| 236 290 | 
             
                # @private
         | 
| 237 291 | 
             
                def updateCanvas__(image, painter)
         | 
| 238 | 
            -
                  @image__, @painter__ | 
| 292 | 
            +
                  @image__, @painter__     = image, painter
         | 
| 293 | 
            +
                  @painter__.miter_limit   = 10
         | 
| 294 | 
            +
                  @painter__.stroke_outset = 0.5
         | 
| 239 295 | 
             
                end
         | 
| 240 296 |  | 
| 241 297 | 
             
                # @private
         | 
| @@ -434,7 +490,7 @@ module Processing | |
| 434 490 | 
             
                end
         | 
| 435 491 |  | 
| 436 492 | 
             
                # @private
         | 
| 437 | 
            -
                def  | 
| 493 | 
            +
                def toDegrees__(angle)
         | 
| 438 494 | 
             
                  angle * @angleScale__
         | 
| 439 495 | 
             
                end
         | 
| 440 496 |  | 
| @@ -460,8 +516,8 @@ module Processing | |
| 460 516 | 
             
                #
         | 
| 461 517 | 
             
                # CORNER  -> rect(left, top, width, height)
         | 
| 462 518 | 
             
                # CORNERS -> rect(left, top, right, bottom)
         | 
| 463 | 
            -
                # CENTER  -> rect( | 
| 464 | 
            -
                # RADIUS  -> rect( | 
| 519 | 
            +
                # CENTER  -> rect(centerX, centerY, width, height)
         | 
| 520 | 
            +
                # RADIUS  -> rect(centerX, centerY, radiusH, radiusV)
         | 
| 465 521 | 
             
                #
         | 
| 466 522 | 
             
                # @param mode [CORNER, CORNERS, CENTER, RADIUS]
         | 
| 467 523 | 
             
                #
         | 
| @@ -475,8 +531,8 @@ module Processing | |
| 475 531 | 
             
                #
         | 
| 476 532 | 
             
                # CORNER  -> ellipse(left, top, width, height)
         | 
| 477 533 | 
             
                # CORNERS -> ellipse(left, top, right, bottom)
         | 
| 478 | 
            -
                # CENTER  -> ellipse( | 
| 479 | 
            -
                # RADIUS  -> ellipse( | 
| 534 | 
            +
                # CENTER  -> ellipse(centerX, centerY, width, height)
         | 
| 535 | 
            +
                # RADIUS  -> ellipse(centerX, centerY, radiusH, radiusV)
         | 
| 480 536 | 
             
                #
         | 
| 481 537 | 
             
                # @param mode [CORNER, CORNERS, CENTER, RADIUS]
         | 
| 482 538 | 
             
                #
         | 
| @@ -490,7 +546,7 @@ module Processing | |
| 490 546 | 
             
                #
         | 
| 491 547 | 
             
                # CORNER  -> image(img, left, top, width, height)
         | 
| 492 548 | 
             
                # CORNERS -> image(img, left, top, right, bottom)
         | 
| 493 | 
            -
                # CENTER  -> image(img,  | 
| 549 | 
            +
                # CENTER  -> image(img, centerX, centerY, width, height)
         | 
| 494 550 | 
             
                #
         | 
| 495 551 | 
             
                # @param mode [CORNER, CORNERS, CENTER]
         | 
| 496 552 | 
             
                #
         | 
| @@ -500,6 +556,20 @@ module Processing | |
| 500 556 | 
             
                  @imageMode__ = mode
         | 
| 501 557 | 
             
                end
         | 
| 502 558 |  | 
| 559 | 
            +
                # Sets shape mode. Default is CORNER.
         | 
| 560 | 
            +
                #
         | 
| 561 | 
            +
                # CORNER  -> shape(shp, left, top, width, height)
         | 
| 562 | 
            +
                # CORNERS -> shape(shp, left, top, right, bottom)
         | 
| 563 | 
            +
                # CENTER  -> shape(shp, centerX, centerY, width, height)
         | 
| 564 | 
            +
                #
         | 
| 565 | 
            +
                # @param mode [CORNER, CORNERS, CENTER]
         | 
| 566 | 
            +
                #
         | 
| 567 | 
            +
                # @return [nil] nil
         | 
| 568 | 
            +
                #
         | 
| 569 | 
            +
                def shapeMode(mode)
         | 
| 570 | 
            +
                  @shapeMode__ = mode
         | 
| 571 | 
            +
                end
         | 
| 572 | 
            +
             | 
| 503 573 | 
             
                # @private
         | 
| 504 574 | 
             
                private def toXYWH__(mode, a, b, c, d)
         | 
| 505 575 | 
             
                  case mode
         | 
| @@ -924,9 +994,8 @@ module Processing | |
| 924 994 | 
             
                def arc(a, b, c, d, start, stop)
         | 
| 925 995 | 
             
                  assertDrawing__
         | 
| 926 996 | 
             
                  x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
         | 
| 927 | 
            -
                   | 
| 928 | 
            -
                   | 
| 929 | 
            -
                  @painter__.ellipse x, y, w, h, from: start, to: stop
         | 
| 997 | 
            +
                  from, to   = toDegrees__(-start), toDegrees__(-stop)
         | 
| 998 | 
            +
                  @painter__.ellipse x, y, w, h, from: from, to: to
         | 
| 930 999 | 
             
                  nil
         | 
| 931 1000 | 
             
                end
         | 
| 932 1001 |  | 
| @@ -1094,6 +1163,98 @@ module Processing | |
| 1094 1163 |  | 
| 1095 1164 | 
             
                alias drawImage image
         | 
| 1096 1165 |  | 
| 1166 | 
            +
                # Draws a shape.
         | 
| 1167 | 
            +
                #
         | 
| 1168 | 
            +
                # The parameters a, b, c, and d are determined by shapeMode().
         | 
| 1169 | 
            +
                #
         | 
| 1170 | 
            +
                # @overload shape(img, a, b)
         | 
| 1171 | 
            +
                # @overload shape(img, a, b, c, d)
         | 
| 1172 | 
            +
                #
         | 
| 1173 | 
            +
                # @param shp [Shape] shape to draw
         | 
| 1174 | 
            +
                # @param a   [Numeric] horizontal position of the shape, by default
         | 
| 1175 | 
            +
                # @param b   [Numeric] vertical position of the shape, by default
         | 
| 1176 | 
            +
                # @param c   [Numeric] width of the shape, by default
         | 
| 1177 | 
            +
                # @param d   [Numeric] height of the shape, by default
         | 
| 1178 | 
            +
                #
         | 
| 1179 | 
            +
                # @return [nil] nil
         | 
| 1180 | 
            +
                #
         | 
| 1181 | 
            +
                def shape(shp, a = 0, b = 0, c = nil, d = nil)
         | 
| 1182 | 
            +
                  assertDrawing__
         | 
| 1183 | 
            +
                  return nil unless shp.isVisible
         | 
| 1184 | 
            +
             | 
| 1185 | 
            +
                  if c || d || @shapeMode__ != CORNER
         | 
| 1186 | 
            +
                    x, y, w, h = toXYWH__ @shapeMode__, a, b, c || shp.width, d || shp.height
         | 
| 1187 | 
            +
                    shp.draw__ @painter__, x, y, w, h
         | 
| 1188 | 
            +
                  else
         | 
| 1189 | 
            +
                    shp.draw__ @painter__, a, b
         | 
| 1190 | 
            +
                  end
         | 
| 1191 | 
            +
                  nil
         | 
| 1192 | 
            +
                end
         | 
| 1193 | 
            +
             | 
| 1194 | 
            +
                alias drawShape shape
         | 
| 1195 | 
            +
             | 
| 1196 | 
            +
                # Begins drawing complex shapes.
         | 
| 1197 | 
            +
                #
         | 
| 1198 | 
            +
                # @param mode [POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, QUAD_STRIP, TESS]
         | 
| 1199 | 
            +
                #
         | 
| 1200 | 
            +
                # @return [nil] nil
         | 
| 1201 | 
            +
                #
         | 
| 1202 | 
            +
                # @example
         | 
| 1203 | 
            +
                #  # Draws polygon
         | 
| 1204 | 
            +
                #  beginShape
         | 
| 1205 | 
            +
                #  vertex 10, 10
         | 
| 1206 | 
            +
                #  vertex 10, 50
         | 
| 1207 | 
            +
                #  vertex 50, 50
         | 
| 1208 | 
            +
                #  vertex 90, 10
         | 
| 1209 | 
            +
                #  endShape CLOSE
         | 
| 1210 | 
            +
                #
         | 
| 1211 | 
            +
                #  # Draws triangles
         | 
| 1212 | 
            +
                #  beginShape TRIANGLES
         | 
| 1213 | 
            +
                #  vertex 10, 10
         | 
| 1214 | 
            +
                #  vertex 10, 50
         | 
| 1215 | 
            +
                #  vertex 50, 50
         | 
| 1216 | 
            +
                #  endShape
         | 
| 1217 | 
            +
                #
         | 
| 1218 | 
            +
                # @see https://processing.org/reference/beginShape_.html
         | 
| 1219 | 
            +
                #
         | 
| 1220 | 
            +
                def beginShape(mode = nil)
         | 
| 1221 | 
            +
                  @shapeMode__, @shapePoints__ = mode, []
         | 
| 1222 | 
            +
                  nil
         | 
| 1223 | 
            +
                end
         | 
| 1224 | 
            +
             | 
| 1225 | 
            +
                # Ends drawing complex shapes.
         | 
| 1226 | 
            +
                #
         | 
| 1227 | 
            +
                # @overload endShape()
         | 
| 1228 | 
            +
                # @overload endShape(CLOSE)
         | 
| 1229 | 
            +
                #
         | 
| 1230 | 
            +
                # @param mode [CLOSE] Use CLOSE to create looped polygon
         | 
| 1231 | 
            +
                #
         | 
| 1232 | 
            +
                # @return [nil] nil
         | 
| 1233 | 
            +
                #
         | 
| 1234 | 
            +
                # @see https://processing.org/reference/endShape_.html
         | 
| 1235 | 
            +
                #
         | 
| 1236 | 
            +
                def endShape(mode = nil)
         | 
| 1237 | 
            +
                  raise "endShape() must be called after beginShape()" unless @shapePoints__
         | 
| 1238 | 
            +
                  polygon = Shape.createPolygon__ @shapeMode__, @shapePoints__, mode == CLOSE
         | 
| 1239 | 
            +
                  @painter__.polygon polygon if polygon
         | 
| 1240 | 
            +
                  @shapeMode__ = @shapePoints__ = nil
         | 
| 1241 | 
            +
                  nil
         | 
| 1242 | 
            +
                end
         | 
| 1243 | 
            +
             | 
| 1244 | 
            +
                # Append vertex for shape polygon.
         | 
| 1245 | 
            +
                #
         | 
| 1246 | 
            +
                # @param x [Numeric] x position of vertex
         | 
| 1247 | 
            +
                # @param y [Numeric] y position of vertex
         | 
| 1248 | 
            +
                #
         | 
| 1249 | 
            +
                # @return [nil] nil
         | 
| 1250 | 
            +
                #
         | 
| 1251 | 
            +
                # @see https://processing.org/reference/vertex_.html
         | 
| 1252 | 
            +
                #
         | 
| 1253 | 
            +
                def vertex(x, y)
         | 
| 1254 | 
            +
                  raise "vertex() must be called after beginShape()" unless @shapePoints__
         | 
| 1255 | 
            +
                  @shapePoints__ << x << y
         | 
| 1256 | 
            +
                end
         | 
| 1257 | 
            +
             | 
| 1097 1258 | 
             
                # Copies image.
         | 
| 1098 1259 | 
             
                #
         | 
| 1099 1260 | 
             
                # @overload copy(sx, sy, sw, sh, dx, dy, dw, dh)
         | 
| @@ -1181,9 +1342,9 @@ module Processing | |
| 1181 1342 | 
             
                #
         | 
| 1182 1343 | 
             
                # @return [nil] nil
         | 
| 1183 1344 | 
             
                #
         | 
| 1184 | 
            -
                def scale(x, y)
         | 
| 1345 | 
            +
                def scale(x, y = nil, z = 1)
         | 
| 1185 1346 | 
             
                  assertDrawing__
         | 
| 1186 | 
            -
                  @painter__.scale x, y
         | 
| 1347 | 
            +
                  @painter__.scale x, (y || x), z
         | 
| 1187 1348 | 
             
                  nil
         | 
| 1188 1349 | 
             
                end
         | 
| 1189 1350 |  | 
| @@ -1195,7 +1356,7 @@ module Processing | |
| 1195 1356 | 
             
                #
         | 
| 1196 1357 | 
             
                def rotate(angle)
         | 
| 1197 1358 | 
             
                  assertDrawing__
         | 
| 1198 | 
            -
                  @painter__.rotate  | 
| 1359 | 
            +
                  @painter__.rotate toDegrees__ angle
         | 
| 1199 1360 | 
             
                  nil
         | 
| 1200 1361 | 
             
                end
         | 
| 1201 1362 |  | 
| @@ -1254,6 +1415,7 @@ module Processing | |
| 1254 1415 | 
             
                    @rectMode__,
         | 
| 1255 1416 | 
             
                    @ellipseMode__,
         | 
| 1256 1417 | 
             
                    @imageMode__,
         | 
| 1418 | 
            +
                    @shapeMode__,
         | 
| 1257 1419 | 
             
                    @textAlignH__,
         | 
| 1258 1420 | 
             
                    @textAlignV__,
         | 
| 1259 1421 | 
             
                    @tint__,
         | 
| @@ -1285,6 +1447,7 @@ module Processing | |
| 1285 1447 | 
             
                  @rectMode__,
         | 
| 1286 1448 | 
             
                  @ellipseMode__,
         | 
| 1287 1449 | 
             
                  @imageMode__,
         | 
| 1450 | 
            +
                  @shapeMode__,
         | 
| 1288 1451 | 
             
                  @textAlignH__,
         | 
| 1289 1452 | 
             
                  @textAlignV__,
         | 
| 1290 1453 | 
             
                  @tint__ = @styleStack__.pop
         | 
| @@ -1732,6 +1895,67 @@ module Processing | |
| 1732 1895 | 
             
                  Image.new Rays::Image.new(w, h, colorspace).paint {background 0, 0}
         | 
| 1733 1896 | 
             
                end
         | 
| 1734 1897 |  | 
| 1898 | 
            +
                # Creates a new shape.
         | 
| 1899 | 
            +
                #
         | 
| 1900 | 
            +
                # @overload createShape()
         | 
| 1901 | 
            +
                # @overload createShape(LINE, x1, y1, x2, y2)
         | 
| 1902 | 
            +
                # @overload createShape(RECT, a, b, c, d)
         | 
| 1903 | 
            +
                # @overload createShape(ELLIPSE, a, b, c, d)
         | 
| 1904 | 
            +
                # @overload createShape(ARC, a, b, c, d, start, stop)
         | 
| 1905 | 
            +
                # @overload createShape(TRIANGLE, x1, y1, x2, y2, x3, y3)
         | 
| 1906 | 
            +
                # @overload createShape(QUAD, x1, y1, x2, y2, x3, y3, x4, y4)
         | 
| 1907 | 
            +
                # @overload createShape(GROUP)
         | 
| 1908 | 
            +
                #
         | 
| 1909 | 
            +
                # @param kind [LINE, RECT, ELLIPSE, ARC, TRIANGLE, QUAD, GROUP]
         | 
| 1910 | 
            +
                #
         | 
| 1911 | 
            +
                def createShape(kind = nil, *args)
         | 
| 1912 | 
            +
                  case kind
         | 
| 1913 | 
            +
                  when LINE     then createLineShape__(    *args)
         | 
| 1914 | 
            +
                  when RECT     then createRectShape__(    *args)
         | 
| 1915 | 
            +
                  when ELLIPSE  then createEllipseShape__( *args)
         | 
| 1916 | 
            +
                  when ARC      then createArcShape__(     *args)
         | 
| 1917 | 
            +
                  when TRIANGLE then createTriangleShape__(*args)
         | 
| 1918 | 
            +
                  when QUAD     then createQuadShape__(    *args)
         | 
| 1919 | 
            +
                  when GROUP    then Shape.new nil, [], context: self
         | 
| 1920 | 
            +
                  when nil      then Shape.new context: self
         | 
| 1921 | 
            +
                  else raise ArgumentError, "Unknown shape kind '#{kind}'"
         | 
| 1922 | 
            +
                  end
         | 
| 1923 | 
            +
                end
         | 
| 1924 | 
            +
             | 
| 1925 | 
            +
                # @private
         | 
| 1926 | 
            +
                private def createLineShape__(x1, y1, x2, y2)
         | 
| 1927 | 
            +
                  Shape.new Rays::Polygon.lines(x1, y1, x2, y2), context: self
         | 
| 1928 | 
            +
                end
         | 
| 1929 | 
            +
             | 
| 1930 | 
            +
                # @private
         | 
| 1931 | 
            +
                private def createRectShape__(a, b, c, d)
         | 
| 1932 | 
            +
                  x, y, w, h = toXYWH__ @rectMode__, a, b, c, d
         | 
| 1933 | 
            +
                  Shape.new Rays::Polygon.rect(x, y, w, h), context: self
         | 
| 1934 | 
            +
                end
         | 
| 1935 | 
            +
             | 
| 1936 | 
            +
                # @private
         | 
| 1937 | 
            +
                private def createEllipseShape__(a, b, c, d)
         | 
| 1938 | 
            +
                  x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
         | 
| 1939 | 
            +
                  Shape.new Rays::Polygon.ellipse(x, y, w, h), context: self
         | 
| 1940 | 
            +
                end
         | 
| 1941 | 
            +
             | 
| 1942 | 
            +
                # @private
         | 
| 1943 | 
            +
                private def createArcShape__(a, b, c, d, start, stop)
         | 
| 1944 | 
            +
                  x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
         | 
| 1945 | 
            +
                  from, to   = toDegrees__(-start), toDegrees__(-stop)
         | 
| 1946 | 
            +
                  Shape.new Rays::Polygon.ellipse(x, y, w, h, from: from, to: to), context: self
         | 
| 1947 | 
            +
                end
         | 
| 1948 | 
            +
             | 
| 1949 | 
            +
                # @private
         | 
| 1950 | 
            +
                private def createTriangleShape__(x1, y1, x2, y2, x3, y3)
         | 
| 1951 | 
            +
                  Shape.new Rays::Polygon.new(x1, y1, x2, y2, x3, y3, loop: true), context: self
         | 
| 1952 | 
            +
                end
         | 
| 1953 | 
            +
             | 
| 1954 | 
            +
                # @private
         | 
| 1955 | 
            +
                private def createQuadShape__(x1, y1, x2, y2, x3, y3, x4, y4)
         | 
| 1956 | 
            +
                  Shape.new Rays::Polygon.quads(x1, y1, x2, y2, x3, y3, x4, y4), context: self
         | 
| 1957 | 
            +
                end
         | 
| 1958 | 
            +
             | 
| 1735 1959 | 
             
                # Creates a new off-screen graphics context object.
         | 
| 1736 1960 | 
             
                #
         | 
| 1737 1961 | 
             
                # @param width        [Numeric] width of graphics image
         |