Skip to content

Commit

Permalink
Correct samples for simplified GfxRender & ShapeRender.
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Sep 24, 2021
1 parent b31363d commit e8b86d1
Show file tree
Hide file tree
Showing 22 changed files with 129 additions and 31 deletions.
3 changes: 1 addition & 2 deletions contributed/elegant_ball.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Ben Notorianni aka lazydog
#
# elegant.rb
java_import 'monkstone.vecmath.GfxRender'

class ElegantBall < Propane::App

Expand Down Expand Up @@ -38,7 +37,7 @@ def draw
end

def renderer
@renderer ||= GfxRender.new(self.g)
@renderer ||= Propane::GfxRender.new(self.g)
end

def setup_lights
Expand Down
2 changes: 1 addition & 1 deletion contributed/recursive_pentagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RecursivePentagons < Propane::App
def setup
sketch_title 'Recursive Pentagons'
@strut_factor = 0.2
@renderer = GfxRender.new self.g # so we can send Vec2D :to_vertex
@renderer = Propane::GfxRender.new self.g # so we can send Vec2D :to_vertex
background 0
end

Expand Down
2 changes: 1 addition & 1 deletion contributed/ribbon_doodle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def mouse_moved

# An example of GfxRenderer usage for Vec3D => vertex conversion
def renderer
@renderer ||= Propane::Render::GfxRender.new(self.g)
@renderer ||= Propane::GfxRender.new(self.g)
end
end

Expand Down
2 changes: 1 addition & 1 deletion contributed/terrain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def mouse_pressed
private

def renderer
@renderer ||= GfxRender.new(self.g)
@renderer ||= Propane::GfxRender.new(self.g)
end
end

Expand Down
6 changes: 3 additions & 3 deletions contributed/tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class Tree < Propane::App
# http://processing.org/learning/topics/tree.html
# by Joe Holt

def setup
size 200, 200
end
# def settings
# size 200, 200
# end

def setup
sketch_title 'Tree'
Expand Down
42 changes: 42 additions & 0 deletions external_library/java/pgs/letter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require_relative 'mink_shear'
# The letter class needs PGS module for its java_imports
class Letter
include Propane::Proxy
include MinkShear::PGS
attr_reader :hue, :l, :xn, :yn, :pos, :letter

def initialize(c)
@pos = Vec2D.new(rand(width), rand(height))
list = Java::ProcessingCore::PFont.list.to_a
random_font = list.sample
font = createFont(random_font, 96, true)
@l = font.get_shape(c.to_java(:char))
@hue = rand
@xn = rand(4096)
@yn = rand(4096)
end

def update
@xn += 0.005
@yn += 0.005
pos.x = map1d(noise(xn), -1.0..1.0, 0..width)
pos.y = map1d(noise(yn), -1.0..1.0, 0..height)
@letter = PGS_Transformation.translate_to(l, 0, 0)
@letter = PGS_Transformation.shear(letter,
map1d(@pos.x, 0..width, -PI..PI),
map1d(@pos.y, 0..height, -PI..PI))
@letter = PGS_Transformation.translate_to(letter, pos.x, pos.y)
@letter = PGS_Morphology.simplify(letter, 1) # as some fonts have very dense vertices
letter.setStroke(color(hue, 1, 1))
end

def randomise
@hue = rand
list = Java::ProcessingCore::PFont.list.to_a
random_font = list.sample
font = createFont(random_font, 128, true)
@l = font.getShape(rand(0..9).to_s.to_java(:char))
end
end
57 changes: 57 additions & 0 deletions external_library/java/pgs/mink_shear.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'propane'
require_relative 'letter'
class MinkShear < Propane::App
load_library :pgs
module PGS
%w[
PGS_Contour PGS_Conversion PGS_Morphology PGS_Transformation PGS_ShapeBoolean
].each do |klass|
java_import "micycle.pgs.#{klass}"
end
end

include PGS

attr_reader :l1, :l2

def setup
sketch_title 'Mink Shear'
color_mode(HSB, 1.0)
@l1 = Letter.new('M')
@l2 = Letter.new('L')
end

