Skip to content

Commit 43adcca

Browse files
committed
fix penrose
1 parent 94bb564 commit 43adcca

File tree

8 files changed

+236
-102
lines changed

8 files changed

+236
-102
lines changed

contributed/25_squares.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Creative Coding
2+
# # # # #
3+
# Vera Molnar – 25 Squares
4+
# # # # #
5+
# Interpretation by Martin Vögeli
6+
# Converted to propane Martin Prout
7+
# # # # #
8+
# Based on code by Indae Hwang and Jon McCormack
9+
def settings
10+
size(600, 600)
11+
end
12+
13+
def setup
14+
sketch_title '25 Squares'
15+
rect_mode(CORNER)
16+
no_stroke
17+
frame_rate(1) # set the frame rate to 1 draw call per second
18+
end
19+
20+
def draw
21+
background(180) # clear the screen to grey
22+
grid_size = 5 # rand(3..12) # select a rand number of squares each frame
23+
gap = 5 # rand(5..50) # select a rand gap between each square
24+
# calculate the size of each square for the given number of squares and gap between them
25+
cellsize = (width - (grid_size + 1) * gap) / grid_size
26+
position = -> (count) { gap * (count + 1) + cellsize * count + rand(-5..5) }
27+
grid_size.times do |i|
28+
grid_size.times do |j|
29+
# Note how to create transparent fill with web color JRubyArt
30+
rand(0..5) > 4 ? fill(color('#a11220'), 180.0) : fill(color('#884444'), 180.0)
31+
rect(position.call(i), position.call(j), cellsize, cellsize)
32+
end
33+
end
34+
# save your drawings when you press keyboard 's' continually
35+
save_frame('######.jpg') if key_pressed? && key == 's'
36+
end # end of draw
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Andrew Glassner - www.glassner.com & www.imaginary-institute.com
2+
# Translated to JRubyArt by Martin Prout class Ag009Hyc < Propane::App
3+
load_library :AULib
4+
include_package 'AULib'
5+
6+
attr_reader :au_camera, :wave_x, :wave_y, :wave_phase
7+
GRID_RES = 20
8+
9+
def settings
10+
size(500, 500)
11+
end
12+
13+
def setup
14+
sketch_title 'Ag008Hyc'
15+
@au_camera = AUCamera.new(self, 300, 4, true)
16+
@wave_x = width / 2.0
17+
@wave_y = height / 2.0
18+
@wave_phase = 0
19+
end
20+
21+
def get_wave(x, y)
22+
d = dist(wave_x, wave_y, x, y)
23+
side_dist = dist(wave_x, wave_y, 0, 0)
24+
angle = TWO_PI * d / side_dist
25+
map1d(sin(angle + wave_phase), (-1.0..1), (0.1..0.9))
26+
end
27+
28+
def draw
29+
theta = au_camera.get_time
30+
@wave_phase = TWO_PI * (1 - theta)
31+
background(color(246, 250, 185))
32+
fill(color(95, 10, 40))
33+
no_stroke
34+
box_size = width * 2.0 / GRID_RES
35+
function = -> (count) { (1 + 2 * count) / (2.0 * GRID_RES) }
36+
(0...GRID_RES).each do |y|
37+
(-1...GRID_RES).each do |x|
38+
fx = function.call(x)
39+
fy = function.call(y)
40+
fx += 0.5 / GRID_RES if y.even?
41+
sx = width * fx
42+
sy = height * fy
43+
w = get_wave(sx, sy)
44+
angle = atan2(sy - (height / 2.0), sx - (width / 2.0))
45+
push_matrix
46+
translate(sx, sy)
47+
rotate(angle)
48+
ellipse(0, 0, w * box_size, (1 - w) * box_size)
49+
pop_matrix
50+
end
51+
end
52+
au_camera.expose
53+
end

external_library/java/hype/magnetic_field.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
load_library :hype
32
include_package 'hype'
43
# Use Hype namespace

