texplay 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README.markdown +35 -0
- data/README1st +1 -1
- data/Rakefile +6 -6
- data/examples/example_alpha_blend.rb +1 -1
- data/examples/example_bezier.rb +4 -13
- data/examples/example_color_control.rb +3 -2
- data/examples/example_color_transform.rb +3 -3
- data/examples/example_dup.rb +1 -1
- data/examples/example_each.rb +1 -1
- data/examples/example_effect.rb +1 -1
- data/examples/example_fill.rb +4 -9
- data/examples/example_fill_old.rb +1 -1
- data/examples/example_fluent.rb +1 -1
- data/examples/example_gen_eval.rb +1 -1
- data/examples/example_hash_arguments.rb +1 -1
- data/examples/example_melt.rb +1 -1
- data/examples/example_polyline.rb +1 -1
- data/examples/example_simple.rb +4 -1
- data/examples/example_splice.rb +9 -13
- data/examples/example_sync.rb +1 -1
- data/examples/example_turtle.rb +2 -2
- data/lib/texplay-contrib.rb +8 -8
- data/lib/texplay.rb +9 -9
- data/src/actions.c +80 -55
- data/src/bindings.c +2 -2
- data/src/texplay.c +1 -1
- data/src/utils.c +6 -5
- metadata +3 -9
- data/README +0 -21
- data/examples/basic.rb +0 -48
- data/examples/basic2.rb +0 -37
- data/examples/benchmark.rb +0 -299
- data/examples/specs.rb +0 -240
- data/examples/test.rb +0 -70
- data/examples/test2.rb +0 -72
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
8/9/09
|
2
|
+
version 0.2.2
|
3
|
+
* fixed color_control bug, action_struct->color was being overwritten (now using a temp).
|
4
|
+
* fixed faulty error msg where max tex size was being displayed as 1024 but is actually 1022
|
5
|
+
* added :start_angle parameter to ngon action
|
6
|
+
* fixed example screen height from 769 to 768
|
7
|
+
* arity of -1 and 0 now supported for color_control procs
|
8
|
+
* fixed parameter checks for circle and ngon
|
9
|
+
* updated documentation to reflect changes, and added details on caching
|
10
|
+
|
1
11
|
2/9/09
|
2
12
|
version 0.2.1
|
3
13
|
* releasing a gem for TexPlay
|
data/README.markdown
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
![Alt text](https://dl.getdropbox.com/u/239375/texplay.png)
|
2
|
+
|
3
|
+
*an image manipulation tool for ruby and gosu*
|
4
|
+
|
5
|
+
INSTRUCTIONS
|
6
|
+
============
|
7
|
+
|
8
|
+
**TexPlay version 0.2.2**
|
9
|
+
|
10
|
+
Gem installation:
|
11
|
+
|
12
|
+
+ sudo gem install texplay
|
13
|
+
|
14
|
+
To compile TexPlay from source, ensure you are in the directory with the Rakefile and type:
|
15
|
+
|
16
|
+
+ rake
|
17
|
+
|
18
|
+
OR
|
19
|
+
|
20
|
+
+ rake19 (assuming this is the name of your 1.9.1 version of rake)
|
21
|
+
|
22
|
+
**NB:** be sure to run the version of rake that corresponds to the ruby version you wish to use! on my system I use rake19 for ruby 1.9.1!
|
23
|
+
|
24
|
+
If all goes well, run the example programs:
|
25
|
+
|
26
|
+
+ cd examples
|
27
|
+
+ ruby example_melt.rb
|
28
|
+
+ ruby example_simple.rb
|
29
|
+
+ ..etc
|
30
|
+
|
31
|
+
+ like any gosu application, gosu.so must be in the current directory (or the gosu gem installed) when running the examples.
|
32
|
+
|
33
|
+
|
34
|
+
---
|
35
|
+
Enjoy!
|
data/README1st
CHANGED
data/Rakefile
CHANGED
@@ -26,9 +26,9 @@ task :build => :clean do
|
|
26
26
|
|
27
27
|
if RUBY_PLATFORM =~ /mswin/
|
28
28
|
if RUBY_VERSION =~ /1.9/
|
29
|
-
File.rename("../lib/ctexplay.#{dlext}", "../lib/
|
29
|
+
File.rename("../lib/ctexplay.#{$dlext}", "../lib/ctexplay.19.#{$dlext}")
|
30
30
|
else
|
31
|
-
File.rename("../lib/ctexplay.#{dlext}", "../lib/
|
31
|
+
File.rename("../lib/ctexplay.#{$dlext}", "../lib/ctexplay.18.#{$dlext}")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
puts "(5) ...done!"
|
@@ -38,8 +38,8 @@ end
|
|
38
38
|
specification = Gem::Specification.new do |s|
|
39
39
|
s.name = "texplay"
|
40
40
|
s.summary = "TexPlay is a light-weight image manipulation framework for Ruby and Gosu"
|
41
|
-
s.version = "0.2.
|
42
|
-
s.date = "2009-09-
|
41
|
+
s.version = "0.2.2"
|
42
|
+
s.date = "2009-09-09"
|
43
43
|
s.author = "John Mair (banisterfiend)"
|
44
44
|
s.email = 'jrmair@gmail.com'
|
45
45
|
s.description = s.summary
|
@@ -47,13 +47,13 @@ specification = Gem::Specification.new do |s|
|
|
47
47
|
s.add_dependency("gosu",">=0.7.14")
|
48
48
|
s.homepage = "http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/"
|
49
49
|
s.has_rdoc = false
|
50
|
-
s.files = ["Rakefile", "README", "CHANGELOG", "README1st",
|
50
|
+
s.files = ["Rakefile", "README.markdown", "CHANGELOG", "README1st",
|
51
51
|
"lib/texplay.rb", "lib/texplay-contrib.rb"] +
|
52
52
|
FileList["src/*", "examples/*.rb", "examples/media/*"].to_a
|
53
53
|
|
54
54
|
if RUBY_PLATFORM =~ /mswin/
|
55
55
|
s.platform = Gem::Platform::CURRENT
|
56
|
-
s.files += ["lib/
|
56
|
+
s.files += ["lib/ctexplay.18.so", "lib/ctexplay.19.so"]
|
57
57
|
|
58
58
|
else
|
59
59
|
s.platform = Gem::Platform::RUBY
|
data/examples/example_bezier.rb
CHANGED
@@ -5,8 +5,8 @@ require 'texplay'
|
|
5
5
|
|
6
6
|
class W < Gosu::Window
|
7
7
|
def initialize
|
8
|
-
super(1024,
|
9
|
-
@img =
|
8
|
+
super(1024, 768, false, 20)
|
9
|
+
@img = TexPlay::create_blank_image(self, 500, 500)
|
10
10
|
|
11
11
|
# put a border on the image
|
12
12
|
@img.rect 0,0, @img.width - 1, @img.height - 1
|
@@ -23,18 +23,9 @@ class W < Gosu::Window
|
|
23
23
|
points << p
|
24
24
|
}
|
25
25
|
|
26
|
-
|
26
|
+
# making the bezier
|
27
|
+
@img.bezier points, :color => :red
|
27
28
|
|
28
|
-
# making the bezier more interesting by using turtle graphics :) (a rough bezier)
|
29
|
-
@img.bezier points, :color => :red, :color_control => proc { |c, x, y|
|
30
|
-
if((x % 10) == 0) then
|
31
|
-
@img.line_to(x, y + rand * 20 - 10)
|
32
|
-
end
|
33
|
-
:none
|
34
|
-
}
|
35
|
-
|
36
|
-
#@img.fill 100, 400, :color => :yellow
|
37
|
-
|
38
29
|
# NOTE: can 'close' a bezier curve too (as with polylines)
|
39
30
|
end
|
40
31
|
|
@@ -4,7 +4,7 @@ require 'texplay'
|
|
4
4
|
|
5
5
|
class W < Gosu::Window
|
6
6
|
def initialize
|
7
|
-
super(1024,
|
7
|
+
super(1024, 768, false, 20)
|
8
8
|
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
9
9
|
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
10
10
|
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
@@ -18,6 +18,7 @@ class W < Gosu::Window
|
|
18
18
|
# a valid color symbol)
|
19
19
|
|
20
20
|
# color_control accepts procs of 4 types:
|
21
|
+
# arity of 0: nothing is yielded and color is set by return value of block
|
21
22
|
# arity of 1: just the destination pixel color is yielded
|
22
23
|
# arity of 2: both the destination and the source pixel colors are yielded (in that order)
|
23
24
|
# arity of 3: the destination pixel color is yielded along with the x and y coords of the current pixel
|
@@ -52,7 +53,7 @@ class W < Gosu::Window
|
|
52
53
|
}
|
53
54
|
|
54
55
|
# this just fills a rect with random colours
|
55
|
-
@img.rect 400, 400, 470, 470, :fill => true, :color_control => proc {
|
56
|
+
@img.rect 400, 400, 470, 470, :fill => true, :color_control => proc { :rand }
|
56
57
|
end
|
57
58
|
|
58
59
|
def draw
|
@@ -6,7 +6,7 @@ require 'texplay'
|
|
6
6
|
|
7
7
|
class W < Gosu::Window
|
8
8
|
def initialize
|
9
|
-
super(1024,
|
9
|
+
super(1024, 768, false, 20)
|
10
10
|
@img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
|
11
11
|
end
|
12
12
|
|
@@ -14,9 +14,9 @@ class W < Gosu::Window
|
|
14
14
|
x = (@img.width - 100/2) * rand
|
15
15
|
y = (@img.height - 100/2) * rand
|
16
16
|
|
17
|
-
@img.rect x, y, x + 50, y + 50, :fill => true,
|
17
|
+
@img.rect x, y, x + 50, y + 50, :fill => true,
|
18
|
+
:color_control => { :mult => [0.9 , 0.3, 0.3, 1] }
|
18
19
|
|
19
|
-
|
20
20
|
|
21
21
|
@img.draw 100, 50,1
|
22
22
|
end
|
data/examples/example_dup.rb
CHANGED
data/examples/example_each.rb
CHANGED
data/examples/example_effect.rb
CHANGED
data/examples/example_fill.rb
CHANGED
@@ -6,16 +6,15 @@ require 'texplay'
|
|
6
6
|
class W < Gosu::Window
|
7
7
|
def initialize
|
8
8
|
super(1024, 768, false, 20)
|
9
|
-
@img = TexPlay::create_blank_image(self,
|
10
|
-
|
11
|
-
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
|
9
|
+
@img = TexPlay::create_blank_image(self, 1022, 1022)
|
10
|
+
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
12
11
|
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/sand1.png")
|
13
12
|
|
14
13
|
points = []
|
15
14
|
|
16
15
|
# NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or y
|
17
16
|
# NOTE: current maximum points for a bezier is 13
|
18
|
-
(0..@img.width + 90).step(
|
17
|
+
(0..@img.width + 90).step(185) { |x|
|
19
18
|
p = TexPlay::TPPoint.new
|
20
19
|
p.x = x
|
21
20
|
p.y = @img.height * rand
|
@@ -25,19 +24,15 @@ class W < Gosu::Window
|
|
25
24
|
|
26
25
|
@img.bezier points
|
27
26
|
|
28
|
-
|
29
27
|
# NOTE: the :texture hash argument works on ALL drawing actions; not just fills
|
30
|
-
@img.fill 300,
|
31
|
-
# @img.circle 300, 400, 40
|
28
|
+
@img.fill 300, 600, :texture => @gosu
|
32
29
|
|
33
30
|
# let's demonstrate by drawing a circle using the gosu.png texture
|
34
31
|
# NOTE: :texture even works on lines, boxes, polylines, beziers etc.
|
35
32
|
@img.circle 400, 50, 40, :fill => true, :texture => @tp
|
36
|
-
|
37
33
|
end
|
38
34
|
|
39
35
|
def draw
|
40
|
-
|
41
36
|
@img.draw 10, 10,1
|
42
37
|
end
|
43
38
|
|
@@ -4,7 +4,7 @@ require 'texplay'
|
|
4
4
|
|
5
5
|
class W < Gosu::Window
|
6
6
|
def initialize
|
7
|
-
super(1024,
|
7
|
+
super(1024, 768, false, 20)
|
8
8
|
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
9
9
|
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
10
10
|
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
data/examples/example_fluent.rb
CHANGED
data/examples/example_melt.rb
CHANGED
data/examples/example_simple.rb
CHANGED
@@ -6,7 +6,7 @@ require 'texplay'
|
|
6
6
|
|
7
7
|
class W < Gosu::Window
|
8
8
|
def initialize
|
9
|
-
super(1024,
|
9
|
+
super(1024, 768, false, 20)
|
10
10
|
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
11
11
|
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
12
12
|
|
@@ -18,6 +18,9 @@ class W < Gosu::Window
|
|
18
18
|
@img.circle 400, 100, 40, :fill => true, :color => [rand, rand, rand, 1]
|
19
19
|
@img.rect 200, 300, 300, 400, :fill => true, :color => :red
|
20
20
|
|
21
|
+
@img.ngon 400,300,50, 5, :start_angle => 90
|
22
|
+
@img.ngon 300,300,50, 5, :start_angle => 45
|
23
|
+
|
21
24
|
# NOTE: chroma_key means NOT to splice in that color (pixels with that color are skipped)
|
22
25
|
# (chroma_key_not does the opposite, it skips pixels that do NOT have that color)
|
23
26
|
@img.splice @gosu, 210, 330, :chroma_key => :alpha
|
data/examples/example_splice.rb
CHANGED
@@ -5,27 +5,23 @@ require 'texplay'
|
|
5
5
|
|
6
6
|
class W < Gosu::Window
|
7
7
|
def initialize
|
8
|
-
super(1024,
|
8
|
+
super(1024, 768, false, 20)
|
9
9
|
@img = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
10
10
|
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
11
11
|
|
12
|
-
|
13
|
-
# @img.rect 20,20, 100, 100, :color => [1, 0, 0, 0.1], :alpha_blend => true, :fill => true
|
14
|
-
@img.splice @gosu, 20,20, :color_control => { :add => [0.5, 0.5, 0.5, 0.5]}
|
15
|
-
@img.splice @gosu, 100,20, :alpha_blend => true,
|
12
|
+
@img.splice @gosu, 140,20,
|
16
13
|
:color_control => proc { |c1, c2, x, y|
|
17
|
-
|
18
|
-
|
14
|
+
factor = 1 - (y - 25) / @gosu.height.to_f
|
15
|
+
c2[0] *= factor
|
16
|
+
c2[1] *= factor
|
17
|
+
c2[2] *= factor
|
18
|
+
c2
|
19
19
|
}
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
|
21
|
+
@img.splice @gosu, 50,20, :chroma_key => :alpha
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
|
-
# NOTE: turtle is currently written in Ruby so is very slow, look at texplay-contrib.rb for source code.
|
27
24
|
def draw
|
28
|
-
|
29
25
|
@img.draw 100, 50,1
|
30
26
|
end
|
31
27
|
|
data/examples/example_sync.rb
CHANGED
data/examples/example_turtle.rb
CHANGED
@@ -5,11 +5,11 @@ require 'texplay'
|
|
5
5
|
|
6
6
|
class W < Gosu::Window
|
7
7
|
def initialize
|
8
|
-
super(1024,
|
8
|
+
super(1024, 768, false, 20)
|
9
9
|
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
10
|
|
11
11
|
# put a border on the image
|
12
|
-
@img.rect 0,0, @img.width - 1, @img.height - 1
|
12
|
+
@img.rect 0, 0, @img.width - 1, @img.height - 1
|
13
13
|
|
14
14
|
@length = 0
|
15
15
|
end
|
data/lib/texplay-contrib.rb
CHANGED
@@ -6,26 +6,26 @@ end
|
|
6
6
|
require 'texplay'
|
7
7
|
|
8
8
|
# setup will be executed straight after Gosu::Image instantiation
|
9
|
-
TexPlay
|
9
|
+
TexPlay::on_setup do
|
10
10
|
@turtle_pos = TexPlay::TPPoint.new(width / 2, height / 2 )
|
11
11
|
@turtle_angle = 0
|
12
12
|
end
|
13
13
|
|
14
|
-
TexPlay
|
14
|
+
TexPlay::create_macro(:move_to) do |x, y|
|
15
15
|
capture {
|
16
16
|
@turtle_pos.x = x
|
17
17
|
@turtle_pos.y = y
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
|
-
TexPlay
|
21
|
+
TexPlay::create_macro(:move_rel) do |dx, dy|
|
22
22
|
capture {
|
23
23
|
@turtle_pos.x += dx
|
24
24
|
@turtle_pos.y += dy
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
|
-
TexPlay
|
28
|
+
TexPlay::create_macro(:line_to) do |x, y, *other|
|
29
29
|
capture {
|
30
30
|
line(@turtle_pos.x, @turtle_pos.y, x, y, *other)
|
31
31
|
|
@@ -33,7 +33,7 @@ TexPlay.create_macro(:line_to) do |x, y, *other|
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
|
-
TexPlay
|
36
|
+
TexPlay::create_macro(:line_rel) do |dx, dy, *other|
|
37
37
|
capture {
|
38
38
|
x = @turtle_pos.x + dx
|
39
39
|
y = @turtle_pos.y + dy
|
@@ -44,19 +44,19 @@ TexPlay.create_macro(:line_rel) do |dx, dy, *other|
|
|
44
44
|
}
|
45
45
|
end
|
46
46
|
|
47
|
-
TexPlay
|
47
|
+
TexPlay::create_macro(:turn_to) do |a|
|
48
48
|
capture {
|
49
49
|
@turtle_angle = a
|
50
50
|
}
|
51
51
|
end
|
52
52
|
|
53
|
-
TexPlay
|
53
|
+
TexPlay::create_macro(:turn) do |da|
|
54
54
|
capture {
|
55
55
|
@turtle_angle += da
|
56
56
|
}
|
57
57
|
end
|
58
58
|
|
59
|
-
TexPlay
|
59
|
+
TexPlay::create_macro(:forward) do |dist, *other|
|
60
60
|
capture {
|
61
61
|
visible = other.shift
|
62
62
|
|
data/lib/texplay.rb
CHANGED
@@ -10,16 +10,16 @@ require 'rbconfig'
|
|
10
10
|
require 'gosu'
|
11
11
|
|
12
12
|
module TexPlay
|
13
|
-
TEXPLAY_VERSION = "0.2.
|
13
|
+
TEXPLAY_VERSION = "0.2.2"
|
14
14
|
|
15
|
-
def self
|
15
|
+
def self::on_setup(&block)
|
16
16
|
raise "need a block" if !block
|
17
17
|
|
18
18
|
@__init_procs__ ||= []
|
19
19
|
@__init_procs__.push(block)
|
20
20
|
end
|
21
21
|
|
22
|
-
def self
|
22
|
+
def self::setup(receiver)
|
23
23
|
if @__init_procs__ then
|
24
24
|
@__init_procs__.each do |init_proc|
|
25
25
|
receiver.instance_eval(&init_proc)
|
@@ -27,7 +27,7 @@ module TexPlay
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def self
|
30
|
+
def self::create_blank_image(window, width, height)
|
31
31
|
Gosu::Image.new(window, EmptyImageStub.new(width, height))
|
32
32
|
end
|
33
33
|
|
@@ -37,7 +37,7 @@ module TexPlay
|
|
37
37
|
Blue = [0, 0, 1, 1]
|
38
38
|
Black = [0, 0, 0, 1]
|
39
39
|
White = [1, 1, 1, 1]
|
40
|
-
Grey = [0.5, 0.5, 0.5,
|
40
|
+
Grey = [0.5, 0.5, 0.5, 1]
|
41
41
|
Alpha = [0, 0, 0, 0]
|
42
42
|
Purple = [1, 0, 1, 1]
|
43
43
|
Yellow = [1, 1, 0, 1]
|
@@ -52,8 +52,8 @@ end
|
|
52
52
|
|
53
53
|
# credit to philomory for this class
|
54
54
|
class EmptyImageStub
|
55
|
-
def initialize(w,h)
|
56
|
-
@w, @h = w, h
|
55
|
+
def initialize(w, h)
|
56
|
+
@w, @h = w, h
|
57
57
|
end
|
58
58
|
|
59
59
|
def to_blob
|
@@ -74,9 +74,9 @@ direc = File.dirname(__FILE__)
|
|
74
74
|
dlext = Config::CONFIG['DLEXT']
|
75
75
|
begin
|
76
76
|
if RUBY_VERSION && RUBY_VERSION =~ /1.9/
|
77
|
-
require "#{direc}/
|
77
|
+
require "#{direc}/ctexplay.19.#{dlext}"
|
78
78
|
else
|
79
|
-
require "#{direc}/
|
79
|
+
require "#{direc}/ctexplay.18.#{dlext}"
|
80
80
|
end
|
81
81
|
rescue LoadError => e
|
82
82
|
require "#{direc}/ctexplay.#{dlext}"
|