Skip to content

Commit 68ccd9d

Browse files
committed
refactoring
1 parent 398f311 commit 68ccd9d

File tree

17 files changed

+153
-150
lines changed

17 files changed

+153
-150
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
require 'toxiclibs'
4+
java_import 'toxi.geom.Circle'
5+
attr_reader :gfx
6+
7+
def setup
8+
sketch_title 'Circle Resolution'
9+
@gfx = Gfx::ToxiclibsSupport.new(self)
10+
end
11+
12+
def draw
13+
background(0)
14+
no_stroke
15+
fill(255)
16+
res = map1d(mouse_x, 0..width, 3..72)
17+
poly = Circle.new(TVec2D.new(width / 2, height / 2), 200).toPolygon2D(res)
18+
gfx.polygon2D(poly)
19+
fill(255, 0, 0)
20+
poly.each { |vertex| gfx.circle(vertex, 5) }
21+
text(res, 20, 20)
22+
end
23+
24+
def settings
25+
size(600, 600)
26+
smooth 8
27+
end
Loading

external_library/gem/toxiclibs/geometry/model_align.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# (c) 2012 Karsten Schmidt / LGPL2 licensed
77
#
88
require 'toxiclibs'
9-
9+
java_import 'toxi.geom.Circle'
1010
# container for mesh positions
1111

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

2626
def draw

external_library/gem/toxiclibs/physics/soft_body/soft_body_square_adapted.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
#
3232
require 'forwardable'
3333
require 'toxiclibs'
34-
require_relative 'blanket'
35-
require_relative 'connection'
36-
require_relative 'particle'
34+
load_library :blanket
3735

3836
attr_reader :b, :physics
3937

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require_relative 'blanket'
2+
require_relative 'connection'
3+
require_relative 'particle'

processing_app/library/video/capture/data/droste.glsl

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This implementation is based on GLSL code by ArKano22:
22
// http://www.gamedev.net/topic/590070-glsl-droste/
3-
uniform float time;
3+
uniform int frameCount;
44
uniform sampler2D texture; // iChannel0 in Shadertoy
55
uniform vec2 resolution; // iResolution in Shadertoy
66
uniform int mode;
@@ -48,14 +48,13 @@ void main( void ){
4848
uv= complexPower(uv, complexDiv(vec2( log(factor) ,TWO_PI), vec2(0.0,TWO_PI) ) );
4949

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

5555
float npower = max(nearestPower(uv.x,scale),nearestPower(uv.y,scale));
56-
// uv.x = map(uv.x,-npower,npower,-1.0,1.0);
57-
// uv.y = map(uv.y,-npower,npower,-1.0,1.0);
58-
uv = normalize(uv) * 2;
56+
uv.x = map(uv.x,-npower,npower,-1.0,1.0);
57+
uv.y = map(uv.y,-npower,npower,-1.0,1.0);
5958

6059
//UNDO SHIFT AND SCALE:
6160
gl_FragColor = texture(texture,uv*off+vec2(off));
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
load_library :video, :video_event
22
include_package 'processing.video'
3-
attr_reader :cam, :my_filter, :origin
3+
attr_reader :cam, :my_filter
44

55
def settings
66
size(1280, 960, P2D)
77
end
88

99
def setup
1010
sketch_title 'Droste'
11-
@origin = Time.now
1211
@my_filter = load_shader(data_path('droste.glsl'))
1312
my_filter.set('resolution', width.to_f, height.to_f)
1413
start_capture
1514
end
1615

17-
def time
18-
(Time.now - origin)
19-
end
20-
2116
def start_capture
2217
@cam = Java::ProcessingVideo::Capture.new(self, "UVC Camera (046d:0825)")
2318
cam.start
@@ -31,7 +26,7 @@ def captureEvent(cam)
3126
def draw
3227
background 0
3328
image(cam, 0, 0, width, height)
34-
my_filter.set('time', time)
29+
my_filter.set('frameCount', frame_count)
3530
return if mouse_pressed?
3631
filter(my_filter)
3732
end

processing_app/topics/cellular_automata/library/ca/ca.rb

-91
This file was deleted.

processing_app/topics/cellular_automata/wolfram.rb

-42
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# RULE 110
2+
# 2 + 4 + 8 + 32 + 64 = 110
3+
# using axiom in sense of an LSystem, starting condition
4+
# see https://en.wikipedia.org/wiki/Rule_110
5+
attr_reader :row, :axiom, :black
6+
7+
def setup
8+
sketch_title 'Wolfram CA Rule 110'
9+
@black = color(0)
10+
# one of most interesting starting points
11+
@axiom = [0, 1, 1, 1, 0, 1, 1, 0]
12+
initial
13+
end
14+
15+
def draw
16+
reset if row > height
17+
display
18+
end
19+
20+
def display
21+
(0..width).each_cons(3) do |triple|
22+
left, center, right = *triple
23+
a = get(left, row)
24+
b = get(center, row)
25+
c = get(right, row)
26+
idx = 0
27+
idx += 1 if a == black
28+
idx += 2 if b == black
29+
idx += 4 if c == black
30+
set(center, row.succ, black) unless axiom[idx].zero?
31+
end
32+
@row += 1
33+
end
34+
35+
def settings
36+
size(400, 400)
37+
end
38+
39+
def initial
40+
background(255)
41+
set(1, 0, black)
42+
@row = 0
43+
end
44+
45+
def reset
46+
# create some random starting conditions and re-start
47+
initial
48+
asum = 0
49+
# filter out some of less interesting results
50+
while asum < 4 || asum > 5
51+
@axiom = Array.new(8) { rand(0..1) }
52+
asum = axiom.inject(:+)
53+
end
54+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# RULE 30
2+
# using axiom in sense of an LSystem, starting condition
3+
# see https://en.wikipedia.org/wiki/Rule_30
4+
attr_reader :row, :axiom
5+
6+
def setup
7+
sketch_title 'Wolfram CA Rule 30'
8+
# An interesting starting point
9+
@axiom = [0, 1, 0, 1, 1, 0, 1, 0]
10+
initial
11+
end
12+
13+
def black
14+
color(0)
15+
end
16+
17+
def white
18+
color(255)
19+
end
20+
21+
def draw
22+
reset if row > height
23+
display
24+
end
25+
26+
def display
27+
(0..width).each_cons(3) do |triple|
28+
left, center, right = *triple
29+
a = get(left, row)
30+
b = get(center, row)
31+
c = get(right, row)
32+
idx = 0
33+
case a + b + c
34+
when 3 * white
35+
idx = 7
36+
when 2 * black + white
37+
idx = (a == white)? 3 : (b == white)? 5 : 6
38+
when 2 * white + black
39+
idx = (c == black)? 1 : (a == black)? 4 : 2
40+
end
41+
set(center, row.succ, white) unless axiom[idx].zero?
42+
end
43+
@row += 1
44+
end
45+
46+
def settings
47+
size(400, 400)
48+
end
49+
50+
def initial
51+
background(0)
52+
set(width / 2, 0, white)
53+
@row = 0
54+
end
55+
56+
def reset
57+
# create some random starting conditions and re-start
58+
initial
59+
@axiom = Array.new(8) {rand(0..1)}
60+
end

0 commit comments

Comments
 (0)