Skip to content

Commit

Permalink
solid text sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Jul 3, 2020
1 parent 9111a17 commit 96d631e
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions external_library/gem/geomerative/solid_text.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# frozen_string_literal: true

require 'propane'
require 'geomerative'

# SolidText sketch, rubyists hate explicit get and set methods, using
# JRuby convention to replace them
class SolidText < Propane::App
attr_reader :em

def settings
size(600, 400, P3D)
smooth
end

def setup
sketch_title 'Solid Text'
RG.init(self)
grp = RG.get_text('Depth!', data_path('FreeSans.ttf'), 50, CENTER)
RG.polygonizer = RCommand::UNIFORMLENGTH
RG.polygonizer_length = 1
@em = RExtrudedMesh.new(grp)
end

def draw
background(100)
lights
translate(width / 2, height / 2, 200)
rotate_y(millis / 2000.0)
fill(255, 100, 0)
no_stroke
em.draw
end
end

SolidText.new

# Custom extrusion class, including Proxy to access App methods
class RExtrudedMesh
include Propane::Proxy
attr_reader :mesh, :points_array, :depth

def initialize(grp, dpth = 10)
@depth = dpth
@mesh = grp.to_mesh
@points_array = grp.points_in_paths
end

def draw_face(strips, depth)
strips.each do |strip|
begin_shape(TRIANGLE_STRIP)
strip.vertices.each do |point|
vertex(point.x, point.y, depth / 2.0)
end
end_shape(CLOSE)
end
end

def draw_sides(points_array, depth)
points_array.each do |points|
begin_shape(QUAD_STRIP)
points.each do |point|
vertex(point.x, point.y, depth / 2.0)
vertex(point.x, point.y, -depth / 2.0)
end
end_shape(CLOSE)
end
end

def draw
strips = mesh.strips
draw_face(strips, depth)
draw_face(strips, depth * -1)
draw_sides(points_array, depth)
end
end

0 comments on commit 96d631e

Please sign in to comment.