Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# propane-examples
Example Sketches for propane see also [Example-Sketches][examples] for ruby-processing (many of with only need to be class wrapped to run with propane).
Example Sketches for propane-2.0+ see also [Example-Sketches][examples] for ruby-processing (many of with only need to be class wrapped to run with propane).

1. Sketches using the [data_path wrapper][path] (yields absolute path to `data` folder). NB without wrapper these sketches would need to be run using jruby-complete (`propane --run sketch.rb` rather than `jruby sketch.rb`
1. Sketches using the [data_path wrapper][path] (yields absolute path to `data` folder).

2. Other [sketches][regular], can be run with `propane --run sketch.rb` or `jruby sketch.rb`
2. Other [sketches][regular]

[path]:https://github.com/ruby-processing/propane-examples/tree/master/data_path
[regular]:https://github.com/ruby-processing/propane-examples/tree/master/data_path
Expand Down
8 changes: 6 additions & 2 deletions data_path/bw_shader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ class BwShader < Propane::App

attr_reader :label, :can, :angle, :bw_shader

def setup
def settings
size(640, 360, P3D)
end

def setup
sketch_title 'Black and White Shader'
@label = load_image(data_path('lachoy.jpg'))
@can = create_can(100, 200, 32, label)
@bw_shader = load_shader(data_path('bwfrag.glsl'))
Expand Down Expand Up @@ -44,4 +48,4 @@ def create_can(r, h, detail, tex)
end
end

BwShader.new title: 'Black & White Shader'
BwShader.new
162 changes: 162 additions & 0 deletions data_path/complex_3D.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/usr/bin/env jruby -v -W2
#
# Geometry
# by Marius Watz.
#

require 'propane'

class Complex3D < Propane::App
load_library :pdf
include_package 'processing.pdf'
attr_reader :num, :pt, :style, :dosave

def setup
sketch_title 'Complex 3 D'
background(255)
@dosave = false
@num = 150
@pt = []
@style = []
# Set up arc shapes
index = 0
(0...num).each do |i|
pt << rand(TAU) # Random X axis rotation
pt << rand(TAU) # Random Y axis rotation
pt << rand(60..80) # Short to quarter-circle arcs
pt[pt.length - 1] = rand(8..27) * 10 if rand(100) > 90
pt << rand(2..50) * 5 # Radius. Space them out nicely
pt << rand(4..32) # Width of band
pt[pt.length - 1] = rand(40..60) if (rand(100) > 90) # Width of band
pt << rand(0.005..0.0334)# Speed of rotation
# get colors
prob = rand(100)
case prob
when (0..30)
style[i * 2] = color_blended(rand, 255,0,100, 255,0,0, 210)
when (30..70)
style[i * 2] = color_blended(rand, 0,153,255, 170,225,255, 210)
when (70..90)
style[i * 2] = color_blended(rand, 200,255,0, 150,255,0, 210)
else
style[i * 2] = color(255,255,255, 220)
end
case prob
when (0..50)
style[i * 2] = color_blended(rand, 200,255,0, 50,120,0, 210)
when (50..90)
style[i * 2] = color_blended(rand, 255,100,0, 255,255,0, 210)
else
style[i * 2] = color(255, 255, 255, 220)
style[i * 2 + 1] = rand(100) % 3
end
end
end

def draw
if dosave
# set up PGraphicsPDF for use with beginRaw
pdf = begin_raw(PDF, data_path('pdf_complex_out.pdf'))
# set default Illustrator stroke styles and paint background rect.
pdf.stroke_join(MITER)
pdf.stroke_cap(SQUARE)
pdf.fill(0)
pdf.no_stroke
pdf.rect(0, 0, width, height)
end
background(0)
index = 0
translate(width / 2, height / 2, 0)
rotate_x(PI / 6)
rotate_y(PI / 6)
(0 ... num).each do |i|
push_matrix
rotate_x(pt[index])
rotate_y(pt[index + 1])
index += 2
case (style[i * 2 + 1])
when 0
stroke(style[i * 2])
no_fill
stroke_weight(1)
arc_line(0, 0, pt[index], pt[index + 1], pt[index + 2])
index += 3
when 1
fill(style[i * 2])
no_stroke
arc_line_bars(0, 0, pt[index], pt[index + 1],pt[index + 2])
index += 3
else
fill(style[i * 2])
no_stroke
arc(0, 0, pt[index], pt[index + 1], pt[index + 2])
index += 3
end
# increase rotation
pt[index - 5] += pt[index] / 10
pt[index - 4] += pt[index] / 20
index += 1
pop_matrix
end
if dosave
end_raw
@dosave=false
end
end

# Get blend of two colors
def color_blended(fract, r, g, b, r2, g2, b2, a)
r2 = (r2 - r)
g2 = (g2 - g)
b2 = (b2 - b)
color(r + r2 * fract, g + g2 * fract, b + b2 * fract, a)
end

# Draw arc line
def arc_line(x, y, deg, rad, w)
a = (deg < 360)? deg : 0
numlines = w / 2
(0...numlines).each do
begin_shape
(0...a).each do |i|
vertex(DegLut.cos(i) * rad + x, DegLut.sin(i) * rad + y)
end
end_shape
rad += 2
end
end

# Draw arc line with bars
def arc_line_bars(x, y, deg, rad, w)
a=(deg < 360)? deg / 16 : 0
begin_shape(QUADS)
(0...a).step(4) do |i|
vertex(DegLut.cos(i) * rad + x,DegLut.sin(i) * (rad) + y)
vertex(DegLut.cos(i) * (rad + w) + x,DegLut.sin(i) * (rad + w) + y)
vertex(DegLut.cos((i + 2)) * (rad + w) + x, DegLut.sin((i + 2)) * (rad + w) + y)
vertex(DegLut.cos((i + 2)) * rad + x, DegLut.sin((i + 2)) * rad + y)
end
end_shape
end

# Draw solid arc
def arc(x, y, deg, rad, w)
a = (deg < 360)? deg : 0
begin_shape(QUAD_STRIP)
(0...a).each do |i|
vertex(DegLut.cos(i) * rad + x, DegLut.sin(i) * rad + y)
vertex(DegLut.cos(i) * (rad + w) + x, DegLut.sin(i) * (rad + w) + y)
end
end_shape
end

def mouse_pressed
@dosave = true
end

def settings
size(1024, 768, P3D)
end
end

Complex3D.new
13 changes: 13 additions & 0 deletions data_path/data/arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions data_path/edge_detection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ class EdgeDetection < Propane::App
KERNEL = [[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]].freeze
attr_reader :img

def setup
def settings
size(640, 360)
end

def setup
sketch_title 'Edge Detection'
@img = load_image(data_path('moon.jpg')) # Load the original image
no_loop
end
Expand Down Expand Up @@ -46,4 +50,4 @@ def draw
end
end

EdgeDetection.new title: 'Edge Detection'
EdgeDetection.new
8 changes: 6 additions & 2 deletions data_path/glsl_heightmap_noise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ class HeightMap < Propane::App
attr_reader :images # array to hold 2 input images
attr_reader :color_map # variable to keep track of the current colorMap

def setup
def settings
size(1280, 720, P3D) # use the P3D OpenGL renderer
end

def setup
sketch_title 'Height Map'
@blur_factor = 3
@resize_factor = 0.25
displace_strength = 0.25 # the displace strength of the GLSL shader displacement effect
Expand Down Expand Up @@ -122,4 +126,4 @@ def key_released
end
end

HeightMap.new title: 'Height Map'
HeightMap.new
8 changes: 6 additions & 2 deletions data_path/kinetic_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
# dispay them 'words'
class KineticType < Propane::App

def setup
def settings
size(200, 200, P3D)
end

def setup
sketch_title 'Kinetic Type'
frame_rate 30
# Load the font from the sketch's data directory.
text_font loadFont(data_path('Univers45.vlw')), 1.0
Expand Down Expand Up @@ -76,4 +80,4 @@ def initialize(c, x, y)
end
end

KineticType.new title: 'Kinetic Type'
KineticType.new
15 changes: 10 additions & 5 deletions data_path/landscape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ class Landscape < Propane::App
# Processing port by Raphaël de Courville.
#
attr_reader :landscape
java_alias :background_int, :background, [Java::int]
java_alias :background_int, :background, [Java::int]
TITLE_FORMAT = 'frame: %d - fps: %0.2f'.freeze

def setup
def settings
size(640, 360, P2D)
end

def setup
sketch_title 'Landscape'
no_stroke
# The code of this shader shows how to integrate shaders from shadertoy
# into Processing with minimal changes.
# into Processing/JRubyArt/propane with minimal changes.
@landscape = load_shader(data_path('landscape.glsl'))
landscape.set('resolution', width.to_f, height.to_f)
end
Expand All @@ -27,8 +32,8 @@ def draw
landscape.set('time', (millis/1000.0).to_f)
shader(landscape)
rect(0, 0, width, height)
frame.set_title("frame: #{frame_count} - fps: #{format('%0.2f', frame_rate)}")
sketch_title(format(TITLE_FORMAT, frame_count, frame_rate))
end
end

Landscape.new title: 'Landscape'
Landscape.new
8 changes: 6 additions & 2 deletions data_path/linear_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
class LinearImage < Propane::App
attr_reader :signal, :img, :direction

def setup
def settings
size(640, 360)
end

def setup
sketch_title 'Linear Image'
stroke(255)
@img = load_image(data_path('sea.jpg'))
@direction = 1
Expand Down Expand Up @@ -48,4 +52,4 @@ def draw
end
end

LinearImage.new title: 'Linear Image'
LinearImage.new
69 changes: 69 additions & 0 deletions data_path/magnetic_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env jruby -v -W2
# frozen_string_literal: true
require 'propane'
# Iconic ruby-processing example for Propane
class MagneticField < Propane::App

load_library :hype
include_package 'hype'
# Use Hype namespace
module Hype
java_import 'hype.extended.layout.HGridLayout'
java_import 'hype.extended.behavior.HMagneticField'
java_import 'hype.extended.behavior.HSwarm'
end

attr_reader :pool, :pool_swarm, :field, :swarm
NUM_MAGNETS = 10

def settings
size(640, 640)
end

def setup
sketch_title 'Magnetic Field'
H.init(self)
H.background(color('#000000'))
@field = Hype::HMagneticField.new
NUM_MAGNETS.times do
if rand > 0.5
# x, y, north polarity / strength = 3 / repel
field.add_pole(rand(0..width), rand(0..height), 3)
else
# x, y, south polarity / strength = -3 / attract
field.add_pole(rand(0..width), rand(0..height), -3)
end
end

@pool = HDrawablePool.new(2_500)
pool.auto_add_to_stage
.add(HShape.new(data_path('arrow.svg')).enable_style(false).anchor_at(H::CENTER))
.layout(Hype::HGridLayout.new.start_x(-60).start_y(-60).spacing(16, 16).cols(50))
.on_create do |obj|
obj.no_stroke.anchor(-20, -20)
field.add_target(obj)
end
.requestAll

@swarm = Hype::HSwarm.new.add_goal(width / 2, height / 2).speed(7).turn_ease(0.03).twitch(20)
@pool_swarm = HDrawablePool.new(NUM_MAGNETS)
pool_swarm.auto_add_to_stage
.add(HRect.new(5))
.on_create do |obj|
obj.no_stroke.no_fill.loc(rand(0..width), rand(0..width)).visibility(false)
swarm.add_target(obj)
end
.requestAll
end

def draw
pool_swarm.each_with_index do |d, i|
p = field.pole(i)
p.x = d.x
p.y = d.y
end
H.draw_stage
end
end

MagneticField.new
Loading