def draw
fill(color(0.1, 0.2))
rect(0, 0, width, height)
begin
l1.update
l2.update
mink = PGS_Morphology.mink_sum(l1.letter, l2.letter)
mink = PGS_Transformation.translate_to(mink, (l1.pos.x + l2.pos.x) / 2, (l1.pos.y + l2.pos.y) / 2)
shape(mink)
shape(l1.letter)
shape(l2.letter)
shape(PGS_Contour.medialAxis(mink, 0.3, 0, 0.1))
intersect = PGS_ShapeBoolean.intersect(l1.letter, mink)
PGS_Conversion.setAllFillColor(intersect, color(0, 0.5))
shape(intersect)
intersect = PGS_ShapeBoolean.intersect(l2.letter, mink)
PGS_Conversion.setAllFillColor(intersect, color(0, 0.5))
shape(intersect)
rescue Java::JavaLang::Exception => e
puts e.to_s
end
if (frame_count % 120).zero?
l1.randomise
l2.randomise
end
end

def settings
size(800, 800)
end
end

MinkShear.new

2 changes: 1 addition & 1 deletion processing_app/basics/form/shape_transform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ShapeTransform < Propane::App

def setup
sketch_title 'Shape Transform'
@renderer = GfxRender.new(self.g)
@renderer = Propane::GfxRender.new(self.g)
no_stroke
@angle_inc = PI / 300
@pts = 4
Expand Down
2 changes: 1 addition & 1 deletion processing_app/basics/form/toroid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def settings
end

def renderer
@renderer ||= GfxRender.new(self.g)
@renderer ||= Propane::GfxRender.new(self.g)
end
end

Expand Down
2 changes: 1 addition & 1 deletion processing_app/basics/math/modules/module_two.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ModuleTwo < Propane::App

def setup
sketch_title 'Module Two'
@renderer = Java::MonkstoneVecmath::GfxRender.new(self.g)
@renderer = Java::MonkstoneVecmath::Propane::GfxRender.new(self.g)
frame_rate 30
reset_scene
end
Expand Down
8 changes: 4 additions & 4 deletions processing_app/demos/graphics/trefoil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#
# Features Vec3D.to_normal(renderer) and Vec3D.to_vertex_uv(renderer, u, v)
# see line 62 for inititialization of renderer where obj is an instance of
# PShape renderer = ShapeRender.new(obj)
java_import 'monkstone.vecmath.ShapeRender'
# PShape renderer = Propane::ShapeRender.new(obj)


class Trefoil < Propane::App
attr_reader :pg, :trefoil
Expand Down Expand Up @@ -44,7 +44,7 @@ def draw
end

# Code to draw a trefoil knot surface, with normals and texture
# coordinates. Makes of the Vec3D Render interface (uses ShapeRender here).
# coordinates. Makes of the Vec3D Render interface (uses Propane::ShapeRender here).
# Adapted from the parametric equations example by Philip Rideout:
# See http://chimera.labs.oreilly.com/books/1234000001814/index.html

Expand All @@ -54,7 +54,7 @@ def create_trefoil(s, ny, nx, tex)
obj = create_shape
obj.begin_shape(TRIANGLES)
obj.texture(tex)
renderer = ShapeRender.new(obj)
renderer = Propane::ShapeRender.new(obj)
(0...nx).each do |j|
u0 = j.to_f / nx
u1 = (j + 1).to_f / nx
Expand Down
6 changes: 3 additions & 3 deletions processing_app/demos/graphics/wiggling.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'propane'
java_import 'monkstone.vecmath.ShapeRender'
java_import 'monkstone.vecmath.Propane::ShapeRender'
#
# WigglePShape. Demonstrates initialization and use of ShapeRender,
# WigglePShape. Demonstrates initialization and use of Propane::ShapeRender,
# that allows us to send Vec2D to PShape vertex
#
# How to move the individual vertices of a PShape
Expand Down Expand Up @@ -41,7 +41,7 @@ def initialize width, height

# Now make the PShape with those vertices
@s = create_shape
renderer = ShapeRender.new(s) # Prefix with Sketch classname
renderer = Propane::ShapeRender.new(s) # Prefix with Sketch classname
s.begin_shape
s.fill(127)
s.stroke(0)
Expand Down
2 changes: 1 addition & 1 deletion processing_app/library/vecmath/vec2d/aabb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def draw
end

