View lexing.rb
to_lex = <<RUBY
1 + 1
RUBY
# ===== https://rubygems.org/gems/parser =====
require 'parser/ruby23'
lexer = Parser::Lexer.new(23)
lexer.diagnostics = Parser::Diagnostic::Engine.new
lexer.static_env = Parser::StaticEnvironment.new
lexer.source_buffer = Parser::Ruby23.send(:setup_source_buffer, 'file.rb', 1, to_lex, Encoding::UTF_8)
View circle.rb
# https://twitter.com/josh_cheek/status/804868012620779521
radius = 21
0.step by: 1 do |degrees|
angle = degrees*Math::PI/180
y = (radius * (Math.sin(angle) / 2 + 1)).to_i
x = (radius * (Math.cos(angle) / 2 + 1)).to_i
print "\e[#{y};#{2*x}HXX"
sleep 0.01
end
View heredoc_example.sh
$ sed 'p;s/b/w/' <<HERE | sed 'p;s/a/e/'
> bat
> ball
> HERE
bat
bet
wat
wet
ball
bell
View sib_binary_finish_criteria.rb
# A binary implementation of https://github.com/JoshCheek/seeing_is_believing/blob/7cf75d540344c3377d8cbf66d12853c2b23c763b/lib/seeing_is_believing/event_stream/consumer.rb#L10-L50
class Fixnum
def inspect
sprintf '%04b', self # => "0001", "0010", "0100", "1000", "1111", "0000", "0000", "0001", "0001", "0101", "0101", "1101", "1101", "1111", "1111"
end # => :inspect
end # => :inspect
class FinishCriteria
FinishCriteria = [
View parametric_square.rb
require 'graphics'
require 'strscan'
class LSystem
attr_accessor :rules, :cache
def initialize(start:, rules:)
self.rules = rules
self.cache = [[start]]
end
View lissajous-curves.rb
# encoding: utf-8
# Screenshots:
# http://joshcheek.deviantart.com/gallery/61181398/Lissajous-Curves
# Videos:
# https://vimeo.com/193155770
# https://vimeo.com/193155808
# https://vimeo.com/193156077
# https://vimeo.com/193156097
View indulgent_bezier.rb
# https://vimeo.com/192222228
require "graphics"
class Bezier < Graphics::Simulation
def initialize
super 800, 600, 24
@radius = 75
@num_lines = 200
@crnt_iteration = 0
@iteration_dir = -1
View calculate_points_at_distance_on_line.rb
# encoding: utf-8
# Given a point, a line, and a distance, calculate the two points on that line that are that distance away.
# Relevant equations
# eqn for line (m here is our gslope, b is the y-intercept)
# y = mx + b
# pythagorean theorem from origin (r, the radius, will be our gdist, the distance between the points)
# r**2 = x**2 + y**2
View _names_and_references.txt
Heighway dragon
https://en.wikipedia.org/w/index.php?title=L-system&oldid=748420339#Example_6:_Dragon_curve
Fractal plant
https://en.wikipedia.org/w/index.php?title=L-system&oldid=748420339#Example_7:_Fractal_plant
Sierpinski Gasket
https://en.wikipedia.org/wiki/L-system#Example_5:_Sierpinski_triangle
Koch Curve