├── lib ├── .gitignore ├── propane │ ├── version.rb │ ├── helpers │ │ ├── version_error.rb │ │ └── numeric.rb │ ├── creators │ │ ├── sketch_factory.rb │ │ ├── sketch_writer.rb │ │ └── sketch_class.rb │ ├── native_loader.rb │ ├── native_folder.rb │ ├── library_loader.rb │ ├── library.rb │ ├── runner.rb │ └── app.rb ├── propane.rb └── export.txt ├── .yardopts ├── Gemfile ├── src └── main │ ├── resources │ ├── cursors │ │ ├── arrow.png │ │ ├── cross.png │ │ ├── hand.png │ │ ├── move.png │ │ ├── text.png │ │ ├── wait.png │ │ └── license.txt │ ├── icon │ │ ├── icon-1024.png │ │ ├── icon-128.png │ │ ├── icon-16.png │ │ ├── icon-256.png │ │ ├── icon-32.png │ │ ├── icon-48.png │ │ ├── icon-512.png │ │ └── icon-64.png │ └── shaders │ │ ├── ColorFrag.glsl │ │ ├── LineFrag.glsl │ │ ├── PointFrag.glsl │ │ ├── ColorVert.glsl │ │ ├── LightFrag.glsl │ │ ├── TexFrag.glsl │ │ ├── TexLightFrag.glsl │ │ ├── TexVert.glsl │ │ ├── MaskFrag.glsl │ │ ├── PointVert.glsl │ │ ├── LineVert.glsl │ │ ├── LightVert.glsl │ │ └── TexLightVert.glsl │ └── java │ ├── japplemenubar │ ├── libjAppleMenuBar.jnilib │ └── JAppleMenuBar.java │ ├── monkstone │ ├── fastmath │ │ ├── package-info.java │ │ ├── Deglut.java │ │ └── DegLutTables.java │ ├── vecmath │ │ ├── vec2 │ │ │ └── package-info.java │ │ ├── vec3 │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── JRender.java │ │ ├── GfxRender.java │ │ └── ShapeRender.java │ ├── videoevent │ │ ├── package-info.java │ │ ├── CaptureEvent.java │ │ └── MovieEvent.java │ ├── slider │ │ ├── Slider.java │ │ ├── WheelHandler.java │ │ ├── SliderGroup.java │ │ ├── SimpleSlider.java │ │ ├── SimpleHorizontalSlider.java │ │ ├── SimpleVerticalSlider.java │ │ ├── CustomHorizontalSlider.java │ │ └── CustomVerticalSlider.java │ ├── filechooser │ │ └── Chooser.java │ ├── PropaneLibrary.java │ ├── core │ │ └── LibraryProxy.java │ ├── ColorUtil.java │ └── FastNoiseModuleJava.java │ └── processing │ ├── javafx │ └── PGraphicsFX2D.java │ ├── data │ ├── Sort.java │ └── TableRow.java │ ├── core │ ├── PStyle.java │ └── ThinkDifferent.java │ ├── event │ ├── KeyEvent.java │ ├── TouchEvent.java │ ├── MouseEvent.java │ └── Event.java │ └── opengl │ └── VertexBuffer.java ├── .travis.yml ├── library ├── dxf │ └── dxf.rb ├── net │ └── net.rb ├── svg │ └── svg.rb ├── pdf │ └── pdf.rb ├── video_event │ └── video_event.rb ├── file_chooser │ ├── chooser.rb │ └── file_chooser.rb ├── color_group │ └── color_group.rb ├── library_proxy │ ├── library_proxy.rb │ └── README.md ├── slider │ └── slider.rb ├── vector_utils │ └── vector_utils.rb ├── boids │ └── boids.rb └── control_panel │ └── control_panel.rb ├── test ├── test_helper.rb ├── deglut_spec_test.rb ├── sketches │ ├── key_event.rb │ └── library │ │ └── my_library │ │ └── my_library.rb ├── native_folder.rb ├── create_test.rb ├── helper_methods_test.rb ├── math_tool_test.rb └── respond_to_test.rb ├── .mvn ├── extensions.xml └── wrapper │ ├── maven-wrapper.properties │ └── MavenWrapperDownloader.java ├── bin └── propane ├── .gitignore ├── .github ├── ISSUE_TEMPLATE.md └── CONTRIBUTING.md ├── Rakefile ├── propane.gemspec ├── vendors └── Rakefile ├── README.md └── pom.rb /lib/.gitignore: -------------------------------------------------------------------------------- 1 | core.jar 2 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | --markup markdown 2 | - 3 | CHANGELOG.md 4 | LICENSE.md 5 | README.md 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /lib/propane/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Propane 4 | VERSION = '4.0.0' 5 | end 6 | -------------------------------------------------------------------------------- /src/main/resources/cursors/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/cursors/arrow.png -------------------------------------------------------------------------------- /src/main/resources/cursors/cross.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/cursors/cross.png -------------------------------------------------------------------------------- /src/main/resources/cursors/hand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/cursors/hand.png -------------------------------------------------------------------------------- /src/main/resources/cursors/move.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/cursors/move.png -------------------------------------------------------------------------------- /src/main/resources/cursors/text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/cursors/text.png -------------------------------------------------------------------------------- /src/main/resources/cursors/wait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/cursors/wait.png -------------------------------------------------------------------------------- /src/main/resources/icon/icon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/icon/icon-1024.png -------------------------------------------------------------------------------- /src/main/resources/icon/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/icon/icon-128.png -------------------------------------------------------------------------------- /src/main/resources/icon/icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/icon/icon-16.png -------------------------------------------------------------------------------- /src/main/resources/icon/icon-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/icon/icon-256.png -------------------------------------------------------------------------------- /src/main/resources/icon/icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/icon/icon-32.png -------------------------------------------------------------------------------- /src/main/resources/icon/icon-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/icon/icon-48.png -------------------------------------------------------------------------------- /src/main/resources/icon/icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/icon/icon-512.png -------------------------------------------------------------------------------- /src/main/resources/icon/icon-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/resources/icon/icon-64.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | dist: bionic 3 | 4 | rvm: 5 | - jruby-9.2.17.0 6 | jdk: 7 | - openjdk11 8 | os: 9 | - linux 10 | -------------------------------------------------------------------------------- /library/dxf/dxf.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # @TODO usage 4 | class Propane::App 5 | java_import Java::ProcessingDxf::RawDXF 6 | end 7 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jruby' 4 | gem 'minitest' 5 | require 'minitest/pride' 6 | require 'minitest/autorun' 7 | -------------------------------------------------------------------------------- /src/main/java/japplemenubar/libjAppleMenuBar.jnilib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-processing/propane/HEAD/src/main/java/japplemenubar/libjAppleMenuBar.jnilib -------------------------------------------------------------------------------- /library/net/net.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # @TODO usage 4 | class Propane::App 5 | java_import Java::ProcessingNet::Client 6 | java_import Java::ProcessingNet::Server 7 | end 8 | -------------------------------------------------------------------------------- /library/svg/svg.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # @TODO usage 4 | class Propane::App 5 | require_relative 'batik-all-1.14.jar' 6 | java_import Java::ProcessingSvg::PGraphicsSVG 7 | end 8 | -------------------------------------------------------------------------------- /library/pdf/pdf.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # @TODO usage 4 | class Propane::App 5 | require_relative 'itextpdf-5.5.13.2.jar' 6 | java_import Java::ProcessingPdf::PGraphicsPDF 7 | end 8 | -------------------------------------------------------------------------------- /library/video_event/video_event.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Propane::App 4 | include Java::MonkstoneVideoevent::CaptureEvent 5 | include Java::MonkstoneVideoevent::MovieEvent 6 | end 7 | -------------------------------------------------------------------------------- /lib/propane/helpers/version_error.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class JDKVersionError < StandardError 4 | def message 5 | 'This version of propane requires at least JDK11 to work' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/propane/helpers/numeric.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Numeric #:nodoc: 4 | def degrees 5 | self * 57.29577951308232 6 | end 7 | 8 | def radians 9 | self * 0.017453292519943295 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | io.takari.polyglot 5 | polyglot-ruby 6 | 0.4.8 7 | 8 | 9 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.3/apache-maven-3.8.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /src/main/java/monkstone/fastmath/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package monkstone.fastmath; 7 | -------------------------------------------------------------------------------- /src/main/java/monkstone/vecmath/vec2/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package monkstone.vecmath.vec2; 7 | -------------------------------------------------------------------------------- /src/main/java/monkstone/vecmath/vec3/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package monkstone.vecmath.vec3; 7 | -------------------------------------------------------------------------------- /bin/propane: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env jruby 2 | # frozen_string_literal: true 3 | 4 | unless defined? PROPANE_ROOT 5 | $LOAD_PATH << __dir__ 6 | PROPANE_ROOT = File.expand_path(File.dirname(__FILE__) + '/../') 7 | end 8 | 9 | require "#{PROPANE_ROOT}/lib/propane/runner" 10 | Propane::Runner.execute 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.log 3 | *.gem 4 | *.rbc 5 | .bundle 6 | .config 7 | .yardoc 8 | Gemfile.lock 9 | InstalledFiles 10 | _yardoc 11 | coverage 12 | doc/ 13 | lib/bundler/man 14 | pkg 15 | rdoc 16 | spec/reports 17 | test/tmp 18 | test/version_tmp 19 | target 20 | *.jar 21 | *~ 22 | MANIFEST.MF 23 | nb-configuration.xml 24 | 25 | -------------------------------------------------------------------------------- /lib/propane.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'java' 4 | unless defined? PROPANE_ROOT 5 | $LOAD_PATH << File.dirname(__dir__) 6 | PROPANE_ROOT = File.dirname(__dir__) 7 | end 8 | Dir["#{PROPANE_ROOT}/lib/*.jar"].sort.each do |jar| 9 | require jar 10 | end 11 | require "#{PROPANE_ROOT}/lib/propane/app" 12 | require "#{PROPANE_ROOT}/lib/propane/helpers/numeric" -------------------------------------------------------------------------------- /lib/propane/creators/sketch_factory.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'sketch_writer' 4 | 5 | class SketchFactory 6 | NAMES = %w[One Two Three].freeze 7 | def initialize(_argc) 8 | NAMES.each do |name| 9 | SketchWriter.new(File.basename(name, '.rb'), width: 300, height: 300).write 10 | end 11 | end 12 | end 13 | 14 | SketchFactory.new(File.join(ENV['HOME'], 'test')) 15 | -------------------------------------------------------------------------------- /library/file_chooser/chooser.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Usage: :wq 4 | # load_library :chooser 5 | # 6 | # def setup 7 | # java_signature 'void selectInput(String, String)' 8 | # selectInput('Select a file to process:', 'fileSelected') 9 | # end 10 | # 11 | # def fileSelected(selection) 12 | # if selection.nil? 13 | # puts 'Window was closed or the user hit cancel.' 14 | # else 15 | # puts format('User selected %s', selection.get_absolute_path) 16 | # end 17 | # end 18 | class Propane::App 19 | include Java::MonkstoneFilechooser::Chooser 20 | Chooser 21 | end 22 | -------------------------------------------------------------------------------- /library/file_chooser/file_chooser.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Usage: 4 | # load_library :file_chooser 5 | # class ... 6 | # def setup 7 | # java_signature 'void selectInput(String, String)' 8 | # selectInput('Select a file to process:', 'fileSelected') 9 | # end 10 | # 11 | # def fileSelected(selection) 12 | # if selection.nil? 13 | # puts 'Window was closed or the user hit cancel.' 14 | # else 15 | # puts format('User selected %s', selection.get_absolute_path) 16 | # end 17 | # end 18 | # ... 19 | class Propane::App 20 | include Java::MonkstoneFilechooser::Chooser 21 | end 22 | -------------------------------------------------------------------------------- /lib/propane/creators/sketch_writer.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: false 2 | 3 | require_relative 'sketch_class' 4 | 5 | # The file writer can write a sketch when given instance of Sketch type 6 | class SketchWriter 7 | attr_reader :file, :sketch 8 | 9 | def initialize(path, args) 10 | @sketch = SketchClass.new( 11 | name: path, 12 | width: args[0].to_i, 13 | height: args[1].to_i, 14 | mode: args[2] 15 | ) 16 | @file = format('%s/%s.rb', File.dirname(path), path) 17 | end 18 | 19 | def write 20 | File.open(file, 'w+') { |f| f.write sketch.lines.join("\n") } 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /test/deglut_spec_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'test_helper' 4 | require 'java' 5 | require_relative '../lib/propane' 6 | 7 | Dir.chdir(File.dirname(__FILE__)) 8 | 9 | class DeglutTest < Minitest::Test 10 | attr_reader :to_radian 11 | 12 | def setup 13 | @to_radian = Math::PI / 180 14 | end 15 | 16 | def test_cos_sin 17 | (-720..720).step(1) do |deg| 18 | sine = DegLut.sin(deg) 19 | deg_sin = Math.sin(deg * to_radian) 20 | assert_in_delta(sine, deg_sin, 0.0003) 21 | cosine = DegLut.cos(deg) 22 | deg_cos = Math.cos(deg * to_radian) 23 | assert_in_delta(cosine, deg_cos, 0.0003) 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /library/color_group/color_group.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | java_import Java::Monkstone::ColorUtil 4 | 5 | # class wraps a java color array, supports shuffle!, last and ruby_string 6 | # as well as ability to initialize with an array of "web" color string 7 | class ColorGroup 8 | attr_reader :colors 9 | def initialize(p5cols) 10 | @colors = p5cols 11 | end 12 | 13 | def self.from_web_array(web) 14 | ColorGroup.new(ColorUtil.web_array(web.to_java(:string))) 15 | end 16 | 17 | def shuffle! 18 | @colors = ColorUtil.shuffle(colors) 19 | end 20 | 21 | def ruby_string 22 | ColorUtil.rubyString(colors) 23 | end 24 | 25 | def last 26 | colors[0] 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /library/library_proxy/library_proxy.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | java_import Java::MonkstoneCore::LibraryProxy 4 | java_import Java::ProcessingEvent::KeyEvent 5 | java_import Java::ProcessingEvent::MouseEvent 6 | 7 | # classes that inherit from LibraryProxy are expected to implement 8 | # the abstract draw method of monkstone.core.LibraryProxy the other methods are 9 | # registered with PApplet instance in constructor ImplementingClass.new(app) 10 | # 11 | # def pre... NOOP can be overridden 12 | # def draw... Abstract Method should be implemented NOOP is OK 13 | # def post... NOOP can be overridden 14 | # def keyEvent(e)... NOOP can be overridden 15 | # def mouseEvent(e)... NOOP can be overridden 16 | # `app` can be called to get PApplet instance 17 | -------------------------------------------------------------------------------- /test/sketches/key_event.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env jruby 2 | # frozen_string_literal: true 3 | 4 | require 'propane' 5 | 6 | class CustomProxySketch < Propane::App 7 | # A simple demonstration of vanilla processing 'reflection' methods using 8 | # propane :library_proxy. See my_library.rb code for the guts. 9 | load_libraries :library_proxy, :my_library 10 | 11 | attr_reader :visible 12 | 13 | def settings 14 | size 300, 200 15 | @visible = false 16 | end 17 | 18 | def setup 19 | sketch_title 'Reflection Voodoo Proxy' 20 | MyLibrary.new self 21 | end 22 | 23 | def hide(val) 24 | @visible = !val 25 | end 26 | 27 | def draw 28 | if visible 29 | fill(0, 0, 200) 30 | ellipse(170, 115, 70, 100) 31 | else 32 | background 0 33 | end 34 | end 35 | end 36 | 37 | CustomProxySketch.new 38 | -------------------------------------------------------------------------------- /src/main/java/monkstone/vecmath/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-22 Martin Prout 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * http://creativecommons.org/licenses/LGPL/2.1/ 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package monkstone.vecmath; 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 8 | 9 | ### Environment 10 | 11 | Ensure that you are using the recommended versions of jruby (`jruby -v`) and java (`java -version`) 12 | Provide Propane version that you are using (`propane --version`) 13 | Provide your operating system and platform (e.g. `uname -a`, and/or `java -version` output if relevant) 14 | 15 | ### Expected Behavior 16 | 17 | Describe your expectation of how Propane sketch should behave. 18 | Provide a `problematic` Propane sketch or a link to an example repository. 19 | 20 | ### Actual Behavior 21 | 22 | Describe or show the actual behavior. 23 | Provide text or screen capture showing the behavior. 24 | 25 | ### Other 26 | 27 | eg installation issue (just use this header and explain the problem as best you can) 28 | -------------------------------------------------------------------------------- /src/main/java/monkstone/videoevent/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-22 Martin Prout 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * http://creativecommons.org/licenses/LGPL/2.1/ 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package monkstone.videoevent; 21 | -------------------------------------------------------------------------------- /lib/propane/native_loader.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This class knows how to dynamically set the 'java' native library path 4 | # It might not work with java 9? 5 | class NativeLoader 6 | attr_reader :separator, :current_path 7 | 8 | # This module wraps java_import with namespace JC 9 | module JC 10 | java_import 'java.lang.Class' 11 | java_import 'java.lang.System' 12 | java_import 'java.io.File' 13 | end 14 | 15 | def initialize 16 | @separator = JC::File.pathSeparatorChar 17 | @current_path = JC::System.getProperty('java.library.path') 18 | end 19 | 20 | def add_native_path(pth) 21 | current_path << separator << pth 22 | JC::System.setProperty('java.library.path', current_path) 23 | field = JC::Class.for_name('java.lang.ClassLoader') 24 | .get_declared_field('sys_paths') 25 | return unless field 26 | 27 | field.accessible = true # some jruby magic 28 | field.set(JC::Class.for_name('java.lang.System').get_class_loader, nil) 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /test/sketches/library/my_library/my_library.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This class demonstrates how by inheriting from the abstract class LibraryProxy 4 | # we can access 'keyEvent' and 'draw' (Note we need a draw method even 5 | # though can be empty) 6 | class MyLibrary < LibraryProxy 7 | java_import 'processing.event.KeyEvent' 8 | 9 | attr_reader :app 10 | 11 | def initialize(parent) 12 | @app = parent 13 | end 14 | 15 | def draw # optional 16 | fill app.color(200, 0, 0, 100) 17 | app.rect 100, 100, 60, 90 18 | end 19 | 20 | # favor guard clause no_op unless key pressed 21 | # and no_op unless ascii key 22 | def keyEvent(e) # NB: need camel case for reflection to work 23 | return unless e.get_action == KeyEvent::PRESS 24 | return if e.get_key > 122 # else we can't use :chr 25 | 26 | case e.get_key.chr.upcase 27 | when 'S' 28 | app.send :hide, false 29 | when 'H' 30 | app.send :hide, true 31 | else 32 | puts e.get_key.chr 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/propane/native_folder.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rbconfig' 4 | 5 | # Utility to load native binaries on Java CLASSPATH 6 | class NativeFolder 7 | attr_reader :os, :bit 8 | 9 | WIN_FORMAT = 'windows%d' 10 | LINUX_FORMAT = 'linux%d' 11 | WIN_PATTERNS = [ 12 | /bccwin/i, 13 | /cygwin/i, 14 | /djgpp/i, 15 | /ming/i, 16 | /mswin/i, 17 | /wince/i 18 | ].freeze 19 | 20 | def initialize 21 | @os = RbConfig::CONFIG['host_os'].downcase 22 | @bit = /64/.match?(java.lang.System.get_property('os.arch')) ? 64 : 32 23 | end 24 | 25 | def name 26 | return 'macosx' if /darwin|mac/.match?(os) 27 | return format(LINUX_FORMAT, bit) if /linux/.match?(os) 28 | return format(WIN_FORMAT, bit) if WIN_PATTERNS.any? { |pat| pat.match?(os) } 29 | 30 | raise 'Unsupported Architecture' 31 | end 32 | 33 | def extension 34 | return '*.so' if /linux/.match?(os) 35 | return '*.dll' if WIN_PATTERNS.any? { |pat| pat.match?(os) } 36 | 37 | '*.dylib' # MacOS 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /src/main/java/monkstone/slider/Slider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package monkstone.slider; 7 | 8 | /** 9 | * 10 | * @author tux 11 | */ 12 | public interface Slider { 13 | 14 | void dispose(); 15 | 16 | void draw(); 17 | 18 | /** 19 | * 20 | */ 21 | void hideBackground(); 22 | 23 | /** 24 | * 25 | */ 26 | void hideLabel(); 27 | 28 | /** 29 | * 30 | */ 31 | void hideNumbers(); 32 | 33 | /** 34 | * 35 | * @param s 36 | */ 37 | void labelSize(int s); 38 | 39 | /** 40 | * 41 | * @return 42 | */ 43 | float readValue(); 44 | 45 | /** 46 | * 47 | * @param value 48 | */ 49 | void setValue(float value); 50 | 51 | /** 52 | * 53 | */ 54 | void showLabel(); 55 | 56 | /** 57 | * 58 | */ 59 | void showNumbers(); 60 | 61 | } 62 | -------------------------------------------------------------------------------- /lib/export.txt: -------------------------------------------------------------------------------- 1 | # If you want to support more platforms, visit jogamp.org to get the 2 | # natives libraries for the platform in question (i.e. Solaris). 3 | 4 | name = OpenGL 5 | 6 | application.macosx=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-macosx-universal.jar,gluegen-rt-natives-macosx-universal.jar 7 | application.windows32=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-windows-i586.jar,gluegen-rt-natives-windows-i586.jar 8 | application.windows64=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-windows-amd64.jar,gluegen-rt-natives-windows-amd64.jar 9 | application.linux32=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-linux-i586.jar,gluegen-rt-natives-linux-i586.jar 10 | application.linux64=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-linux-amd64.jar,gluegen-rt-natives-linux-amd64.jar 11 | application.linux-armv6hf=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-linux-armv6hf.jar,gluegen-rt-natives-linux-armv6hf.jar 12 | application.linux-arm64=core.jar,jogl-all.jar,gluegen-rt.jar,jogl-all-natives-linux-aarch64.jar,gluegen-rt-natives-linux-aarch64.jar 13 | -------------------------------------------------------------------------------- /src/main/java/processing/javafx/PGraphicsFX2D.java: -------------------------------------------------------------------------------- 1 | /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Processing project - http://processing.org 5 | 6 | Copyright (c) 2015 The Processing Foundation 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | package processing.javafx; 24 | 25 | 26 | 27 | import processing.core.*; 28 | 29 | 30 | public class PGraphicsFX2D extends PGraphics { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/monkstone/videoevent/CaptureEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-22 Martin Prout 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * http://creativecommons.org/licenses/LGPL/2.1/ 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | package monkstone.videoevent; 22 | import processing.video.Capture; 23 | 24 | @FunctionalInterface 25 | public interface CaptureEvent{ 26 | public void captureEvent(Capture capture); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/processing/data/Sort.java: -------------------------------------------------------------------------------- 1 | package processing.data; 2 | 3 | 4 | /** 5 | * Internal sorter used by several data classes. 6 | * Advanced users only, not official API. 7 | */ 8 | public abstract class Sort implements Runnable { 9 | 10 | public Sort() { } 11 | 12 | 13 | @Override 14 | public void run() { 15 | int c = size(); 16 | if (c > 1) { 17 | sort(0, c - 1); 18 | } 19 | } 20 | 21 | 22 | protected void sort(int i, int j) { 23 | int pivotIndex = (i+j)/2; 24 | swap(pivotIndex, j); 25 | int k = partition(i-1, j); 26 | swap(k, j); 27 | if ((k-i) > 1) sort(i, k-1); 28 | if ((j-k) > 1) sort(k+1, j); 29 | } 30 | 31 | 32 | protected int partition(int left, int right) { 33 | int pivot = right; 34 | do { 35 | while (compare(++left, pivot) < 0) { } 36 | while ((right != 0) && (compare(--right, pivot) > 0)) { } 37 | swap(left, right); 38 | } while (left < right); 39 | swap(left, right); 40 | return left; 41 | } 42 | 43 | 44 | abstract public int size(); 45 | abstract public int compare(int a, int b); 46 | abstract public void swap(int a, int b); 47 | } -------------------------------------------------------------------------------- /src/main/resources/shaders/ColorFrag.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifdef GL_ES 24 | precision mediump float; 25 | precision mediump int; 26 | #endif 27 | 28 | varying vec4 vertColor; 29 | 30 | void main() { 31 | gl_FragColor = vertColor; 32 | } -------------------------------------------------------------------------------- /src/main/resources/shaders/LineFrag.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifdef GL_ES 24 | precision mediump float; 25 | precision mediump int; 26 | #endif 27 | 28 | varying vec4 vertColor; 29 | 30 | void main() { 31 | gl_FragColor = vertColor; 32 | } -------------------------------------------------------------------------------- /src/main/resources/shaders/PointFrag.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifdef GL_ES 24 | precision mediump float; 25 | precision mediump int; 26 | #endif 27 | 28 | varying vec4 vertColor; 29 | 30 | void main() { 31 | gl_FragColor = vertColor; 32 | } -------------------------------------------------------------------------------- /src/main/java/monkstone/vecmath/JRender.java: -------------------------------------------------------------------------------- 1 | package monkstone.vecmath; 2 | 3 | /** 4 | * 5 | * @author Martin Prout 6 | */ 7 | public interface JRender { 8 | 9 | /** 10 | * 11 | * @param x double 12 | * @param y double 13 | */ 14 | void vertex(double x, double y); 15 | 16 | /** 17 | * 18 | * @param x double 19 | * @param y double 20 | */ 21 | void curveVertex(double x, double y); 22 | 23 | /** 24 | * 25 | * @param x double 26 | * @param y double 27 | * @param z double 28 | */ 29 | void vertex(double x, double y, double z); 30 | 31 | /** 32 | * 33 | * @param x double 34 | * @param y double 35 | * @param z double 36 | * @param u double 37 | * @param v double 38 | */ 39 | void vertex(double x, double y, double z, double u, double v); 40 | 41 | /** 42 | * 43 | * @param x double 44 | * @param y double 45 | * @param z double 46 | */ 47 | void curveVertex(double x, double y, double z); 48 | 49 | /** 50 | * 51 | * @param x double 52 | * @param y double 53 | * @param z double 54 | */ 55 | void normal(double x, double y, double z); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/resources/shaders/ColorVert.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | uniform mat4 transformMatrix; 24 | 25 | attribute vec4 position; 26 | attribute vec4 color; 27 | 28 | varying vec4 vertColor; 29 | 30 | void main() { 31 | gl_Position = transformMatrix * position; 32 | 33 | vertColor = color; 34 | } -------------------------------------------------------------------------------- /src/main/resources/shaders/LightFrag.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifdef GL_ES 24 | precision mediump float; 25 | precision mediump int; 26 | #endif 27 | 28 | varying vec4 vertColor; 29 | varying vec4 backVertColor; 30 | 31 | void main() { 32 | gl_FragColor = gl_FrontFacing ? vertColor : backVertColor; 33 | } -------------------------------------------------------------------------------- /src/main/resources/shaders/TexFrag.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifdef GL_ES 24 | precision mediump float; 25 | precision mediump int; 26 | #endif 27 | 28 | uniform sampler2D texture; 29 | 30 | uniform vec2 texOffset; 31 | 32 | varying vec4 vertColor; 33 | varying vec4 vertTexCoord; 34 | 35 | void main() { 36 | gl_FragColor = texture2D(texture, vertTexCoord.st) * vertColor; 37 | } -------------------------------------------------------------------------------- /src/main/java/monkstone/videoevent/MovieEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-22 Martin Prout 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * http://creativecommons.org/licenses/LGPL/2.1/ 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | package monkstone.videoevent; 22 | import processing.video.Movie; 23 | 24 | /** 25 | * This interface makes it easier/possible to use the reflection methods 26 | * from Movie and Capture classes in Processing::App in JRubyArt 27 | * @author Martin Prout 28 | */ 29 | @FunctionalInterface 30 | public interface MovieEvent { 31 | public void movieEvent(Movie movie); 32 | } 33 | -------------------------------------------------------------------------------- /test/native_folder.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'test_helper' 4 | require 'java' 5 | require_relative '../lib/propane' 6 | # Mock class 7 | class WindowsNativeFolder < NativeFolder 8 | def initialize 9 | @os = 'mswin' 10 | @bit = 64 11 | end 12 | end 13 | 14 | class MacNativeFolder < NativeFolder 15 | def initialize 16 | @os = 'mac' 17 | @bit = 64 18 | end 19 | end 20 | 21 | # Test class 22 | class NativeFolderTest < Minitest::Test 23 | def test_windows_native_folder 24 | obj = WindowsNativeFolder.new 25 | assert_kind_of NativeFolder, obj, 'Constructor Failed' 26 | assert(/windows/.match?(obj.name)) 27 | assert(/\*.dll/.match?(obj.extension)) 28 | end 29 | 30 | class NativeFolderTest < Minitest::Test 31 | def test_windows_native_folder 32 | obj = MacNativeFolder.new 33 | assert_kind_of NativeFolder, obj, 'Constructor Failed' 34 | assert(/macos/.match?(obj.name)) 35 | assert(/\*.dylib/.match?(obj.extension)) 36 | end 37 | end 38 | 39 | if /linux/.match?(RbConfig::CONFIG['host_os'].downcase) 40 | def test_native_folder 41 | obj = NativeFolder.new 42 | assert_instance_of NativeFolder, obj, 'Constructor Failed' 43 | assert(/linux/.match?(obj.name)) 44 | assert(/\*.so/.match?(obj.extension)) 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /library/slider/slider.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Here's a little library for quickly hooking up in sketch sliders. 4 | # Copyright (c) 2015-22 Martin Prout. 5 | 6 | java_import 'monkstone.slider.CustomHorizontalSlider' 7 | java_import 'monkstone.slider.CustomVerticalSlider' 8 | 9 | # Slider module 10 | module Slider 11 | def self.slider(app:, x:, y:, name:, **opts) 12 | options = default.merge opts 13 | slider = if options[:vertical] 14 | CustomVerticalSlider.new( 15 | app, 16 | x, 17 | y, 18 | options[:length], 19 | options[:range].first, 20 | options[:range].last, 21 | name 22 | ) 23 | else 24 | CustomHorizontalSlider.new( 25 | app, 26 | x, 27 | y, 28 | options[:length], 29 | options[:range].first, 30 | options[:range].last, 31 | name 32 | ) 33 | end 34 | unless opts.empty? 35 | slider.bar_width(opts.fetch(:bar_width, 10)) 36 | slider.set_value(opts.fetch(:initial_value, 0)) 37 | end 38 | slider 39 | end 40 | 41 | def self.default 42 | { length: 100, range: (0..100) } 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /src/main/java/monkstone/slider/WheelHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-22 Martin Prout 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * http://creativecommons.org/licenses/LGPL/2.1/ 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package monkstone.slider; 21 | 22 | /** 23 | * @author Martin Prout from a borrowed pattern seen in Jonathan Feinbergs 24 | * Peasycam when I was struggling with non functioning browser applet, probably 25 | * superfluous here. 26 | */ 27 | @FunctionalInterface 28 | public interface WheelHandler { 29 | 30 | /** 31 | * 32 | * @param amount int 33 | */ 34 | void handleWheel(final short amount); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/resources/shaders/TexLightFrag.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | #ifdef GL_ES 23 | precision mediump float; 24 | precision mediump int; 25 | #endif 26 | 27 | uniform sampler2D texture; 28 | 29 | uniform vec2 texOffset; 30 | 31 | varying vec4 vertColor; 32 | varying vec4 backVertColor; 33 | varying vec4 vertTexCoord; 34 | 35 | void main() { 36 | gl_FragColor = texture2D(texture, vertTexCoord.st) * (gl_FrontFacing ? vertColor : backVertColor); 37 | } -------------------------------------------------------------------------------- /src/main/resources/shaders/TexVert.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | uniform mat4 transformMatrix; 24 | uniform mat4 texMatrix; 25 | 26 | attribute vec4 position; 27 | attribute vec4 color; 28 | attribute vec2 texCoord; 29 | 30 | varying vec4 vertColor; 31 | varying vec4 vertTexCoord; 32 | 33 | void main() { 34 | gl_Position = transformMatrix * position; 35 | 36 | vertColor = color; 37 | vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0); 38 | } -------------------------------------------------------------------------------- /src/main/resources/cursors/license.txt: -------------------------------------------------------------------------------- 1 | These files are based on the DMZ Cursors package, 2 | used with permission from Jakub Steiner 3 | 11 September 2015 4 | 5 | 6 | The MIT License (MIT) 7 | 8 | Copyright (c) 2006 Jakub Steiner 9 | Copyright (c) 2006 Novell, Inc. 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | -------------------------------------------------------------------------------- /src/main/resources/shaders/MaskFrag.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifdef GL_ES 24 | precision mediump float; 25 | precision mediump int; 26 | #endif 27 | 28 | #define PROCESSING_TEXTURE_SHADER 29 | 30 | uniform sampler2D texture; 31 | uniform sampler2D mask; 32 | 33 | varying vec4 vertTexCoord; 34 | 35 | void main() { 36 | vec3 texColor = texture2D(texture, vertTexCoord.st).rgb; 37 | vec3 maskColor = texture2D(mask, vertTexCoord.st).rgb; 38 | float luminance = dot(maskColor, vec3(0.2126, 0.7152, 0.0722)); 39 | gl_FragColor = vec4(texColor, luminance); 40 | } -------------------------------------------------------------------------------- /src/main/java/monkstone/filechooser/Chooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-22 Martin Prout 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * http://creativecommons.org/licenses/LGPL/2.1/ 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package monkstone.filechooser; 21 | 22 | import java.io.File; 23 | 24 | /** 25 | * This interface makes it easier/possible to use the reflection methods 26 | * selectInput def setup java_signature 'void selectInput(String, String)' 27 | * selectInput('Select a file to process:', 'fileSelected') end 28 | * 29 | * def file_selected(selection) if selection.nil? puts 'Window was closed or the 30 | * user hit cancel.' else puts format('User selected %s', 31 | * selection.get_absolute_path) end end 32 | * 33 | * @author Martin Prout 34 | */ 35 | @FunctionalInterface 36 | public interface Chooser { 37 | 38 | void file_selected(File selection); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/monkstone/PropaneLibrary.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The purpose of this class is to load the MathTool into ruby-processing runtime 3 | * Copyright (C) 2015-22 Martin Prout. This code is free software; you can 4 | * redistribute it and/or modify it under the terms of the GNU Lesser General 5 | * Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * Obtain a copy of the license at http://www.gnu.org/licenses/lgpl-2.1.html 9 | */ 10 | package monkstone; 11 | 12 | import java.io.IOException; 13 | import monkstone.fastmath.Deglut; 14 | import monkstone.vecmath.vec2.Vec2; 15 | import monkstone.vecmath.vec3.Vec3; 16 | import org.jruby.Ruby; 17 | import org.jruby.runtime.load.Library; 18 | 19 | /** 20 | * 21 | * @author Martin Prout 22 | */ 23 | public class PropaneLibrary implements Library { 24 | 25 | /** 26 | * 27 | * @param runtime 28 | */ 29 | public static void load(final Ruby runtime) { 30 | MathToolModule.createMathToolModule(runtime); 31 | FastNoiseModuleJava.createNoiseModule(runtime); 32 | SmoothNoiseModuleJava.createNoiseModule(runtime); 33 | Deglut.createDeglut(runtime); 34 | Vec2.createVec2(runtime); 35 | Vec3.createVec3(runtime); 36 | } 37 | 38 | /** 39 | * 40 | * @param runtime 41 | * @param wrap 42 | * @throws java.io.IOException 43 | */ 44 | @Override 45 | public void load(final Ruby runtime, boolean wrap) throws IOException { 46 | PropaneLibrary.load(runtime); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: false 2 | 3 | require_relative 'lib/propane/version' 4 | 5 | task default: %i[init compile install test gem] 6 | 7 | # Currently depends on local jogl-2.4.0 jars on path ~/jogl24 8 | desc 'Copy Jars' 9 | task :init do 10 | jogl24 = File.join(ENV['HOME'], 'jogl24') 11 | opengl = Dir.entries(jogl24).grep(/amd64|universal|arm64/).select { |jar| jar =~ /linux|windows|macosx|ios|/ } 12 | opengl.concat %w[jogl-all.jar gluegen-rt.jar] 13 | opengl.each do |gl| 14 | FileUtils.cp(File.join(jogl24, gl), File.join('.', 'lib')) 15 | end 16 | end 17 | 18 | desc 'Install' 19 | task :install do 20 | sh './mvnw dependency:copy' 21 | FileUtils.mv("target/propane-#{Propane::VERSION}.jar", 'lib') 22 | end 23 | 24 | desc 'Gem' 25 | task :gem do 26 | sh 'jgem build propane.gemspec' 27 | end 28 | 29 | desc 'Document' 30 | task :javadoc do 31 | sh './mvnw javadoc:javadoc' 32 | end 33 | 34 | desc 'Compile' 35 | task :compile do 36 | sh './mvnw package' 37 | end 38 | 39 | desc 'pmd' 40 | task :pmd do 41 | sh './mvnw pmd:pmd' 42 | end 43 | 44 | desc 'Test' 45 | task :test do 46 | sh 'jruby test/helper_methods_test.rb' 47 | # sh 'jruby test/respond_to_test.rb' Skip test on Travis to avoid Headless fail 48 | sh 'jruby --dev test/create_test.rb' 49 | sh 'jruby --dev test/math_tool_test.rb' 50 | sh 'jruby --dev test/deglut_spec_test.rb' 51 | sh 'jruby --dev test/vecmath_spec_test.rb' 52 | end 53 | 54 | desc 'clean' 55 | task :clean do 56 | Dir['./**/*.{jar,gem}'].each do |path| 57 | puts 'Deleting #{path} ...' 58 | File.delete(path) 59 | end 60 | FileUtils.rm_rf('./target') 61 | end 62 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | In the spirit of [free software][free-sw], **everyone** is encouraged to help improve this project. 3 | 4 | Here are some ways *you* can contribute: 5 | 6 | * by reporting bugs 7 | * by suggesting/implementing new features (eg integrate with atom) 8 | * by writing or editing documentation ( _expert Windows users could help write install instructions_ ) 9 | * by contributing examples ( _show your creativity, or translate someone elses masterpiece_ ) 10 | * by refactoring examples to be more rubyfied 11 | * by closing [issues][] 12 | * by proselytizing propane, we need more champions 13 | * by supporting [processing.org][], nothing to do with us but we rely on them 14 | * by creating gems for pdf, video library etc see arcball gem as example 15 | 16 | ## Submitting an Issue 17 | We use the [GitHub issue tracker][issues] to track bugs and features. Before 18 | submitting a bug report or feature request, check to make sure it hasn't 19 | already been submitted. When submitting a bug report, ideally include a [Gist][] 20 | that includes a stack trace and any details that may be necessary to reproduce 21 | the bug, including your gem version, Ruby version, and operating system. 22 | 23 | 24 | ## Submitting a Pull Request 25 | 1. [Fork the repository.][fork] 26 | 2. [Submit a pull request.][pr] 27 | 28 | [free-sw]: http://www.fsf.org/licensing/essays/free-sw.html 29 | [issues]: https://github.com/ruby-processing/propane/issues 30 | [gist]: https://gist.github.com/ 31 | [fork]: http://help.github.com/fork-a-repo/ 32 | [pr]: http://help.github.com/send-pull-requests/ 33 | [processing.org]: http://processing.org/foundation/ 34 | -------------------------------------------------------------------------------- /lib/propane/creators/sketch_class.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: false 2 | 3 | # the sketch class 4 | class SketchClass 5 | attr_reader :name, :width, :height, :mode 6 | 7 | def initialize(name:, width: 150, height: 150, mode: nil) 8 | @name = name 9 | @width = width 10 | @height = height 11 | @mode = mode 12 | end 13 | 14 | def class_sketch 15 | format('class %s < Propane::App', sketch_class) 16 | end 17 | 18 | def sketch_class 19 | name.split('_').collect(&:capitalize).join 20 | end 21 | 22 | def sketch_new 23 | format('%s.new', sketch_class) 24 | end 25 | 26 | def indent(line) 27 | format(' %s', line) 28 | end 29 | 30 | def size 31 | return format(' size %d, %d', width.to_i, height.to_i) unless mode 32 | 33 | format(' size %d, %d, %s', width.to_i, height.to_i, mode.upcase) 34 | end 35 | 36 | def sketch_title 37 | human = name.split('_').collect(&:capitalize).join(' ') 38 | format(" sketch_title '%s'", human) 39 | end 40 | 41 | def method_lines(name, content = nil) 42 | return [format(' def %s', name), '', ' end'] unless content 43 | 44 | [format(' def %s', name), content, ' end', ''] 45 | end 46 | 47 | def lines 48 | lines = [ 49 | '#!/usr/bin/env jruby', 50 | '# frozen_string_literal: false', 51 | '', 52 | "require 'propane'", 53 | '', 54 | class_sketch 55 | ] 56 | lines.concat method_lines('settings', size) 57 | lines.concat method_lines('setup', sketch_title) 58 | lines.concat method_lines('draw') 59 | lines << 'end' 60 | lines << '' 61 | lines << sketch_new 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/propane/library_loader.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: false 2 | 3 | # The processing wrapper module 4 | module Propane 5 | require_relative 'library' 6 | 7 | # Encapsulate library loader functionality as a class 8 | class LibraryLoader 9 | attr_reader :library 10 | 11 | def initialize 12 | @loaded_libraries = Hash.new(false) 13 | end 14 | 15 | # Detect if a library has been loaded (for conditional loading) 16 | def library_loaded?(library_name) 17 | @loaded_libraries[library_name.to_sym] 18 | end 19 | 20 | # Load a list of Ruby or Java libraries (in that order) 21 | # Usage: load_libraries :video, :video_event 22 | # 23 | # If a library is put into a 'library' folder next to the sketch it will 24 | # be used instead of an installed propane library. 25 | def load_libraries(*args) 26 | message = 'no such file to load -- %s' 27 | args.each do |lib| 28 | loaded = loader(lib) 29 | raise(LoadError.new, format(message, lib)) unless loaded 30 | end 31 | end 32 | alias load_library load_libraries 33 | 34 | def loader(name) 35 | return true if @loaded_libraries.include?(name) 36 | 37 | fname = name.to_s 38 | library = Library.new(fname) 39 | library.locate 40 | return require_library(library, name) if library.ruby? 41 | 42 | warn("Not found library: #{fname}") unless library.exist? 43 | load_jars(library, name) 44 | end 45 | 46 | def load_jars(lib, name) 47 | lib.load_jars 48 | @loaded_libraries[name] = true 49 | end 50 | 51 | def require_library(lib, name) 52 | @loaded_libraries[name] = require lib.path 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /test/create_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'test_helper' 4 | require_relative '../lib/propane/creators/sketch_class' 5 | require_relative '../lib/propane/creators/sketch_writer' 6 | 7 | CLASS_SKETCH = <<~CODE 8 | #!/usr/bin/env jruby 9 | # frozen_string_literal: false 10 | 11 | require 'propane' 12 | 13 | class FredSketch < Propane::App 14 | def settings 15 | size 200, 200 16 | end 17 | 18 | def setup 19 | sketch_title 'Fred Sketch' 20 | end 21 | 22 | def draw 23 | 24 | end 25 | end 26 | 27 | FredSketch.new 28 | 29 | CODE 30 | # Create sketch test 31 | class SketchClassTest < Minitest::Test 32 | def setup 33 | @basic = SketchClass.new(name: 'fred_sketch', width: 200, height: 200) 34 | @sketch = SketchClass.new(name: 'fred_sketch', width: 200, height: 200, mode: 'p2d') 35 | end 36 | 37 | def test_class 38 | result = CLASS_SKETCH.split(/\n/, -1) 39 | class_lines = @basic.lines 40 | class_lines.each_with_index do |line, i| 41 | assert_equal result[i], line 42 | end 43 | end 44 | 45 | def test_indent 46 | assert_equal ' indent', @sketch.indent('indent') 47 | end 48 | 49 | def test_size 50 | assert_equal ' size 200, 200, P2D', @sketch.size 51 | assert_equal ' size 200, 200', @basic.size 52 | end 53 | 54 | def test_sketch_title 55 | assert_equal " sketch_title 'Fred Sketch'", @sketch.sketch_title 56 | end 57 | 58 | def test_class_class 59 | assert_equal 'FredSketch', @sketch.sketch_class 60 | end 61 | 62 | def test_class_new 63 | assert_equal 'FredSketch.new', @sketch.sketch_new 64 | end 65 | 66 | def test_sketch_class 67 | assert_equal 'class FredSketch < Propane::App', @basic.class_sketch 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /lib/propane/library.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'native_folder' 4 | require_relative 'native_loader' 5 | require 'pathname' 6 | 7 | # This class knows where to find propane libraries 8 | class Library 9 | attr_reader :name, :path, :dir, :ppath 10 | 11 | def initialize(name) 12 | @name = name 13 | @ruby = true 14 | end 15 | 16 | def locate 17 | return if (@path = Pathname.new( 18 | File.join(Propane::SKETCH_ROOT, 'library', name, "#{name}.rb") 19 | )).exist? 20 | return if (@path = Pathname.new( 21 | File.join(PROPANE_ROOT, 'library', name, "#{name}.rb") 22 | )).exist? 23 | 24 | locate_java 25 | end 26 | 27 | def locate_java 28 | @dir = Pathname.new( 29 | File.join(Propane::SKETCH_ROOT, 'library', name) 30 | ) 31 | locate_installed_java 32 | end 33 | 34 | def locate_installed_java 35 | unless dir.directory? 36 | @dir = Pathname.new( 37 | File.join(ENV['HOME'], '.propane', 'libraries', name, 'library') 38 | ) 39 | end 40 | @path = dir.join(Pathname.new("#{name}.jar")) 41 | end 42 | 43 | def ruby? 44 | path.extname == '.rb' 45 | end 46 | 47 | def exist? 48 | path.exist? 49 | end 50 | 51 | def load_jars 52 | Dir.glob("#{dir}/*.jar").sort.each do |jar| 53 | require jar 54 | end 55 | return true unless native_binaries? 56 | 57 | add_binaries_to_classpath 58 | end 59 | 60 | def native_binaries? 61 | native_folder = NativeFolder.new 62 | native = native_folder.name 63 | @ppath = File.join(dir, native) 64 | File.directory?(ppath) && 65 | !Dir.glob(File.join(ppath, native_folder.extension)).empty? 66 | end 67 | 68 | def add_binaries_to_classpath 69 | native_loader = NativeLoader.new 70 | native_loader.add_native_path(ppath) 71 | true 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /src/main/java/monkstone/slider/SliderGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-22 Martin Prout 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * http://creativecommons.org/licenses/LGPL/2.1/ 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package monkstone.slider; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | import processing.core.PApplet; 25 | 26 | public class SliderGroup { 27 | 28 | int count = 0; 29 | List sliders; 30 | PApplet applet; 31 | boolean vertical; 32 | 33 | public SliderGroup(final PApplet outer) { 34 | applet = outer; 35 | sliders = new ArrayList<>(); 36 | vertical = false; 37 | } 38 | 39 | public void vertical() { 40 | vertical = true; 41 | } 42 | 43 | public void addSlider(float beginRange, float endRange, float initial) { 44 | if (vertical) { 45 | sliders.add(new SimpleVerticalSlider(applet, beginRange, endRange, initial, count)); 46 | } else { 47 | sliders.add(new SimpleHorizontalSlider(applet, beginRange, endRange, initial, count)); 48 | } 49 | count = sliders.size(); 50 | } 51 | 52 | public float readValue(int count) { 53 | return sliders.get(count).readValue(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /propane.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | lib = File.expand_path('lib', __dir__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'propane/version' 6 | 7 | Gem::Specification.new do |gem| 8 | gem.name = 'propane' 9 | gem.version = Propane::VERSION 10 | gem.authors = ['monkstone'] 11 | gem.email = ['mamba2928@yahoo.co.uk'] 12 | gem.licenses = %w[GPL-3.0 LGPL-2.0] 13 | gem.description = <<-EOS 14 | A batteries included version of processing in ruby targetting jdk11+. 15 | EOS 16 | gem.summary = 'ruby implementation of processing-4.0 on linux and windows (64bit only), might work MacOS, needs testing' 17 | gem.homepage = 'https://ruby-processing.github.io/propane/' 18 | gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) 19 | gem.files << "lib/propane-#{Propane::VERSION}.jar" 20 | gem.files << 'lib/gluegen-rt.jar' 21 | gem.files << 'lib/jogl-all.jar' 22 | gem.files << 'lib/gluegen-rt-natives-linux-amd64.jar' 23 | gem.files << 'lib/gluegen-rt-natives-macosx-universal.jar' 24 | # gem.files << 'lib/gluegen-rt-natives-ios-arm64.jar' 25 | gem.files << 'lib/gluegen-rt-natives-windows-amd64.jar' 26 | gem.files << 'lib/jogl-all-natives-linux-amd64.jar' 27 | gem.files << 'lib/jogl-all-natives-macosx-universal.jar' 28 | # gem.files << 'lib/jogl-all-natives-ios-arm64.jar' 29 | gem.files << 'lib/jogl-all-natives-windows-amd64.jar' 30 | gem.files << 'library/pdf/itextpdf-5.5.13.2.jar' 31 | gem.files << 'library/svg/batik-all-1.14.jar' 32 | gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } 33 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 34 | gem.add_development_dependency 'jruby-openssl', '~> 0.10', '>=0.10.7' 35 | gem.add_development_dependency 'minitest', '~> 5.15' 36 | gem.add_runtime_dependency 'rake', '~> 13.0' 37 | gem.add_runtime_dependency 'arcball', '~> 1.2' 38 | gem.require_paths = ['lib'] 39 | gem.platform = 'java' 40 | gem.requirements << 'java runtime >= 17.0.1+' 41 | end 42 | -------------------------------------------------------------------------------- /src/main/java/monkstone/vecmath/GfxRender.java: -------------------------------------------------------------------------------- 1 | package monkstone.vecmath; 2 | 3 | import processing.core.PGraphics; 4 | 5 | /** 6 | * 7 | * @author Martin Prout 8 | */ 9 | public class GfxRender implements JRender { 10 | 11 | final PGraphics graphics; 12 | 13 | /** 14 | * 15 | * @param graphics PGraphics 16 | */ 17 | public GfxRender(final PGraphics graphics) { 18 | this.graphics = graphics; 19 | } 20 | 21 | /** 22 | * 23 | * @param x double 24 | * @param y double 25 | */ 26 | @Override 27 | public void vertex(double x, double y) { 28 | graphics.vertex((float) x, (float) y); 29 | } 30 | 31 | /** 32 | * 33 | * @param x double 34 | * @param y double 35 | */ 36 | @Override 37 | public void curveVertex(double x, double y) { 38 | graphics.curveVertex((float) x, (float) y); 39 | } 40 | 41 | /** 42 | * 43 | * @param x double 44 | * @param y double 45 | * @param z double 46 | */ 47 | @Override 48 | public void vertex(double x, double y, double z) { 49 | graphics.vertex((float) x, (float) y, (float) z); 50 | } 51 | 52 | /** 53 | * 54 | * @param x double 55 | * @param y double 56 | * @param z double 57 | */ 58 | @Override 59 | public void normal(double x, double y, double z) { 60 | graphics.normal((float) x, (float) y, (float) z); 61 | } 62 | 63 | /** 64 | * 65 | * @param x double 66 | * @param y double 67 | * @param z double 68 | * @param u double 69 | * @param v double 70 | */ 71 | @Override 72 | public void vertex(double x, double y, double z, double u, double v) { 73 | graphics.vertex((float) x, (float) y, (float) z, (float) u, (float) v); 74 | } 75 | 76 | /** 77 | * 78 | * @param x double 79 | * @param y double 80 | * @param z double 81 | */ 82 | @Override 83 | public void curveVertex(double x, double y, double z) { 84 | graphics.curveVertex((float) x, (float) y, (float) z); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/processing/core/PStyle.java: -------------------------------------------------------------------------------- 1 | /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Processing project - http://processing.org 5 | 6 | Copyright (c) 2008 Ben Fry and Casey Reas 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | */ 23 | 24 | package processing.core; 25 | 26 | 27 | public class PStyle implements PConstants { 28 | public int imageMode; 29 | public int rectMode; 30 | public int ellipseMode; 31 | public int shapeMode; 32 | 33 | public int blendMode; 34 | 35 | public int colorMode; 36 | public float colorModeX; 37 | public float colorModeY; 38 | public float colorModeZ; 39 | public float colorModeA; 40 | 41 | public boolean tint; 42 | public int tintColor; 43 | public boolean fill; 44 | public int fillColor; 45 | public boolean stroke; 46 | public int strokeColor; 47 | public float strokeWeight; 48 | public int strokeCap; 49 | public int strokeJoin; 50 | 51 | // TODO these fellas are inconsistent, and may need to go elsewhere 52 | public float ambientR, ambientG, ambientB; 53 | public float specularR, specularG, specularB; 54 | public float emissiveR, emissiveG, emissiveB; 55 | public float shininess; 56 | 57 | public PFont textFont; 58 | public int textAlign; 59 | public int textAlignY; 60 | public int textMode; 61 | public float textSize; 62 | public float textLeading; 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/monkstone/vecmath/ShapeRender.java: -------------------------------------------------------------------------------- 1 | package monkstone.vecmath; 2 | 3 | import processing.core.PShape; 4 | 5 | /** 6 | * 7 | * @author Martin Prout 8 | */ 9 | public class ShapeRender implements JRender { 10 | 11 | final PShape shape; 12 | 13 | /** 14 | * 15 | * @param shape PShape 16 | */ 17 | public ShapeRender(final PShape shape) { 18 | this.shape = shape; 19 | 20 | } 21 | 22 | /** 23 | * 24 | * @param x double 25 | * @param y double 26 | */ 27 | @Override 28 | public void vertex(double x, double y) { 29 | shape.vertex((float) x, (float) y); 30 | } 31 | 32 | /** 33 | * 34 | * @param x double 35 | * @param y double 36 | */ 37 | @Override 38 | public void curveVertex(double x, double y) { 39 | throw new UnsupportedOperationException("Not implemented for this renderer"); 40 | } 41 | 42 | /** 43 | * 44 | * @param x double 45 | * @param y double 46 | * @param z double 47 | */ 48 | @Override 49 | public void vertex(double x, double y, double z) { 50 | shape.vertex((float) x, (float) y, (float) z); 51 | } 52 | 53 | /** 54 | * 55 | * @param x double 56 | * @param y double 57 | * @param z double 58 | */ 59 | @Override 60 | public void normal(double x, double y, double z) { 61 | shape.normal((float) x, (float) y, (float) z); 62 | } 63 | 64 | /** 65 | * 66 | * @param x double 67 | * @param y double 68 | * @param z double 69 | * @param u double 70 | * @param v double 71 | */ 72 | @Override 73 | public void vertex(double x, double y, double z, double u, double v) { 74 | shape.vertex((float) x, (float) y, (float) z, (float) u, (float) v); 75 | } 76 | 77 | /** 78 | * 79 | * @param x double 80 | * @param y double 81 | * @param z double 82 | */ 83 | @Override 84 | public void curveVertex(double x, double y, double z) { 85 | throw new UnsupportedOperationException("Not implemented for this renderer"); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/processing/event/KeyEvent.java: -------------------------------------------------------------------------------- 1 | /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Processing project - http://processing.org 5 | 6 | Copyright (c) 2012 The Processing Foundation 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | package processing.event; 24 | 25 | 26 | public class KeyEvent extends Event { 27 | static public final int PRESS = 1; 28 | static public final int RELEASE = 2; 29 | static public final int TYPE = 3; 30 | 31 | char key; 32 | int keyCode; 33 | 34 | boolean isAutoRepeat; 35 | 36 | 37 | public KeyEvent(Object nativeObject, 38 | long millis, int action, int modifiers, 39 | char key, int keyCode) { 40 | super(nativeObject, millis, action, modifiers); 41 | this.flavor = KEY; 42 | this.key = key; 43 | this.keyCode = keyCode; 44 | } 45 | 46 | public KeyEvent(Object nativeObject, 47 | long millis, int action, int modifiers, 48 | char key, int keyCode, boolean isAutoRepeat) { 49 | super(nativeObject, millis, action, modifiers); 50 | this.flavor = KEY; 51 | this.key = key; 52 | this.keyCode = keyCode; 53 | this.isAutoRepeat = isAutoRepeat; 54 | } 55 | 56 | 57 | public char getKey() { 58 | return key; 59 | } 60 | 61 | 62 | public int getKeyCode() { 63 | return keyCode; 64 | } 65 | 66 | 67 | public boolean isAutoRepeat() { 68 | return isAutoRepeat; 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/java/processing/event/TouchEvent.java: -------------------------------------------------------------------------------- 1 | /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Processing project - http://processing.org 5 | 6 | Copyright (c) 2012 The Processing Foundation 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | package processing.event; 24 | 25 | 26 | // PLACEHOLDER CLASS: DO NOT USE. IT HAS NOT EVEN DECIDED WHETHER 27 | // THIS WILL BE CALLED TOUCHEVENT ONCE IT'S FINISHED. 28 | 29 | /* 30 | http://developer.android.com/guide/topics/ui/ui-events.html 31 | http://developer.android.com/reference/android/view/MotionEvent.html 32 | http://developer.apple.com/library/safari/#documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html 33 | http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIGestureRecognizer 34 | 35 | Apple's high-level gesture names: 36 | tap 37 | pinch 38 | rotate 39 | swipe 40 | pan 41 | longpress 42 | 43 | W3C touch events 44 | http://www.w3.org/TR/touch-events/ 45 | http://www.w3.org/TR/2011/WD-touch-events-22110913/ 46 | 47 | Pointer and gesture events (Windows) 48 | http://msdn.microsoft.com/en-US/library/ie/hh673557.aspx 49 | 50 | */ 51 | public class TouchEvent extends Event { 52 | 53 | public TouchEvent(Object nativeObject, long millis, int action, int modifiers) { 54 | super(nativeObject, millis, action, modifiers); 55 | this.flavor = TOUCH; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/resources/shaders/PointVert.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2012-15 The Processing Foundation 5 | Copyright (c) 2004-12 Ben Fry and Casey Reas 6 | Copyright (c) 2001-04 Massachusetts Institute of Technology 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation, version 2.1. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | 23 | uniform mat4 projectionMatrix; 24 | uniform mat4 modelviewMatrix; 25 | 26 | uniform vec4 viewport; 27 | uniform int perspective; 28 | 29 | attribute vec4 position; 30 | attribute vec4 color; 31 | attribute vec2 offset; 32 | 33 | varying vec4 vertColor; 34 | 35 | void main() { 36 | vec4 pos = modelviewMatrix * position; 37 | vec4 clip = projectionMatrix * pos; 38 | 39 | // Perspective --- 40 | // convert from world to clip by multiplying with projection scaling factor 41 | // invert Y, projections in Processing invert Y 42 | vec2 perspScale = (projectionMatrix * vec4(1, -1, 0, 0)).xy; 43 | 44 | // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height]) 45 | // screen_p = (p.xy/p.w + <1,1>) * 0.5 * viewport.zw 46 | 47 | // No Perspective --- 48 | // multiply by W (to cancel out division by W later in the pipeline) and 49 | // convert from screen to clip (derived from clip to screen above) 50 | vec2 noPerspScale = clip.w / (0.5 * viewport.zw); 51 | 52 | gl_Position.xy = clip.xy + offset.xy * mix(noPerspScale, perspScale, float(perspective > 0)); 53 | gl_Position.zw = clip.zw; 54 | 55 | vertColor = color; 56 | } 57 | -------------------------------------------------------------------------------- /library/vector_utils/vector_utils.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | PHI ||= (1 + Math.sqrt(5)) / 2 # golden ratio 4 | GA = PHI * 2 * Math::PI # golden angle 5 | 6 | # Useful Vector Utiliies 7 | module VectorUtil 8 | def self.rotate_vec2d(vectors: [], angle: 0) 9 | vectors.map { |vector| vector.rotate(angle) } 10 | end 11 | 12 | def self.vogel_layout(number:, node_size:) 13 | (0..number).map do |i| 14 | r = Math.sqrt(i) 15 | theta = i * ((2 * Math::PI) / (PHI * PHI)) 16 | x = Math.cos(theta) * r * node_size 17 | y = Math.sin(theta) * r * node_size 18 | Vec2D.new(x, y) 19 | end 20 | end 21 | 22 | def self.fibonacci_sphere(number:, radius:) 23 | (0..number).map do |i| 24 | lon = GA * i 25 | lon /= 2 * Math::PI 26 | lon -= lon.floor 27 | lon *= 2 * Math::PI 28 | lon -= 2 * Math::PI if lon > Math::PI 29 | lat = Math.asin(-1 + 2 * i / number.to_f) 30 | x = radius * Math.cos(lat) * Math.cos(lon) 31 | y = radius * Math.cos(lat) * Math.sin(lon) 32 | z = radius * Math.sin(lat) 33 | Vec3D.new(x, y, z) 34 | end 35 | end 36 | 37 | def self.spiral_layout(number:, radius:, resolution:, spacing:, inc:) 38 | n = 0 39 | angle = nil 40 | (0..number).map do 41 | angle = n * resolution 42 | n += inc 43 | radius -= angle * spacing 44 | x = Math.cos(angle) * radius 45 | y = Math.sin(angle) * radius 46 | Vec2D.new(x, y) 47 | end 48 | end 49 | 50 | def self.cartesian_to_polar(vec:) 51 | res = Vec3D.new(vec.mag, 0, 0) 52 | return Vec3D.new unless res.x > 0 53 | 54 | res.y = -Math.atan2(vec.z, vec.x) 55 | res.z = Math.asin(vec.y / res.x) 56 | res 57 | end 58 | 59 | def self.to_cartesian(lat:, long:, radius:) 60 | latitude = lat 61 | longitude = long 62 | x = radius * Math.cos(latitude) * Math.cos(longitude) 63 | y = radius * Math.cos(latitude) * Math.sin(longitude) 64 | z = radius * Math.sin(latitude) 65 | Vec3D.new(x, y, z) 66 | end 67 | 68 | def self.polar_to_cartesian(vec:) 69 | return Vec3D.new if vec.mag <= 0 70 | 71 | Vec3D.new(Math.asin(vec.y / vec.mag), vec.mag, -Math.atan2(vec.z, vec.x)) 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /test/helper_methods_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'test_helper' 4 | require 'java' 5 | require_relative '../lib/propane' 6 | 7 | Java::Monkstone::PropaneLibrary.new.load(JRuby.runtime, false) 8 | 9 | include Propane::HelperMethods 10 | include MathTool 11 | 12 | Dir.chdir(File.dirname(__FILE__)) 13 | 14 | class HelperMethodsTest < Minitest::Test 15 | ARRAY = %w[albatross dog horse].freeze 16 | def test_hex_color 17 | col_double = 0.5 18 | hexcolor = 0xFFCC6600 19 | dodgy_hexstring = '*56666' 20 | hexstring = '#CC6600' 21 | assert hex_color(col_double) == 0.5, 'double as a color' 22 | assert hex_color(hexcolor) == -3_381_760, 'hexadecimal fixnum color' 23 | assert hex_color(hexstring) == -3_381_760, 'hexadecimal string color' 24 | assert_raises(StandardError, 'Dodgy Hexstring') do 25 | hex_color(dodgy_hexstring) 26 | end 27 | assert_raises(StandardError, 'Dodgy Color Conversion') do 28 | hex_color([]) 29 | end 30 | end 31 | 32 | def test_dist 33 | ax = 0 34 | ay = 0 35 | bx = 1.0 36 | by = 1.0 37 | assert_in_epsilon(dist(ax, ay, bx, by), Math.sqrt(2), 0.0001, '2D distance') 38 | by = 0.0 39 | assert_in_epsilon(dist(ax, ay, bx, by), 1.0, 0.0001, 'when y dimension is zero') 40 | ax = 0 41 | ay = 0 42 | bx = 0.0 43 | by = 0.0 44 | assert_in_epsilon(dist(ax, ay, bx, by), 0.0, 0.0001, 'when x and y dimension are zero') 45 | ax = 1 46 | ay = 1 47 | bx = -2.0 48 | by = -3.0 49 | assert_in_epsilon(dist(ax, ay, bx, by), 5.0, 0.0001, 'classic triangle dimensions') 50 | ax = -1 51 | ay = -1 52 | bx = 100 53 | by = 2.0 54 | cx = 3.0 55 | cy = 100 56 | assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 5.0, 0.0001, 'classic triangle dimensions') 57 | ax = 0 58 | ay = 0 59 | bx = -1.0 60 | by = -1.0 61 | cx = 0 62 | cy = 0 63 | assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), Math.sqrt(2), 0.0001, '2D distance') 64 | ax = 0 65 | ay = 0 66 | bx = 0.0 67 | by = 0.0 68 | cx = 0 69 | cy = 0 70 | assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 0.0) 71 | ax = 0 72 | ay = 0 73 | bx = 1.0 74 | by = 0.0 75 | cx = 0 76 | cy = 0 77 | assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 1.0, 0.0001, 'when x and z dimension are zero') 78 | end 79 | 80 | def test_min 81 | assert_equal(min(*ARRAY), 'albatross') 82 | end 83 | 84 | def test_max 85 | assert_equal(max(*ARRAY), 'horse') 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /src/main/java/monkstone/fastmath/Deglut.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-22 Martin Prout 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * http://creativecommons.org/licenses/LGPL/2.1/ 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | package monkstone.fastmath; 21 | 22 | import org.jruby.Ruby; 23 | import org.jruby.RubyNumeric; 24 | import org.jruby.RubyModule; 25 | import org.jruby.anno.JRubyModule; 26 | import org.jruby.anno.JRubyMethod; 27 | import org.jruby.runtime.ThreadContext; 28 | import org.jruby.runtime.builtin.IRubyObject; 29 | 30 | /** 31 | * 32 | * @author Martin Prout 33 | */ 34 | @JRubyModule(name = "DegLut") 35 | public class Deglut { 36 | 37 | /** 38 | * 39 | * @param runtime Ruby 40 | */ 41 | public static void createDeglut(final Ruby runtime) { 42 | RubyModule deglutModule = runtime.defineModule("DegLut"); 43 | deglutModule.defineAnnotatedMethods(Deglut.class); 44 | } 45 | 46 | /** 47 | * 48 | * @param context ThreadContext 49 | * @param recv IRubyObject 50 | * @param other IRubyObject degrees 51 | * @return sin IRubyObject 52 | */ 53 | @JRubyMethod(name = "sin", module = true) 54 | public static IRubyObject sin(ThreadContext context, IRubyObject recv, IRubyObject other) { 55 | float thet = (float) ((RubyNumeric) other).getLongValue(); 56 | return context.runtime.newFloat(DegLutTables.sinDeg(thet)); 57 | } 58 | 59 | /** 60 | * 61 | * @param context ThreadContext 62 | * @param recv IRubyObject 63 | * @param other IRubyObject degrees 64 | * @return cos IRubyObject 65 | */ 66 | @JRubyMethod(name = "cos", module = true) 67 | public static IRubyObject cos(ThreadContext context, IRubyObject recv, IRubyObject other) { 68 | float thet = (float) ((RubyNumeric) other).getLongValue(); 69 | return context.runtime.newFloat(DegLutTables.cosDeg(thet)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/japplemenubar/JAppleMenuBar.java: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Processing project - http://processing.org 3 | 4 | Copyright (c) 2011-12 hansi raber, released under LGPL under agreement 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation, version 2.1. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General 16 | Public License along with this library; if not, write to the 17 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 18 | Boston, MA 02111-1307 USA 19 | */ 20 | package japplemenubar; 21 | 22 | import java.io.*; 23 | 24 | import processing.core.PApplet; 25 | 26 | 27 | /** 28 | * Starting point for the application. General initialization should be done 29 | * inside the ApplicationController's init() method. If certain kinds of 30 | * non-Swing initialization takes too long, it should happen in a new Thread 31 | * and off the Swing event dispatch thread (EDT). 32 | * 33 | * @author hansi 34 | */ 35 | public class JAppleMenuBar { 36 | static JAppleMenuBar instance; 37 | static final String FILENAME = "libjAppleMenuBar.jnilib"; 38 | 39 | static { 40 | try { 41 | File temp = File.createTempFile("processing", "menubar"); 42 | temp.delete(); // remove the file itself 43 | temp.mkdirs(); // create a directory out of it 44 | temp.deleteOnExit(); 45 | 46 | File jnilibFile = new File(temp, FILENAME); 47 | InputStream input = JAppleMenuBar.class.getResourceAsStream(FILENAME); 48 | if (input != null) { 49 | if (PApplet.saveStream(jnilibFile, input)) { 50 | System.load(jnilibFile.getAbsolutePath()); 51 | instance = new JAppleMenuBar(); 52 | 53 | } else { 54 | sadness("Problem saving " + FILENAME + " for full screen use."); 55 | } 56 | } else { 57 | sadness("Could not load " + FILENAME + " from core.jar"); 58 | } 59 | } catch (IOException e) { 60 | sadness("Unknown error, here's the stack trace."); 61 | e.printStackTrace(); 62 | } 63 | } 64 | 65 | 66 | static void sadness(String msg) { 67 | System.err.println("Full screen mode disabled. " + msg); 68 | } 69 | 70 | 71 | // static public void show() { 72 | // instance.setVisible(true); 73 | // } 74 | 75 | 76 | static public void hide() { 77 | instance.setVisible(false, false); 78 | } 79 | 80 | 81 | public native void setVisible(boolean visibility, boolean kioskMode); 82 | 83 | 84 | // public void setVisible(boolean visibility) { 85 | // // Keep original API in-tact. Default kiosk-mode to off. 86 | // setVisible(visibility, false); 87 | // } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/processing/opengl/VertexBuffer.java: -------------------------------------------------------------------------------- 1 | /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Processing project - http://processing.org 5 | 6 | Copyright (c) 2012-15 The Processing Foundation 7 | Copyright (c) 2004-12 Ben Fry and Casey Reas 8 | Copyright (c) 2001-04 Massachusetts Institute of Technology 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation, version 2.1. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General 20 | Public License along with this library; if not, write to the 21 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 22 | Boston, MA 02111-1307 USA 23 | */ 24 | 25 | package processing.opengl; 26 | 27 | import processing.opengl.PGraphicsOpenGL.GLResourceVertexBuffer; 28 | 29 | // TODO: need to combine with PGraphicsOpenGL.VertexAttribute 30 | public class VertexBuffer { 31 | static protected final int INIT_VERTEX_BUFFER_SIZE = 256; 32 | static protected final int INIT_INDEX_BUFFER_SIZE = 512; 33 | 34 | public int glId; 35 | int target; 36 | int elementSize; 37 | int ncoords; 38 | boolean index; 39 | 40 | protected PGL pgl; // The interface between Processing and OpenGL. 41 | protected int context; // The context that created this texture. 42 | private GLResourceVertexBuffer glres; 43 | 44 | VertexBuffer(PGraphicsOpenGL pg, int target, int ncoords, int esize) { 45 | this(pg, target, ncoords, esize, false); 46 | } 47 | 48 | VertexBuffer(PGraphicsOpenGL pg, int target, int ncoords, int esize, boolean index) { 49 | pgl = pg.pgl; 50 | context = pgl.createEmptyContext(); 51 | 52 | this.target = target; 53 | this.ncoords = ncoords; 54 | this.elementSize = esize; 55 | this.index = index; 56 | create(); 57 | init(); 58 | } 59 | 60 | protected final void create() { 61 | context = pgl.getCurrentContext(); 62 | glres = new GLResourceVertexBuffer(this); 63 | } 64 | 65 | protected final void init() { 66 | int size = index ? ncoords * INIT_INDEX_BUFFER_SIZE * elementSize : 67 | ncoords * INIT_VERTEX_BUFFER_SIZE * elementSize; 68 | pgl.bindBuffer(target, glId); 69 | pgl.bufferData(target, size, null, PGL.STATIC_DRAW); 70 | } 71 | 72 | protected void dispose() { 73 | if (glres != null) { 74 | glres.dispose(); 75 | glId = 0; 76 | glres = null; 77 | } 78 | } 79 | 80 | protected boolean contextIsOutdated() { 81 | boolean outdated = !pgl.contextIsCurrent(context); 82 | if (outdated) { 83 | dispose(); 84 | } 85 | return outdated; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /vendors/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rake/clean' 4 | 5 | WARNING = <<-WGET 6 | WARNING: you may not have wget installed, you could just download 7 | the correct version of propane-examples (see EXAMPLES vendors directory) 8 | WGET 9 | SOUND = 'sound.zip' 10 | PROCESSING_GITHUB = 'https://github.com/processing' 11 | PROPANE_EXAMPLES = 'https://github.com/ruby-processing/propane-examples' 12 | VIDEO = 'video.zip' 13 | DOWNLOAD = 'releases/download/latest' 14 | EXAMPLES = '3.5' 15 | HOME_DIR = ENV['HOME'] 16 | LIBRARY = File.join(HOME_DIR, '.propane', 'libraries') 17 | MAC_OR_LINUX = /linux|mac|darwin/.match?(RbConfig::CONFIG['host_os']) 18 | 19 | CLOBBER.include(EXAMPLES, SOUND, VIDEO) 20 | 21 | desc 'download, and copy propane examples' 22 | task default: [:download_and_copy_samples] 23 | 24 | desc 'download and copy examples to user home' 25 | task download_and_copy_samples: %i[download_examples copy_examples] 26 | 27 | task :download_examples 28 | file_name = MAC_OR_LINUX.nil? ? "#{EXAMPLES}.zip" : "#{EXAMPLES}.tar.gz" 29 | wget_base = ['wget', PROPANE_EXAMPLES].join(' ') 30 | wget_string = [wget_base, 'archive', file_name].join('/') 31 | file file_name do 32 | begin 33 | sh wget_string 34 | rescue StandardError 35 | warn(WARNING) 36 | end 37 | end 38 | 39 | desc 'download and copy sound library to ~/.propane' 40 | task download_and_copy_sound: %i[init_dir download_sound copy_sound clobber] 41 | 42 | desc 'download and copy video library to ~/.propane' 43 | task download_and_copy_video: %i[init_dir download_video copy_video clobber] 44 | 45 | desc 'download sound library' 46 | task :download_sound do 47 | wget_base = ['wget', PROCESSING_GITHUB].join(' ') 48 | wget_string = [wget_base, 'processing-sound', DOWNLOAD, SOUND].join('/') 49 | begin 50 | sh wget_string 51 | rescue StandardError 52 | warn(WARNING) 53 | end 54 | end 55 | 56 | desc 'initialize ~/.propane directories' 57 | task :init_dir do 58 | FileUtils.mkdir_p LIBRARY unless File.exist? LIBRARY 59 | end 60 | 61 | desc 'download video library' 62 | task :download_video do 63 | wget_base = ['wget', PROCESSING_GITHUB].join(' ') 64 | wget_string = [wget_base, 'processing-video', DOWNLOAD, VIDEO].join('/') 65 | begin 66 | sh wget_string 67 | rescue StandardError 68 | warn(WARNING) 69 | end 70 | end 71 | 72 | desc 'copy examples' 73 | task copy_examples: file_name do 74 | if MAC_OR_LINUX.nil? 75 | sh "unzip #{EXAMPLES}.zip" 76 | else 77 | sh "tar xzvf #{EXAMPLES}.tar.gz" 78 | end 79 | sh "rm -r #{HOME_DIR}/propane_samples" if File.exist? "#{HOME_DIR}/propane_samples" 80 | sh "cp -r propane-examples-#{EXAMPLES} #{HOME_DIR}/propane_samples" 81 | sh "rm -r propane-examples-#{EXAMPLES}" 82 | end 83 | 84 | desc 'copy sound library' 85 | task copy_sound: SOUND do 86 | sh "unzip #{SOUND}" 87 | sh "rm -r #{LIBRARY}/sound" if File.exist? "#{LIBRARY}/sound" 88 | sh "cp -r sound #{LIBRARY}" 89 | sh 'rm -r sound' 90 | end 91 | 92 | desc 'copy video library' 93 | task copy_video: VIDEO do 94 | sh "unzip #{VIDEO}" 95 | sh "rm -r #{LIBRARY}/video" if File.exist? "#{LIBRARY}/video" 96 | sh "cp -r video #{LIBRARY}" 97 | sh 'rm -r video' 98 | end 99 | -------------------------------------------------------------------------------- /lib/propane/runner.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: false 2 | 3 | require 'optparse' 4 | require_relative 'version' 5 | 6 | module Propane 7 | # Utility class to handle the different commands that the 'propane' offers 8 | class Runner 9 | attr_reader :options, :argc, :filename 10 | 11 | def initialize 12 | @options = {} 13 | end 14 | 15 | # Start running a propane command from the passed-in arguments 16 | def self.execute 17 | runner = new 18 | runner.parse_options(ARGV) 19 | runner.execute! 20 | end 21 | 22 | # Dispatch central. 23 | def execute! 24 | show_help if options.empty? 25 | show_version if options[:version] 26 | create if options[:create] 27 | install(filename) if options[:install] 28 | end 29 | 30 | # Parse the command-line options. Keep it simple. 31 | def parse_options(args) 32 | opt_parser = OptionParser.new do |opts| 33 | # Set a banner, displayed at the top 34 | # of the help screen. 35 | opts.banner = 'Usage: propane [options] []' 36 | 37 | # Define the options, and what they do 38 | options[:version] = false 39 | opts.on('-v', '--version', 'Propane Version') do 40 | options[:version] = true 41 | end 42 | 43 | options[:install] = false 44 | message = '