texplay 0.2.800 → 0.2.900
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +138 -119
- data/README.markdown +43 -41
- data/Rakefile +68 -68
- data/examples/common.rb +8 -8
- data/examples/example_alpha_blend.rb +31 -31
- data/examples/example_bezier.rb +42 -42
- data/examples/example_color_control.rb +69 -69
- data/examples/example_color_transform.rb +64 -67
- data/examples/example_color_transform_circle.rb +65 -0
- data/examples/example_dup.rb +75 -75
- data/examples/example_each.rb +42 -42
- data/examples/example_effect.rb +35 -35
- data/examples/example_fill.rb +44 -44
- data/examples/example_fill_old.rb +49 -49
- data/examples/example_fluent.rb +31 -31
- data/examples/example_gen_eval.rb +34 -34
- data/examples/example_hash_arguments.rb +47 -47
- data/examples/example_light.rb +77 -0
- data/examples/example_lsystem.rb +61 -61
- data/examples/example_melt.rb +27 -27
- data/examples/example_meyet.rb +64 -0
- data/examples/example_polyline.rb +43 -43
- data/examples/example_scale.rb +29 -29
- data/examples/example_simple.rb +48 -38
- data/examples/example_sync.rb +60 -60
- data/examples/example_trace.rb +1 -1
- data/examples/example_turtle.rb +40 -40
- data/examples/example_weird.rb +3 -1
- data/examples/media/Thumbs.db +0 -0
- data/ext/texplay/actions.c +999 -1001
- data/ext/texplay/actions.h +60 -60
- data/ext/texplay/bindings.c +1162 -1149
- data/ext/texplay/bindings.h +46 -46
- data/ext/texplay/cache.c +118 -118
- data/ext/texplay/cache.h +24 -24
- data/ext/texplay/compat.h +27 -27
- data/ext/texplay/extconf.rb +28 -28
- data/ext/texplay/gen_eval.c +211 -211
- data/ext/texplay/gen_eval.h +20 -20
- data/ext/texplay/graphics_utils.c +188 -63
- data/ext/texplay/graphics_utils.h +0 -1
- data/ext/texplay/object2module.c +171 -171
- data/ext/texplay/object2module.h +11 -11
- data/ext/texplay/texplay.c +169 -169
- data/ext/texplay/texplay.h +147 -130
- data/ext/texplay/utils.c +816 -752
- data/ext/texplay/utils.h +151 -145
- data/lib/texplay-contrib.rb +171 -171
- data/lib/texplay.rb +162 -137
- data/lib/texplay/version.rb +1 -1
- metadata +9 -5
data/examples/example_fluent.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'common'
|
3
|
-
require 'gosu'
|
4
|
-
require 'texplay'
|
5
|
-
|
6
|
-
class W < Gosu::Window
|
7
|
-
def initialize
|
8
|
-
super(1024, 768, false, 20)
|
9
|
-
@img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
|
10
|
-
@img.rect 0,0, @img.width - 1, @img.height - 1
|
11
|
-
|
12
|
-
# test the fluent interface
|
13
|
-
@img.
|
14
|
-
line(0, 0, 1024, 1024).
|
15
|
-
circle(20, 20, 50).
|
16
|
-
rect 30, 30, 100, 100
|
17
|
-
end
|
18
|
-
|
19
|
-
def draw
|
20
|
-
x = @img.width * rand
|
21
|
-
y = @img.height * rand
|
22
|
-
|
23
|
-
@img.draw 100, 50,1
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
w = W.new
|
30
|
-
w.show
|
31
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'gosu'
|
4
|
+
require 'texplay'
|
5
|
+
|
6
|
+
class W < Gosu::Window
|
7
|
+
def initialize
|
8
|
+
super(1024, 768, false, 20)
|
9
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
|
10
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
11
|
+
|
12
|
+
# test the fluent interface
|
13
|
+
@img.
|
14
|
+
line(0, 0, 1024, 1024).
|
15
|
+
circle(20, 20, 50).
|
16
|
+
rect 30, 30, 100, 100
|
17
|
+
end
|
18
|
+
|
19
|
+
def draw
|
20
|
+
x = @img.width * rand
|
21
|
+
y = @img.height * rand
|
22
|
+
|
23
|
+
@img.draw 100, 50,1
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
w = W.new
|
30
|
+
w.show
|
31
|
+
|
@@ -1,34 +1,34 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'common'
|
3
|
-
require 'texplay'
|
4
|
-
|
5
|
-
|
6
|
-
class W < Gosu::Window
|
7
|
-
def initialize
|
8
|
-
super(1024, 768, false, 20)
|
9
|
-
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
|
-
|
11
|
-
@width = @img.width
|
12
|
-
@height = @img.height
|
13
|
-
|
14
|
-
# turn alpha blending and filling on
|
15
|
-
@img.set_options :alpha_blend => true, :fill => true
|
16
|
-
end
|
17
|
-
|
18
|
-
def draw
|
19
|
-
|
20
|
-
# Gen_eval lets us use local instance vars within the block
|
21
|
-
# even though the block appears to be getting instance_eval'd
|
22
|
-
# for more information see gen_eval.c and object2module.c
|
23
|
-
@img.paint {
|
24
|
-
rect @width * rand, @height * rand, @width * rand, @height * rand,
|
25
|
-
:color => [rand, rand ,rand, rand]
|
26
|
-
}
|
27
|
-
|
28
|
-
@img.draw 100, 50,1
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
w = W.new
|
33
|
-
w.show
|
34
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
|
6
|
+
class W < Gosu::Window
|
7
|
+
def initialize
|
8
|
+
super(1024, 768, false, 20)
|
9
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
|
+
|
11
|
+
@width = @img.width
|
12
|
+
@height = @img.height
|
13
|
+
|
14
|
+
# turn alpha blending and filling on
|
15
|
+
@img.set_options :alpha_blend => true, :fill => true
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw
|
19
|
+
|
20
|
+
# Gen_eval lets us use local instance vars within the block
|
21
|
+
# even though the block appears to be getting instance_eval'd
|
22
|
+
# for more information see gen_eval.c and object2module.c
|
23
|
+
@img.paint {
|
24
|
+
rect @width * rand, @height * rand, @width * rand, @height * rand,
|
25
|
+
:color => [rand, rand ,rand, rand]
|
26
|
+
}
|
27
|
+
|
28
|
+
@img.draw 100, 50,1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
w = W.new
|
33
|
+
w.show
|
34
|
+
|
@@ -1,47 +1,47 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'common'
|
3
|
-
require 'texplay'
|
4
|
-
|
5
|
-
|
6
|
-
class W < Gosu::Window
|
7
|
-
def initialize
|
8
|
-
super(1024, 768, false, 20)
|
9
|
-
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
|
-
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
11
|
-
|
12
|
-
|
13
|
-
# put a border on the image
|
14
|
-
@img.rect 0,0, @img.width - 1, @img.height - 1
|
15
|
-
|
16
|
-
# it can be annoying having to specify a bunch of :hash_arguments for every action
|
17
|
-
# here is how you specify common hash args that all actions will use (in the same image)
|
18
|
-
|
19
|
-
# all actions that respond to 'thickness' use a thickness of 8 pixels
|
20
|
-
# also set the color to random
|
21
|
-
@img.set_options :thickness => 8, :color => :rand
|
22
|
-
|
23
|
-
@img.rect 100, 100, 200, 200, :fill => false
|
24
|
-
|
25
|
-
# NOTE: for ngon, the parameters are as follows: x, y, radius, num_sides
|
26
|
-
@img.ngon 400, 400, 40, 3
|
27
|
-
|
28
|
-
# NOTE: the defaults can also be overidden:
|
29
|
-
@img.ngon 400, 200, 90, 6, :thickness => 1
|
30
|
-
|
31
|
-
# you can also delete the defaults
|
32
|
-
@img.delete_options
|
33
|
-
|
34
|
-
# this action will no longer have any default values
|
35
|
-
@img.ngon 200, 400, 90, 10
|
36
|
-
end
|
37
|
-
|
38
|
-
def draw
|
39
|
-
@img.draw 100, 50,1
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
w = W.new
|
46
|
-
w.show
|
47
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
|
6
|
+
class W < Gosu::Window
|
7
|
+
def initialize
|
8
|
+
super(1024, 768, false, 20)
|
9
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
|
+
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
11
|
+
|
12
|
+
|
13
|
+
# put a border on the image
|
14
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
15
|
+
|
16
|
+
# it can be annoying having to specify a bunch of :hash_arguments for every action
|
17
|
+
# here is how you specify common hash args that all actions will use (in the same image)
|
18
|
+
|
19
|
+
# all actions that respond to 'thickness' use a thickness of 8 pixels
|
20
|
+
# also set the color to random
|
21
|
+
@img.set_options :thickness => 8, :color => :rand
|
22
|
+
|
23
|
+
@img.rect 100, 100, 200, 200, :fill => false
|
24
|
+
|
25
|
+
# NOTE: for ngon, the parameters are as follows: x, y, radius, num_sides
|
26
|
+
@img.ngon 400, 400, 40, 3
|
27
|
+
|
28
|
+
# NOTE: the defaults can also be overidden:
|
29
|
+
@img.ngon 400, 200, 90, 6, :thickness => 1
|
30
|
+
|
31
|
+
# you can also delete the defaults
|
32
|
+
@img.delete_options
|
33
|
+
|
34
|
+
# this action will no longer have any default values
|
35
|
+
@img.ngon 200, 400, 90, 10
|
36
|
+
end
|
37
|
+
|
38
|
+
def draw
|
39
|
+
@img.draw 100, 50,1
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
w = W.new
|
46
|
+
w.show
|
47
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'gosu'
|
4
|
+
require 'texplay'
|
5
|
+
|
6
|
+
class W < Gosu::Window
|
7
|
+
def initialize
|
8
|
+
super(500, 500, false, 20)
|
9
|
+
|
10
|
+
@x1 = 10
|
11
|
+
@x2 = 200
|
12
|
+
@y1 = 10
|
13
|
+
@y2 = 10
|
14
|
+
|
15
|
+
@radius = 100.0
|
16
|
+
@inner = 20.0
|
17
|
+
@max_opacity = 0.5
|
18
|
+
@max_opacity2 = 0.5
|
19
|
+
|
20
|
+
penumbra = (@radius - @inner).to_i
|
21
|
+
|
22
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
|
23
|
+
#@img.rect(0, 0, @img.width - 1, @img.height - 1, :fill => true)
|
24
|
+
|
25
|
+
@circ2 = TexPlay.create_image(self, @radius * 2, @radius * 2)
|
26
|
+
|
27
|
+
@circ1 = TexPlay.create_image(self, @radius * 2, @radius * 2)
|
28
|
+
|
29
|
+
|
30
|
+
shading_step = @max_opacity2.to_f / penumbra.to_f
|
31
|
+
@radius.to_i.downto(@inner) { |r|
|
32
|
+
@circ1.circle @radius, @radius, r, :color => [1, 0, 0, ((@radius - r) * shading_step)],
|
33
|
+
:fill => true
|
34
|
+
}
|
35
|
+
|
36
|
+
@circ1.circle @radius, @radius, @inner, :color => [1, 0, 0, @max_opacity2], :fill => true
|
37
|
+
|
38
|
+
shading_step = @max_opacity.to_f / penumbra.to_f
|
39
|
+
@radius.to_i.downto(@inner) { |r|
|
40
|
+
@circ2.circle @radius, @radius, r, :color => [0, 0, 1, ((@radius - r) * shading_step)],
|
41
|
+
:fill => true
|
42
|
+
}
|
43
|
+
|
44
|
+
@circ2.circle @radius, @radius, @inner, :color => [0, 0, 1, @max_opacity], :fill => true
|
45
|
+
end
|
46
|
+
|
47
|
+
def draw
|
48
|
+
@x1 += 1
|
49
|
+
@y1 += 1
|
50
|
+
|
51
|
+
@x2 -= 1
|
52
|
+
@y2 += 1
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
@img.draw 10, 10,1
|
57
|
+
@circ1.draw @x1, @y1,1
|
58
|
+
@circ2.draw @x2, @y1,1
|
59
|
+
|
60
|
+
if button_down?(Gosu::KbEscape)
|
61
|
+
IL.Enable(IL::ORIGIN_SET)
|
62
|
+
IL.OriginFunc(IL::ORIGIN_UPPER_LEFT)
|
63
|
+
# screenshot.crop(0,0, 500, 500).save("screenshot.jpg").free
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def update
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
w = W.new
|
76
|
+
w.show
|
77
|
+
|
data/examples/example_lsystem.rb
CHANGED
@@ -1,61 +1,61 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'gosu'
|
3
|
-
|
4
|
-
Dragon = TexPlay::LSystem.new do
|
5
|
-
rule "F" => "F"
|
6
|
-
rule "X" => "X+YF+"
|
7
|
-
rule "Y" => "-FX-Y"
|
8
|
-
angle 90
|
9
|
-
|
10
|
-
atom "FX"
|
11
|
-
end
|
12
|
-
|
13
|
-
Koch = TexPlay::LSystem.new do
|
14
|
-
rule "F" => "F-F++F-F"
|
15
|
-
|
16
|
-
angle 60
|
17
|
-
|
18
|
-
atom "F"
|
19
|
-
end
|
20
|
-
|
21
|
-
Bush1 = TexPlay::LSystem.new do
|
22
|
-
rule "F" => "F[-F]F[+F][F]"
|
23
|
-
|
24
|
-
angle 20
|
25
|
-
atom "F"
|
26
|
-
end
|
27
|
-
|
28
|
-
Bush2 = TexPlay::LSystem.new do
|
29
|
-
rule "F" => "FF"
|
30
|
-
rule "X" => "F[+X]F[-X]+X"
|
31
|
-
|
32
|
-
angle 20
|
33
|
-
atom "X"
|
34
|
-
end
|
35
|
-
|
36
|
-
Bush3 = TexPlay::LSystem.new do
|
37
|
-
rule "F" => "FF"
|
38
|
-
rule "X" => "F-[[X]+X]+F[+FX]-X"
|
39
|
-
|
40
|
-
angle 22.5
|
41
|
-
atom "X"
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
class W < Gosu::Window
|
47
|
-
def initialize
|
48
|
-
super(1024, 768, false, 20)
|
49
|
-
@img = TexPlay::create_blank_image(self, 500, 500)
|
50
|
-
@img.set_options :color => :rand
|
51
|
-
@img.lsystem(400, 150, Koch, :order => 8, :line_length => 6)
|
52
|
-
#@img.save("dragon.jpg")
|
53
|
-
end
|
54
|
-
|
55
|
-
def draw
|
56
|
-
@img.draw(100,0,1)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
w = W.new
|
61
|
-
w.show
|
1
|
+
require 'common'
|
2
|
+
require 'gosu'
|
3
|
+
|
4
|
+
Dragon = TexPlay::LSystem.new do
|
5
|
+
rule "F" => "F"
|
6
|
+
rule "X" => "X+YF+"
|
7
|
+
rule "Y" => "-FX-Y"
|
8
|
+
angle 90
|
9
|
+
|
10
|
+
atom "FX"
|
11
|
+
end
|
12
|
+
|
13
|
+
Koch = TexPlay::LSystem.new do
|
14
|
+
rule "F" => "F-F++F-F"
|
15
|
+
|
16
|
+
angle 60
|
17
|
+
|
18
|
+
atom "F"
|
19
|
+
end
|
20
|
+
|
21
|
+
Bush1 = TexPlay::LSystem.new do
|
22
|
+
rule "F" => "F[-F]F[+F][F]"
|
23
|
+
|
24
|
+
angle 20
|
25
|
+
atom "F"
|
26
|
+
end
|
27
|
+
|
28
|
+
Bush2 = TexPlay::LSystem.new do
|
29
|
+
rule "F" => "FF"
|
30
|
+
rule "X" => "F[+X]F[-X]+X"
|
31
|
+
|
32
|
+
angle 20
|
33
|
+
atom "X"
|
34
|
+
end
|
35
|
+
|
36
|
+
Bush3 = TexPlay::LSystem.new do
|
37
|
+
rule "F" => "FF"
|
38
|
+
rule "X" => "F-[[X]+X]+F[+FX]-X"
|
39
|
+
|
40
|
+
angle 22.5
|
41
|
+
atom "X"
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
class W < Gosu::Window
|
47
|
+
def initialize
|
48
|
+
super(1024, 768, false, 20)
|
49
|
+
@img = TexPlay::create_blank_image(self, 500, 500)
|
50
|
+
@img.set_options :color => :rand
|
51
|
+
@img.lsystem(400, 150, Koch, :order => 8, :line_length => 6)
|
52
|
+
#@img.save("dragon.jpg")
|
53
|
+
end
|
54
|
+
|
55
|
+
def draw
|
56
|
+
@img.draw(100,0,1)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
w = W.new
|
61
|
+
w.show
|
data/examples/example_melt.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'common'
|
3
|
-
require 'gosu'
|
4
|
-
require 'texplay'
|
5
|
-
|
6
|
-
|
7
|
-
class W < Gosu::Window
|
8
|
-
def initialize
|
9
|
-
super(1024, 768, false, 20)
|
10
|
-
@img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
|
11
|
-
end
|
12
|
-
|
13
|
-
def draw
|
14
|
-
x = (@img.width - 100/2) * rand
|
15
|
-
y = (@img.height - 100/2) * rand
|
16
|
-
|
17
|
-
@img.splice @img, x, y + 1, :crop => [x, y, x + 100, y + 100]
|
18
|
-
|
19
|
-
@img.draw 100, 50,1
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
w = W.new
|
26
|
-
w.show
|
27
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'gosu'
|
4
|
+
require 'texplay'
|
5
|
+
|
6
|
+
|
7
|
+
class W < Gosu::Window
|
8
|
+
def initialize
|
9
|
+
super(1024, 768, false, 20)
|
10
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
|
11
|
+
end
|
12
|
+
|
13
|
+
def draw
|
14
|
+
x = (@img.width - 100/2) * rand
|
15
|
+
y = (@img.height - 100/2) * rand
|
16
|
+
|
17
|
+
@img.splice @img, x, y + 1, :crop => [x, y, x + 100, y + 100]
|
18
|
+
|
19
|
+
@img.draw 100, 50,1
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
w = W.new
|
26
|
+
w.show
|
27
|
+
|