def renderer
@renderer ||= GfxRender.new(self.g)
@renderer ||= Propane::GfxRender.new(self.g)
end

def block_locked?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setup
@font = create_font('Arial', 16, true)
@points = TPoints.new
ellipse_mode RADIUS
@renderer = GfxRender.new(self.g)
@renderer = Propane::GfxRender.new(self.g)
end

def draw
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
java_import 'monkstone.vecmath.ShapeRender'
java_import 'monkstone.vecmath.Propane::ShapeRender'
# An object that wraps the PShape
class Wiggler
include Propane::Proxy
Expand All @@ -12,7 +12,7 @@ def initialize width, height
@original = (0...16).map{ |a| Vec2D.from_angle(PI * a / 8) * 100 }
# Now make the PShape with those vertices
@s = create_shape
renderer = ShapeRender.new(s) # Prefix with Sketch classname
renderer = Propane::ShapeRender.new(s) # Prefix with Sketch classname
s.begin_shape
s.fill(127)
s.stroke(0)
Expand Down
2 changes: 1 addition & 1 deletion processing_app/library/vecmath/vec2d/morph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def draw
end

def renderer
@renderer = GfxRender.new(self.g)
@renderer = Propane::GfxRender.new(self.g)
end

def settings
Expand Down
2 changes: 1 addition & 1 deletion processing_app/library/vecmath/vec2d/soft_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def draw
end

def renderer
@renderer ||= GfxRender.new(self.g)
@renderer ||= Propane::GfxRender.new(self.g)
end

def draw_shape
Expand Down
2 changes: 1 addition & 1 deletion processing_app/library/vecmath/vec2d/wiggle_pshape.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'propane'
# WigglePShape. Demonstrates initialization and use of ShapeRender,
# WigglePShape. Demonstrates initialization and use of Propane::ShapeRender,
# that allows us to send Vec2D to PShape vertex see wiggler.rb
#
# How to move the individual vertices of a PShape
Expand Down
4 changes: 2 additions & 2 deletions processing_app/library/vecmath/vec3d/drawolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'propane'
# Drawolver: draw 2D & revolve 3D

# Example shows how to use the vecmath library, including GfxRender utility.
# Example shows how to use the vecmath library, including Propane::GfxRender utility.
# On the ruby side features the use each_cons, a possibly a rare use for this
# ruby Enumerable method?
# 2010-03-22 - fjenett (somewhat revised by Martin Prout 2014-07-06)
Expand Down Expand Up @@ -47,7 +47,7 @@ def draw
end

def renderer
@renderer ||= GfxRender.new(self.g)
@renderer ||= Propane::GfxRender.new(self.g)
end

def reset_scene
Expand Down
2 changes: 1 addition & 1 deletion processing_app/library/vecmath/vec3d/frame_of_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def draw
end

def renderer
@renderer ||= GfxRender.new(self.g)
@renderer ||= Propane::GfxRender.new(self.g)
end
end

Expand Down
2 changes: 1 addition & 1 deletion processing_app/topics/lsystems/peano.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def render(points)
end

def renderer
@renderer ||= GfxRender.new(g)
@renderer ||= Propane::GfxRender.new(g)
end

def settings
Expand Down
4 changes: 2 additions & 2 deletions processing_app/topics/shaders/glsl_heightmap_noise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
require 'propane'

module Renderer
java_import 'monkstone.vecmath.ShapeRender'
java_import 'monkstone.vecmath.Propane::ShapeRender'
end

class HeightMap < Propane::App
Expand Down Expand Up @@ -106,7 +106,7 @@ def create_plane(xsegs, ysegs)
tex = images[0]

mesh = create_shape # create the initial PShape
renderer = ShapeRender.new(mesh) # initialize the shape renderer
renderer = Propane::ShapeRender.new(mesh) # initialize the shape renderer
mesh.begin_shape(QUADS) # define the PShape type: QUADS
mesh.no_stroke
mesh.texture(tex) # set a texture to make a textured PShape
Expand Down

0 comments on commit e8b86d1

Please sign in to comment.