Skip to content

Commit 96d631e

Browse files
committed
solid text sketch
1 parent 9111a17 commit 96d631e

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# frozen_string_literal: true
2+
3+
require 'propane'
4+
require 'geomerative'
5+
6+
# SolidText sketch, rubyists hate explicit get and set methods, using
7+
# JRuby convention to replace them
8+
class SolidText < Propane::App
9+
attr_reader :em
10+
11+
def settings
12+
size(600, 400, P3D)
13+
smooth
14+
end
15+
16+
def setup
17+
sketch_title 'Solid Text'
18+
RG.init(self)
19+
grp = RG.get_text('Depth!', data_path('FreeSans.ttf'), 50, CENTER)
20+
RG.polygonizer = RCommand::UNIFORMLENGTH
21+
RG.polygonizer_length = 1
22+
@em = RExtrudedMesh.new(grp)
23+
end
24+
25+
def draw
26+
background(100)
27+
lights
28+
translate(width / 2, height / 2, 200)
29+
rotate_y(millis / 2000.0)
30+
fill(255, 100, 0)
31+
no_stroke
32+
em.draw
33+
end
34+
end
35+
36+
SolidText.new
37+
38+
# Custom extrusion class, including Proxy to access App methods
39+
class RExtrudedMesh
40+
include Propane::Proxy
41+
attr_reader :mesh, :points_array, :depth
42+
43+
def initialize(grp, dpth = 10)
44+
@depth = dpth
45+
@mesh = grp.to_mesh
46+
@points_array = grp.points_in_paths
47+
end
48+
49+
def draw_face(strips, depth)
50+
strips.each do |strip|
51+
begin_shape(TRIANGLE_STRIP)
52+
strip.vertices.each do |point|
53+
vertex(point.x, point.y, depth / 2.0)
54+
end
55+
end_shape(CLOSE)
56+
end
57+
end
58+
59+
def draw_sides(points_array, depth)
60+
points_array.each do |points|
61+
begin_shape(QUAD_STRIP)
62+
points.each do |point|
63+
vertex(point.x, point.y, depth / 2.0)
64+
vertex(point.x, point.y, -depth / 2.0)
65+
end
66+
end_shape(CLOSE)
67+
end
68+
end
69+
70+
def draw
71+
strips = mesh.strips
72+
draw_face(strips, depth)
73+
draw_face(strips, depth * -1)
74+
draw_sides(points_array, depth)
75+
end
76+
end

0 commit comments

Comments
 (0)