processing_app/topics/lsystems/library/grammar/grammar.rb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,97 @@ def generate(gen)
2828
end
2929
end
3030
end
31+
32+
33+
Turtle = Struct.new(:x, :y, :angle, :color)
34+
35+
#############################
36+
# PenroseColored class
37+
#############################
38+
class PenroseColored
39+
include Processing::Proxy
40+
41+
attr_reader :axiom, :grammar, :start_length, :theta, :production,
42+
:draw_length, :repeats, :xpos, :ypos
43+
44+
DELTA = 36 # degrees
45+
RED = 70<<24|200<<16|0<<8|0 # using bit operations to set color int
46+
BLUE = 70<<24|0<<16|0<<8|200
47+
48+
def initialize(xpos, ypos) # Note use of abbreviated grammar
49+
@axiom = '[X]2+[X]2+[X]2+[X]2+[X]' # nos, used to indicate repeats
50+
@grammar = Grammar.new(
51+
axiom,
52+
'F' => '', # a so called deletion rule
53+
'W' => 'YBF2+ZRF4-XBF[-YBF4-WRF]2+',
54+
'X' => '+YBF2-ZRF[3-WRF2-XBF]+',
55+
'Y' => '-WRF2+XBF[3+YBF2+ZRF]-',
56+
'Z' => '2-YBF4+WRF[+ZRF4+XBF]2-XBF')
57+
@start_length = 1000.0
58+
@theta = 0
59+
@xpos = xpos
60+
@ypos = ypos
61+
@production = axiom.split('')
62+
@draw_length = start_length
63+
end
64+
65+
##############################################################################
66+
# Not strictly in the spirit of either processing in my render
67+
# function I have ignored the processing translate/rotate functions in favour
68+
# of the direct calculation of the new x and y positions, thus avoiding such
69+
# affine transformations.
70+
##############################################################################
71+
72+
def render
73+
repeats = 1
74+
ignored = %w(W X Y Z)
75+
repeated = %w(1 2 3 4)
76+
pen = Turtle.new(xpos, ypos, theta, :R) # simple Struct for pen, symbol :R = red
77+
stack = [] # simple array for stack
78+
production.each do |element|
79+
case element
80+
when 'F'
81+
pen = draw_line(pen, draw_length)
82+
when '+'
83+
pen.angle += DELTA * repeats
84+
repeats = 1
85+
when '-'
86+
pen.angle -= DELTA * repeats
87+
repeats = 1
88+
when '['
89+
stack << pen.dup # push a copy current pen to stack
90+
when ']'
91+
pen = stack.pop # assign current pen to instance off the stack
92+
when 'R', 'B'
93+
pen.color = element.to_sym # set pen color as symbol
94+
when *ignored
95+
when *repeated
96+
repeats = element.to_i
97+
else puts format('Character %s not in grammar', element)
98+
end
99+
end
100+
end
101+
#####################################################
102+
# create grammar from axiom and # rules (adjust scale)
103+
#####################################################
104+
105+
def create_grammar(gen)
106+
@draw_length *= 0.5**gen
107+
@production = grammar.generate gen
108+
end
109+
110+
private
111+
112+
####################################################################
113+
# draws line using current pen position, color and length parameters
114+
# returns a pen corresponding to the new position
115+
###################################################################
116+
117+
def draw_line(pen, length)
118+
stroke(pen.color == :R ? RED : BLUE)
119+
new_xpos = pen.x - length * DegLut.cos(pen.angle)
120+
new_ypos = pen.y - length * DegLut.sin(pen.angle)
121+
line(pen.x, pen.y, new_xpos, new_ypos) # draw line
122+
Turtle.new(new_xpos, new_ypos, pen.angle, pen.color) # return pen @ new pos
123+
end
124+
end

processing_app/topics/lsystems/penrose.rb

Lines changed: 5 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
# in JRubyArt by Martin Prout
44
######################################################
55
load_library :grammar
6-
76
attr_reader :penrose
87

