texplay 0.2.7-x86-mswin32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +103 -0
- data/README.markdown +41 -0
- data/Rakefile +61 -0
- data/examples/common.rb +8 -0
- data/examples/example_alpha_blend.rb +31 -0
- data/examples/example_bezier.rb +42 -0
- data/examples/example_blur.rb +59 -0
- data/examples/example_color_control.rb +69 -0
- data/examples/example_color_transform.rb +29 -0
- data/examples/example_dup.rb +75 -0
- data/examples/example_each.rb +42 -0
- data/examples/example_effect.rb +35 -0
- data/examples/example_fill.rb +44 -0
- data/examples/example_fill_old.rb +49 -0
- data/examples/example_fluent.rb +31 -0
- data/examples/example_gen_eval.rb +34 -0
- data/examples/example_hash_arguments.rb +47 -0
- data/examples/example_lsystem.rb +61 -0
- data/examples/example_melt.rb +27 -0
- data/examples/example_polyline.rb +43 -0
- data/examples/example_scale.rb +29 -0
- data/examples/example_simple.rb +38 -0
- data/examples/example_splice.rb +33 -0
- data/examples/example_sync.rb +60 -0
- data/examples/example_turtle.rb +40 -0
- data/examples/media/empty2.png +0 -0
- data/examples/media/gosu.png +0 -0
- data/examples/media/logo.png +0 -0
- data/examples/media/maria.png +0 -0
- data/examples/media/rose.bmp +0 -0
- data/examples/media/sand1.png +0 -0
- data/examples/media/sunset.png +0 -0
- data/examples/media/texplay.png +0 -0
- data/ext/texplay/actions.c +1331 -0
- data/ext/texplay/actions.h +52 -0
- data/ext/texplay/bindings.c +1129 -0
- data/ext/texplay/bindings.h +46 -0
- data/ext/texplay/cache.c +135 -0
- data/ext/texplay/cache.h +24 -0
- data/ext/texplay/compat.h +27 -0
- data/ext/texplay/extconf.rb +30 -0
- data/ext/texplay/gen_eval.c +211 -0
- data/ext/texplay/gen_eval.h +20 -0
- data/ext/texplay/object2module.c +171 -0
- data/ext/texplay/object2module.h +11 -0
- data/ext/texplay/texplay.c +137 -0
- data/ext/texplay/texplay.h +107 -0
- data/ext/texplay/utils.c +978 -0
- data/ext/texplay/utils.h +145 -0
- data/lib/1.8/texplay.so +0 -0
- data/lib/1.9/texplay.so +0 -0
- data/lib/texplay-contrib.rb +171 -0
- data/lib/texplay.rb +134 -0
- metadata +114 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
class W < Gosu::Window
|
6
|
+
def initialize
|
7
|
+
super(1024, 768, false, 20)
|
8
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
9
|
+
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
10
|
+
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
11
|
+
|
12
|
+
# put a border on the image
|
13
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
14
|
+
|
15
|
+
points = []
|
16
|
+
|
17
|
+
# NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or 'y'
|
18
|
+
# NOTE: current maximum points for a bezier is 13
|
19
|
+
(0..@img.width).step(50) { |x|
|
20
|
+
p = TexPlay::TPPoint.new
|
21
|
+
p.x = x
|
22
|
+
p.y = @img.height * rand
|
23
|
+
|
24
|
+
points << p
|
25
|
+
}
|
26
|
+
|
27
|
+
@img.bezier points, :color => :white
|
28
|
+
|
29
|
+
|
30
|
+
# NOTE: the :texture hash argument works on ALL drawing actions; not just fills
|
31
|
+
@img.fill 300, 480, :texture => @tp
|
32
|
+
|
33
|
+
# let's demonstrate by drawing a circle using the gosu.png texture
|
34
|
+
# NOTE: :texture even works on lines, boxes, polylines, beziers etc.
|
35
|
+
@img.circle 400, 50, 40, :fill => true, :texture => @gosu
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw
|
40
|
+
|
41
|
+
@img.draw 100, 50,1
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
w = W.new
|
48
|
+
w.show
|
49
|
+
|
@@ -0,0 +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
|
+
|
@@ -0,0 +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
|
+
|
@@ -0,0 +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
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'devil/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, 350, Dragon, :order => 13, :line_length => 4)
|
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
|
@@ -0,0 +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
|
+
|
@@ -0,0 +1,43 @@
|
|
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
|
+
# put a border on the image
|
12
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
13
|
+
|
14
|
+
points = []
|
15
|
+
|
16
|
+
# NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or 'y'
|
17
|
+
10.times {
|
18
|
+
p = TexPlay::TPPoint.new
|
19
|
+
p.x = @img.width * rand
|
20
|
+
p.y = @img.height * rand
|
21
|
+
|
22
|
+
points << p
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
# what if we want to turn a polyline into a polygon?
|
27
|
+
@img.polyline points, :closed => true, :color => :blue
|
28
|
+
@img.polyline points, :color => :red
|
29
|
+
end
|
30
|
+
|
31
|
+
def draw
|
32
|
+
|
33
|
+
# NOTE: (when viewing) the blue line is the extra line added to close the polygon,
|
34
|
+
# red lines are original polyline
|
35
|
+
@img.draw 100, 50,1
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
w = W.new
|
42
|
+
w.show
|
43
|
+
|
@@ -0,0 +1,29 @@
|
|
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}/logo.png")
|
11
|
+
@img2 = TexPlay::create_blank_image(self, 500, 500)
|
12
|
+
|
13
|
+
@img2.splice_and_scale @img, 0, 50, :factor => 2
|
14
|
+
@img2.splice @img, 0, 200
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw
|
18
|
+
x = @img.width * rand
|
19
|
+
y = @img.height * rand
|
20
|
+
|
21
|
+
@img2.draw 100, 100,1
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
w = W.new
|
28
|
+
w.show
|
29
|
+
|
@@ -0,0 +1,38 @@
|
|
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}/empty2.png")
|
11
|
+
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
12
|
+
|
13
|
+
# put a border on the image
|
14
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
15
|
+
|
16
|
+
# perform some simple drawing actions
|
17
|
+
@img.line 0,0, @img.width - 1, @img.height - 1, :color => :yellow
|
18
|
+
@img.circle 400, 100, 40, :fill => true, :color => [rand, rand, rand, 1]
|
19
|
+
@img.rect 200, 300, 300, 400, :fill => true, :color => :red
|
20
|
+
|
21
|
+
@img.ngon 400,300,50, 5, :start_angle => 90
|
22
|
+
@img.ngon 300,300,50, 5, :start_angle => 45
|
23
|
+
|
24
|
+
# NOTE: chroma_key means NOT to splice in that color (pixels with that color are skipped)
|
25
|
+
# (chroma_key_not does the opposite, it skips pixels that do NOT have that color)
|
26
|
+
@img.splice @gosu, 210, 330, :chroma_key => :alpha
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw
|
30
|
+
@img.draw 100, 50,1
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
w = W.new
|
37
|
+
w.show
|
38
|
+
|
@@ -0,0 +1,33 @@
|
|
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}/texplay.png")
|
10
|
+
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
11
|
+
|
12
|
+
@img.splice @gosu, 140,20,
|
13
|
+
:color_control => proc { |c1, c2, x, y|
|
14
|
+
factor = 1 - (y - 25) / @gosu.height.to_f
|
15
|
+
c2[0] *= factor
|
16
|
+
c2[1] *= factor
|
17
|
+
c2[2] *= factor
|
18
|
+
c2
|
19
|
+
}
|
20
|
+
|
21
|
+
@img.splice @gosu, 50,20, :chroma_key => :alpha
|
22
|
+
end
|
23
|
+
|
24
|
+
def draw
|
25
|
+
@img.draw 100, 50,1
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
w = W.new
|
32
|
+
w.show
|
33
|
+
|
@@ -0,0 +1,60 @@
|
|
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
|
+
# sets the 'global' color for all actions in this image
|
12
|
+
@img.color :red
|
13
|
+
|
14
|
+
# let's draw the circle without syncing it to gl
|
15
|
+
@img.circle 100, 100, 50, :fill => true, :sync_mode => :no_sync
|
16
|
+
|
17
|
+
# now let's sync half of it to gl
|
18
|
+
@img.force_sync [100, 50, 150, 150]
|
19
|
+
|
20
|
+
# let's draw some lazy shapes
|
21
|
+
@img.set_options :sync_mode => :lazy_sync
|
22
|
+
|
23
|
+
@img.ngon 200, 300, 40, 5, :color => :red
|
24
|
+
@img.ngon 280, 300, 40, 6, :color => :green
|
25
|
+
@img.ngon 360, 300, 40, 7, :color => :blue
|
26
|
+
|
27
|
+
# now let's sync the lazy shapes to gl
|
28
|
+
@img.paint
|
29
|
+
|
30
|
+
# NOTE: the lazy drawing (above) is identical to using the following paint block
|
31
|
+
# @img.paint {
|
32
|
+
# ngon 200, 300, 50, 5
|
33
|
+
# ...etc
|
34
|
+
# }
|
35
|
+
|
36
|
+
# end lazy drawing mode
|
37
|
+
@img.delete_options
|
38
|
+
|
39
|
+
# the default sync mode is eager_sync
|
40
|
+
# in this mode actions are drawn and sync'd immediately
|
41
|
+
# NOTE: TexPlay only syncs the part of the image that changed to gl
|
42
|
+
@img.ngon 440, 300, 40, 8, :color => :tyrian
|
43
|
+
|
44
|
+
# paint blocks can also accept a sync_mode parameter
|
45
|
+
# NOTE: the line below will not be visible until you
|
46
|
+
# explictly sync it to gl; probably using @img.force_sync
|
47
|
+
@img.paint(:sync_mode => :no_sync) {
|
48
|
+
line 0, 0, @img.width, @img.height
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def draw
|
53
|
+
|
54
|
+
@img.draw 100, 50,1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
w = W.new
|
59
|
+
w.show
|
60
|
+
|
@@ -0,0 +1,40 @@
|
|
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
|
+
# put a border on the image
|
12
|
+
@img.rect 0, 0, @img.width - 1, @img.height - 1
|
13
|
+
|
14
|
+
@length = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# NOTE: turtle is currently written in Ruby so is very slow, look at texplay-contrib.rb for source code.
|
19
|
+
def draw
|
20
|
+
|
21
|
+
# NOTE: putting actions in paint block means they are only sync'd to gl at end of block.
|
22
|
+
# compare to calling an action directly (on an @img) where it is sync'd to gl immediately
|
23
|
+
|
24
|
+
@img.paint {
|
25
|
+
|
26
|
+
# a 2nd arg of 'true' means to show the turtle
|
27
|
+
forward(@length, true, :color => :red)
|
28
|
+
turn(89.5)
|
29
|
+
@length += 2
|
30
|
+
}
|
31
|
+
|
32
|
+
@img.draw 100, 50,1
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
w = W.new
|
39
|
+
w.show
|
40
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|