-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Former-commit-id: 616886e Former-commit-id: 2771967618a4cfd722f9f2729cd938defb69cc44
- Loading branch information
1 parent
71b9dfe
commit 6dc76e2
Showing
3 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
require 'ruby-processing' | ||
|
||
class KineticType < Processing::App | ||
load_java_library "opengl" | ||
|
||
WORDS = ["sometimes it's like", "the lines of text", "are so happy", "that they want to dance", | ||
"or leave the page or jump", "can you blame them?", "living on the page like that", | ||
"waiting to be read..."] | ||
|
||
include Math | ||
|
||
def setup | ||
render_mode OPENGL | ||
|
||
frame_rate 30 | ||
|
||
# Array of line objects | ||
@lns = []; | ||
|
||
# Load the font from the sketch's data directory | ||
f = load_font(File.dirname(__FILE__) + "/Univers66.vlw.gz") | ||
text_font f, 1.0 | ||
|
||
# White type, black background | ||
fill 255 | ||
|
||
# Creating the line objects | ||
i = -1 | ||
@lines = WORDS.map do |ln| | ||
i += 1 | ||
Line.new self, ln, 0, i * 70, f | ||
end | ||
end | ||
|
||
def draw | ||
background 0 | ||
|
||
translate (width / 2.0) - 350, (height / 2.0) - 240, -450 | ||
rotateY 0.3 | ||
|
||
# Now animate every line object & draw it... | ||
@lines.each_with_index do |line,i| | ||
f1 = sin((i + 1.0) * (millis() / 10000.0) * TWO_PI) | ||
f2 = sin((8.0 - i) * (millis() / 10000.0) * TWO_PI) | ||
push_matrix | ||
translate 0.0, line.ypos, 0.0 | ||
0.upto(line.letters.length - 1) do |j| | ||
if j != 0 | ||
translate(text_width(line.letters[j - 1].char)*75, 0.0, 0.0) | ||
end | ||
rotate_y(f1 * 0.035 * f2) | ||
push_matrix | ||
scale(75.0, 75.0, 75.0) | ||
text(line.letters[j].char, 0.0, 0.0) | ||
pop_matrix | ||
end | ||
pop_matrix | ||
end | ||
rescue => e | ||
puts e.to_s, *e.backtrace | ||
raise e | ||
end | ||
|
||
class AppObject | ||
attr_accessor :app | ||
def method_missing(meth, *args, &block) | ||
app.send(meth, *args, &block) | ||
end | ||
end | ||
|
||
class Line < AppObject | ||
attr_accessor :string, :xpos, :ypos, :highlight_num, | ||
:font, :speed, :curl_in_x, :letters | ||
|
||
def initialize(app, s, i, j, bagelfont) | ||
@app, @string, @xpos, @ypos, @font = app, s, i, j, bagelfont | ||
@letters = [] | ||
f1 = 0.0 | ||
s.each_byte do |c| | ||
f1 += text_width c | ||
@letters << Letter.new(c, f1, 0.0) | ||
end | ||
@curl_in_x = 0.1 | ||
end | ||
end | ||
|
||
class Letter | ||
attr_accessor :char, :x, :y | ||
def initialize(c, x, y) | ||
@char, @x, @y = c, x, y | ||
end | ||
end | ||
end | ||
|
||
KineticType.new :width => 200, :height => 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
require 'ruby-processing' | ||
|
||
class Space < Processing::App | ||
load_java_library "opengl" | ||
|
||
class << self; attr_accessor :instance; end | ||
|
||
class Velocity | ||
attr_accessor :dx, :dy, :dz | ||
def initialize(dx = 0, dy = 0, dz = 0) | ||
@dx, @dy, @dz = dx, dy, dz | ||
end | ||
end | ||
|
||
class PObject | ||
def method_missing(meth, *args, &block) | ||
Space.instance.send(meth, *args, &block) | ||
end | ||
end | ||
|
||
class Position < PObject | ||
attr_accessor :x, :y, :z | ||
def initialize(x = 0, y = 0, z = 0) | ||
@x, @y, @z = x, y, z | ||
end | ||
def move(vel) | ||
if vel | ||
@x += vel.dx | ||
@y += vel.dy | ||
@z += vel.dz | ||
end | ||
translate @x, @y, @z | ||
end | ||
end | ||
|
||
class Rotation < PObject | ||
attr_accessor :x, :y, :z | ||
def initialize(x = 0, y = 0, z = 0) | ||
@x, @y, @z = x, y, z | ||
end | ||
def move(spin) | ||
if spin | ||
@x += spin.dx | ||
@y += spin.dy | ||
@z += spin.dz | ||
end | ||
rotate_x @x | ||
rotate_y @y | ||
rotate_z @z | ||
end | ||
end | ||
|
||
class Shape < PObject | ||
attr_accessor :position, :velocity, :rotation, :spin, :size | ||
def initialize(pos = Position.new, rot = Rotation.new, sz = 10) | ||
@position, @rotation, @size = pos, rot, sz | ||
end | ||
def move | ||
@size = 0 if @size < 0 | ||
position.move(@velocity) | ||
rotation.move(@spin) | ||
end | ||
end | ||
|
||
class Box < Shape | ||
def draw | ||
box size | ||
end | ||
end | ||
|
||
def initialize(*args) | ||
self.class.instance = self | ||
super | ||
end | ||
|
||
def setup | ||
render_mode OPENGL | ||
fill 204 | ||
@vel = Velocity.new 0, 0, 0 | ||
@spin = Velocity.new 0, 0, 0 | ||
@growth = 0 | ||
@object = Box.new(Position.new(0, 200, -20), Rotation.new, 50) | ||
end | ||
|
||
# KEYS = {UP => :up, DOWN => :down, LEFT => :left, RIGHT => :right, SHIFT => :shift} | ||
# class Keyboard | ||
# def method_missing(meth,*args,&block) | ||
# end | ||
# end | ||
|
||
def key_pressed | ||
if key == CODED | ||
shift = false | ||
case keyCode | ||
when UP | ||
if shift | ||
@vel.dy = -20 | ||
else | ||
@vel.dz = -20 | ||
end | ||
when DOWN | ||
if shift | ||
@vel.dy = 20 | ||
else | ||
@vel.dz = 20 | ||
end | ||
when LEFT | ||
@vel.dx = -5 | ||
when RIGHT | ||
@vel.dx = 5 | ||
else | ||
puts "unknown key: #{keyCode}" | ||
end | ||
else | ||
case keyCode | ||
when ?W | ||
@growth -= 1 | ||
when ?E | ||
@growth += 1 | ||
when ?S | ||
@spin.dy -= PI/40 | ||
when ?D | ||
@spin.dy += PI/40 | ||
when ?X | ||
@spin.dx -= PI/40 | ||
when ?C | ||
@spin.dx += PI/40 | ||
else | ||
puts "unknown key: #{keyCode}" | ||
end | ||
end | ||
end | ||
|
||
def key_released | ||
@vel, @spin, @growth = Velocity.new(0,0,0), Velocity.new(0,0,0), 0 | ||
end | ||
|
||
def draw | ||
lights | ||
background 0 | ||
no_stroke | ||
@object.velocity = @vel | ||
@object.spin = @spin | ||
@object.size += @growth | ||
@object.move | ||
@object.draw | ||
rescue => e | ||
puts e.to_s, *e.backtrace | ||
raise e | ||
end | ||
end | ||
|
||
Space.new :full_screen => true |