Skip to content

Instantly share code, notes, and snippets.

@monkstone
Created July 3, 2020 11:38
Show Gist options
  • Save monkstone/1c921c07b613fc30969f989493ee6b32 to your computer and use it in GitHub Desktop.
Save monkstone/1c921c07b613fc30969f989493ee6b32 to your computer and use it in GitHub Desktop.
Geomerative Solid Text
# frozen_string_literal: true
require 'picrate'
require 'geomerative'
# SolidText sketch, rubyists hate explicit get and set methods, using
# JRuby convention to replace them
class SolidText < Processing::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 Processing::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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment