Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Nov 12, 2020
1 parent 398f311 commit 68ccd9d
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 150 deletions.
27 changes: 27 additions & 0 deletions external_library/gem/toxiclibs/geometry/circle_resolution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'toxiclibs'
java_import 'toxi.geom.Circle'
attr_reader :gfx

def setup
sketch_title 'Circle Resolution'
@gfx = Gfx::ToxiclibsSupport.new(self)
end

def draw
background(0)
no_stroke
fill(255)
res = map1d(mouse_x, 0..width, 3..72)
poly = Circle.new(TVec2D.new(width / 2, height / 2), 200).toPolygon2D(res)
gfx.polygon2D(poly)
fill(255, 0, 0)
poly.each { |vertex| gfx.circle(vertex, 5) }
text(res, 20, 20)
end

def settings
size(600, 600)
smooth 8
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions external_library/gem/toxiclibs/geometry/model_align.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# (c) 2012 Karsten Schmidt / LGPL2 licensed
#
require 'toxiclibs'

java_import 'toxi.geom.Circle'
# container for mesh positions

attr_reader :gfx, :positions
Expand All @@ -20,7 +20,7 @@ def setup
Processing::ArcBall.init(self)
@gfx = Gfx::ToxiclibsSupport.new(self)
# compute mesh positions on circle in XZ plane
@positions = Toxi::Circle.new(200).toPolygon2D(8).map(&:to3DXZ)
@positions = Circle.new(200).toPolygon2D(8).map(&:to3DXZ)
end

def draw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
#
require 'forwardable'
require 'toxiclibs'
require_relative 'blanket'
require_relative 'connection'
require_relative 'particle'
load_library :blanket

attr_reader :b, :physics

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative 'blanket'
require_relative 'connection'
require_relative 'particle'
9 changes: 4 additions & 5 deletions processing_app/library/video/capture/data/droste.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This implementation is based on GLSL code by ArKano22:
// http://www.gamedev.net/topic/590070-glsl-droste/
uniform float time;
uniform int frameCount;
uniform sampler2D texture; // iChannel0 in Shadertoy
uniform vec2 resolution; // iResolution in Shadertoy
uniform int mode;
Expand Down Expand Up @@ -48,14 +48,13 @@ void main( void ){
uv= complexPower(uv, complexDiv(vec2( log(factor) ,TWO_PI), vec2(0.0,TWO_PI) ) );

//RECTANGULAR DROSTE EFFECT:
float FT = fract(time);
float FT = float(frameCount % 100 / 100.0);
FT = log(FT+1.)/log(2.);
uv *= 1.0+FT*(scale-1.0);

float npower = max(nearestPower(uv.x,scale),nearestPower(uv.y,scale));
// uv.x = map(uv.x,-npower,npower,-1.0,1.0);
// uv.y = map(uv.y,-npower,npower,-1.0,1.0);
uv = normalize(uv) * 2;
uv.x = map(uv.x,-npower,npower,-1.0,1.0);
uv.y = map(uv.y,-npower,npower,-1.0,1.0);

//UNDO SHIFT AND SCALE:
gl_FragColor = texture(texture,uv*off+vec2(off));
Expand Down
9 changes: 2 additions & 7 deletions processing_app/library/video/capture/droste.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
load_library :video, :video_event
include_package 'processing.video'
attr_reader :cam, :my_filter, :origin
attr_reader :cam, :my_filter

def settings
size(1280, 960, P2D)
end

def setup
sketch_title 'Droste'
@origin = Time.now
@my_filter = load_shader(data_path('droste.glsl'))
my_filter.set('resolution', width.to_f, height.to_f)
start_capture
end

def time
(Time.now - origin)
end

def start_capture
@cam = Java::ProcessingVideo::Capture.new(self, "UVC Camera (046d:0825)")
cam.start
Expand All @@ -31,7 +26,7 @@ def captureEvent(cam)
def draw
background 0
image(cam, 0, 0, width, height)
my_filter.set('time', time)
my_filter.set('frameCount', frame_count)
return if mouse_pressed?
filter(my_filter)
end
91 changes: 0 additions & 91 deletions processing_app/topics/cellular_automata/library/ca/ca.rb

This file was deleted.

42 changes: 0 additions & 42 deletions processing_app/topics/cellular_automata/wolfram.rb

This file was deleted.

54 changes: 54 additions & 0 deletions processing_app/topics/cellular_automata/wolfram_ca_110.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# RULE 110
# 2 + 4 + 8 + 32 + 64 = 110
# using axiom in sense of an LSystem, starting condition
# see https://en.wikipedia.org/wiki/Rule_110
attr_reader :row, :axiom, :black

def setup
sketch_title 'Wolfram CA Rule 110'
@black = color(0)
# one of most interesting starting points
@axiom = [0, 1, 1, 1, 0, 1, 1, 0]
initial
end

def draw
reset if row > height
display
end

def display
(0..width).each_cons(3) do |triple|
left, center, right = *triple
a = get(left, row)
b = get(center, row)
c = get(right, row)
idx = 0
idx += 1 if a == black
idx += 2 if b == black
idx += 4 if c == black
set(center, row.succ, black) unless axiom[idx].zero?
end
@row += 1
end

def settings
size(400, 400)
end

def initial
background(255)
set(1, 0, black)
@row = 0
end

def reset
# create some random starting conditions and re-start
initial
asum = 0
# filter out some of less interesting results
while asum < 4 || asum > 5
@axiom = Array.new(8) { rand(0..1) }
asum = axiom.inject(:+)
end
end
60 changes: 60 additions & 0 deletions processing_app/topics/cellular_automata/wolfram_ca_30.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# RULE 30
# using axiom in sense of an LSystem, starting condition
# see https://en.wikipedia.org/wiki/Rule_30
attr_reader :row, :axiom

def setup
sketch_title 'Wolfram CA Rule 30'
# An interesting starting point
@axiom = [0, 1, 0, 1, 1, 0, 1, 0]
initial
end

def black
color(0)
end

def white
color(255)
end

def draw
reset if row > height
display
end

def display
(0..width).each_cons(3) do |triple|
left, center, right = *triple
a = get(left, row)
b = get(center, row)
c = get(right, row)
idx = 0
case a + b + c
when 3 * white
idx = 7
when 2 * black + white
idx = (a == white)? 3 : (b == white)? 5 : 6
when 2 * white + black
idx = (c == black)? 1 : (a == black)? 4 : 2
end
set(center, row.succ, white) unless axiom[idx].zero?
end
@row += 1
end

def settings
size(400, 400)
end

def initial
background(0)
set(width / 2, 0, white)
@row = 0
end

def reset
# create some random starting conditions and re-start
initial
@axiom = Array.new(8) {rand(0..1)}
end

0 comments on commit 68ccd9d

Please sign in to comment.