8+
def settings
9+
size 800, 800
10+
smooth
11+
end
12+
913
def setup
1014
sketch_title 'Penrose'
1115
stroke_weight 2
@@ -18,103 +22,3 @@ def draw
1822
background 0
1923
penrose.render
2024
end
21-
22-
Turtle = Struct.new(:x, :y, :angle, :color)
23-
24-
#############################
25-
# PenroseColored class
26-
#############################
27-
class PenroseColored
28-
include Processing::Proxy
29-
30-
attr_reader :axiom, :grammar, :start_length, :theta, :production,
31-
:draw_length, :repeats, :xpos, :ypos
32-
33-
DELTA = 36 # degrees
34-
RED = 70<<24|200<<16|0<<8|0 # using bit operations to set color int
35-
BLUE = 70<<24|0<<16|0<<8|200
36-
37-
def initialize(xpos, ypos) # Note use of abbreviated grammar
38-
@axiom = '[X]2+[X]2+[X]2+[X]2+[X]' # nos, used to indicate repeats
39-
@grammar = Grammar.new(
40-
axiom,
41-
'F' => '', # a so called deletion rule
42-
'W' => 'YBF2+ZRF4-XBF[-YBF4-WRF]2+',
43-
'X' => '+YBF2-ZRF[3-WRF2-XBF]+',
44-
'Y' => '-WRF2+XBF[3+YBF2+ZRF]-',
45-
'Z' => '2-YBF4+WRF[+ZRF4+XBF]2-XBF')
46-
@start_length = 1000.0
47-
@theta = 0
48-
@xpos = xpos
49-
@ypos = ypos
50-
@production = axiom
51-
@draw_length = start_length
52-
end
53-
54-
##############################################################################
55-
# Not strictly in the spirit of either processing in my render
56-
# function I have ignored the processing translate/rotate functions in favour
57-
# of the direct calculation of the new x and y positions, thus avoiding such
58-
# affine transformations.
59-
##############################################################################
60-
61-
def render
62-
repeats = 1
63-
ignored = %w(W X Y Z)
64-
repeated = %w(1 2 3 4)
65-
pen = Turtle.new(xpos, ypos, theta, :R) # simple Struct for pen, symbol :R = red
66-
stack = [] # simple array for stack
67-
production.each do |element|
68-
case element
69-
when 'F'
70-
pen = draw_line(pen, draw_length)
71-
when '+'
72-
pen.angle += DELTA * repeats
73-
repeats = 1
74-
when '-'
75-
pen.angle -= DELTA * repeats
76-
repeats = 1
77-
when '['
78-
stack << pen.dup # push a copy current pen to stack
79-
when ']'
80-
pen = stack.pop # assign current pen to instance off the stack
81-
when 'R', 'B'
82-
pen.color = element.to_sym # set pen color as symbol
83-
when *ignored
84-
when *repeated
85-
repeats = element.to_i
86-
else puts format('Character %s not in grammar', element)
87-
end
88-
end
89-
end
90-
91-
#####################################################
92-
# create grammar from axiom and # rules (adjust scale)
93-
#####################################################
94-
95-
def create_grammar(gen)
96-
@draw_length *= 0.5**gen
97-
@production = grammar.generate gen
98-
end
99-
100-
private
101-
102-
####################################################################
103-
# draws line using current pen position, color and length parameters
104-
# returns a pen corresponding to the new position
105-
###################################################################
106-
107-
def draw_line(pen, length)
108-
stroke(pen.color == :R ? RED : BLUE)
109-
new_xpos = pen.x - length * DegLut.cos(pen.angle)
110-
new_ypos = pen.y - length * DegLut.sin(pen.angle)
111-
line(pen.x, pen.y, new_xpos, new_ypos) # draw line
112-
Turtle.new(new_xpos, new_ypos, pen.angle, pen.color) # return pen @ new pos
113-
end
114-
end
115-
116-
def settings
117-
size 800, 800
118-
smooth
119-
end
120-
87.6 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//---------------------------------------------------------
2+
// Display endless moving background using a tile texture.
3+
// Contributed by martiSteiger
4+
//---------------------------------------------------------
5+
6+
uniform float time;
7+
uniform vec2 resolution;
8+
uniform sampler2D tileImage;
9+
10+
#define TILES_COUNT_X 4.0
11+
12+
void main() {
13+
vec2 pos = gl_FragCoord.xy - vec2(4.0 * time);
14+
vec2 p = (resolution - TILES_COUNT_X * pos) / resolution.x;
15+
vec3 col = texture2D (tileImage, p).xyz;
16+
gl_FragColor = vec4 (col, 1.0);
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#-------------------------------------------------------------
2+
# Display endless moving background using a tile texture.
3+
# Contributed by martiSteiger
4+
#-------------------------------------------------------------
5+
6+
attr_reader :tile_texture, :tile_shader, :time0
7+
8+
def settings
9+
size(640, 480, P2D)
10+
end
11+
12+
def setup
13+
sketch_title 'Infinite Tiling'
14+
texture_wrap(REPEAT)
15+
@tile_texture = load_image(data_path('penrose.jpg'))
16+
load_tile_shader
17+
@time0 = Time.now
18+
end
19+
20+
def load_tile_shader
21+
@tile_shader = load_shader(data_path('scroller.glsl'))
22+
tile_shader.set('resolution', width.to_f, height.to_f)
23+
tile_shader.set('tileImage', tile_texture)
24+
end
25+
26+
def draw
27+
mil = (Time.now - time0).to_f
28+
tile_shader.set('time', mil)
29+
shader(tile_shader)
30+
rect(0, 0, width, height)
31+
end

0 commit comments

Comments
 (0)