Skip to content

Instantly share code, notes, and snippets.

View monkstone's full-sized avatar

Martin Prout monkstone

View GitHub Profile
@monkstone
monkstone / grid_demo.rb
Last active June 9, 2017 07:52
Using Create Graphics and Grid methods propane
#!/usr/bin/env jruby
# frozen_string_literal: false
require 'propane'
class GridDemo < Propane::App
attr_reader :tile # attr_accessor is frowned on in ruby circles
def settings
size(700, 100)
end
@monkstone
monkstone / fred.rb
Last active June 9, 2017 06:40
A template sketch for exploring jirb
#!/usr/bin/env jruby
# frozen_string_literal: false
require 'propane'
class Fred < Propane::App
attr_accessor :back # we can set this variable dynamically
def settings
size 300, 300
end
@monkstone
monkstone / lib_path.rb
Last active May 15, 2017 10:30
Exploring options for library loader (first find a file?)
# frozen_string_literal: true
module BuildPath
def library_path(base, name, ext)
File.join(base, 'library', name, "#{name}.#{ext}")
end
def processing_library_path(base, name, ext)
File.join(base, name, 'library', "#{name}.#{ext}")
end
end

Inspired by Nodebox, JRubyArt (copied from ruby-processing) provides a way to control the instance variables of your sketch with a control panel. You can create sliders, buttons, menus and checkboxes that set instance variables on your sketch. Since ruby-processing-2.0 you need to explicitly set the panel visible from the processing sketch (see included examples). Start by loading in the control_panel library, and then define your panel like so:

  load_library :control_panel
  attr_reader :panel, :hide

  def setup
    size(200, 200)
    @hide = false
@monkstone
monkstone / simple_capture.rb
Created April 20, 2017 19:09
ViideoGL sketch
load_library :glvideo
include_package 'gohai.glvideo'
attr_reader :video
def settings
size(320, 240, P2D)
end
def setup
@monkstone
monkstone / read_write_xml_processing.rb
Last active March 29, 2017 17:39
Work in progress to convert pure java xml to java flavored nokogiri
#
# Loading XML Data
# by Daniel Shiffman.
#
# This example demonstrates how to use loadXML
# to retrieve data from an XML file and make objects
# from that data.
#
# Here is what the XML looks like:
#
@monkstone
monkstone / Palettes.java
Created March 28, 2017 18:28
Color Harmony
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import processing.core.*;
import com.cage.colorharmony.*;
@monkstone
monkstone / StopWatch.java
Created March 20, 2017 16:22
Stop watch using System.nano
package monkstone;
public class StopWatch {
private long startTime, pausedTime;
private boolean paused = true;
public StopWatch() {
startTime = System.nanoTime();
}
@monkstone
monkstone / ruby_wordcram.rb
Last active March 7, 2017 14:05
The power of ruby to be concise
# frozen_string_literal: false
if RUBY_PLATFORM == 'java'
require 'WordCram.jar'
require 'jsoup-1.7.2.jar'
require 'cue.language.jar'
wc = %w(WordAngler WordColorer WordCram WordFonter WordPlacer WordSkipReason)
sh = %w(Colorers ImageShaper Word ShapeBasedPlacer)
WC = wc.concat(sh).freeze
WC.each do |klass|
java_import "wordcram.#{klass}"
@monkstone
monkstone / MathToolModule.java
Last active February 11, 2017 14:06
Implement grid method in java
/**
* The purpose of this tool is to allow JRubyArt users to use an alternative
* to processing.org map, lerp and norm methods in their sketches and to implement
* JRubyArt convenenience method grid(width, height, stepW, stepH) { |x, y| do stuff }
* Copyright (c) 2015-17 Martin Prout. This tool is free software; you can
* redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* Obtain a copy of the license at http://www.gnu.org/licenses/lgpl-2.1.html