texplay 0.2.2 → 0.2.3
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 +5 -0
- data/README.markdown +1 -1
- data/Rakefile +4 -2
- data/examples/example_fill.rb +2 -2
- data/examples/example_lsystem.rb +51 -0
- data/lib/texplay-contrib.rb +76 -0
- data/lib/texplay.rb +1 -1
- data/src/Makefile +1 -1
- data/src/compat.h +4 -0
- data/src/extconf.rb +3 -0
- data/src/utils.c +18 -2
- data/src/utils.h +2 -0
- metadata +2 -2
- data/README1st +0 -9
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
11/9/09
|
2
|
+
version 0.2.3
|
3
|
+
* added Ruby 1.8.7 compatibility by modifying extconf.rb to define RUBY_19 macro
|
4
|
+
* and modified compat.h to get rid of feature test (fails on 1.8.7)
|
5
|
+
|
1
6
|
8/9/09
|
2
7
|
version 0.2.2
|
3
8
|
* fixed color_control bug, action_struct->color was being overwritten (now using a temp).
|
data/README.markdown
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rake/clean'
|
2
2
|
require 'rake/gempackagetask'
|
3
3
|
|
4
|
+
TEXPLAY_VERSION = "0.2.3"
|
5
|
+
|
4
6
|
$dlext = Config::CONFIG['DLEXT']
|
5
7
|
|
6
8
|
CLEAN.include("src/*.#{$dlext}", "src/*.log", "src/*.o", "src/*~", "src/*#*", "src/*.obj", "src/*.def", "src/*.pdb")
|
@@ -38,7 +40,7 @@ end
|
|
38
40
|
specification = Gem::Specification.new do |s|
|
39
41
|
s.name = "texplay"
|
40
42
|
s.summary = "TexPlay is a light-weight image manipulation framework for Ruby and Gosu"
|
41
|
-
s.version =
|
43
|
+
s.version = TEXPLAY_VERSION
|
42
44
|
s.date = "2009-09-09"
|
43
45
|
s.author = "John Mair (banisterfiend)"
|
44
46
|
s.email = 'jrmair@gmail.com'
|
@@ -47,7 +49,7 @@ specification = Gem::Specification.new do |s|
|
|
47
49
|
s.add_dependency("gosu",">=0.7.14")
|
48
50
|
s.homepage = "http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/"
|
49
51
|
s.has_rdoc = false
|
50
|
-
s.files = ["Rakefile", "README.markdown", "CHANGELOG",
|
52
|
+
s.files = ["Rakefile", "README.markdown", "CHANGELOG",
|
51
53
|
"lib/texplay.rb", "lib/texplay-contrib.rb"] +
|
52
54
|
FileList["src/*", "examples/*.rb", "examples/media/*"].to_a
|
53
55
|
|
data/examples/example_fill.rb
CHANGED
@@ -6,7 +6,7 @@ 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, 1022,
|
9
|
+
@img = TexPlay::create_blank_image(self, 1022, 800)
|
10
10
|
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
11
11
|
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/sand1.png")
|
12
12
|
|
@@ -25,7 +25,7 @@ class W < Gosu::Window
|
|
25
25
|
@img.bezier points
|
26
26
|
|
27
27
|
# NOTE: the :texture hash argument works on ALL drawing actions; not just fills
|
28
|
-
@img.fill 300,
|
28
|
+
@img.fill 300, 650, :texture => @gosu
|
29
29
|
|
30
30
|
# let's demonstrate by drawing a circle using the gosu.png texture
|
31
31
|
# NOTE: :texture even works on lines, boxes, polylines, beziers etc.
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'texplay'
|
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
|
+
Bush1 = TexPlay::LSystem.new do
|
14
|
+
rule "F" => "F[-F]F[+F][F]"
|
15
|
+
|
16
|
+
angle 20
|
17
|
+
atom "F"
|
18
|
+
end
|
19
|
+
|
20
|
+
Bush2 = TexPlay::LSystem.new do
|
21
|
+
rule "F" => "FF"
|
22
|
+
rule "X" => "F[+X]F[-X]+X"
|
23
|
+
|
24
|
+
angle 20
|
25
|
+
atom "X"
|
26
|
+
end
|
27
|
+
|
28
|
+
Bush3 = TexPlay::LSystem.new do
|
29
|
+
rule "F" => "FF"
|
30
|
+
rule "X" => "F-[[X]+X]+F[+FX]-X"
|
31
|
+
|
32
|
+
angle 22.5
|
33
|
+
atom "X"
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
class W < Gosu::Window
|
39
|
+
def initialize
|
40
|
+
super(1024, 768, false, 20)
|
41
|
+
@img = TexPlay::create_blank_image(self, 800, 500)
|
42
|
+
@img.lsystem(250, 250, Dragon, :order => 13, :line_length => 2)
|
43
|
+
end
|
44
|
+
|
45
|
+
def draw
|
46
|
+
@img.draw(100,0,1)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
w = W.new
|
51
|
+
w.show
|
data/lib/texplay-contrib.rb
CHANGED
@@ -5,12 +5,22 @@ end
|
|
5
5
|
|
6
6
|
require 'texplay'
|
7
7
|
|
8
|
+
# monkey-patches to core classes
|
9
|
+
class String
|
10
|
+
if !method_defined? :each_char
|
11
|
+
alias_method :_each_char, :each_byte
|
12
|
+
else
|
13
|
+
alias_method :_each_char, :each_char
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
8
17
|
# setup will be executed straight after Gosu::Image instantiation
|
9
18
|
TexPlay::on_setup do
|
10
19
|
@turtle_pos = TexPlay::TPPoint.new(width / 2, height / 2 )
|
11
20
|
@turtle_angle = 0
|
12
21
|
end
|
13
22
|
|
23
|
+
|
14
24
|
TexPlay::create_macro(:move_to) do |x, y|
|
15
25
|
capture {
|
16
26
|
@turtle_pos.x = x
|
@@ -73,5 +83,71 @@ TexPlay::create_macro(:forward) do |dist, *other|
|
|
73
83
|
}
|
74
84
|
end
|
75
85
|
|
86
|
+
## L-System code
|
87
|
+
|
88
|
+
# monkeypatches to TexPlay class
|
89
|
+
module TexPlay
|
90
|
+
class LSystem
|
91
|
+
def initialize(&block)
|
92
|
+
@rules = {}
|
93
|
+
|
94
|
+
instance_eval(&block) if block
|
95
|
+
end
|
96
|
+
|
97
|
+
def rule(new_rule)
|
98
|
+
@rules.merge!(new_rule)
|
99
|
+
end
|
100
|
+
|
101
|
+
def atom(new_atom)
|
102
|
+
@atom = new_atom
|
103
|
+
end
|
104
|
+
|
105
|
+
def angle(new_angle=nil)
|
106
|
+
return @angle if !new_angle
|
107
|
+
@angle = new_angle
|
108
|
+
end
|
76
109
|
|
110
|
+
def produce_string(order)
|
111
|
+
order = order[:order]
|
112
|
+
string = @atom.dup
|
113
|
+
|
114
|
+
order.times do
|
115
|
+
i = 0
|
116
|
+
while(i < string.length)
|
117
|
+
sub = @rules[string[i, 1]]
|
118
|
+
|
119
|
+
string[i] = sub if sub
|
120
|
+
|
121
|
+
i += sub ? sub.length : 1
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
string
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
77
129
|
|
130
|
+
# L-System macro
|
131
|
+
TexPlay::create_macro(:lsystem) do |x, y, system, options|
|
132
|
+
capture {
|
133
|
+
theta = system.angle
|
134
|
+
turtle_stack = []
|
135
|
+
move_to(x, y)
|
136
|
+
line_length = options[:line_length] || 1
|
137
|
+
|
138
|
+
system.produce_string(options)._each_char do |v|
|
139
|
+
case v
|
140
|
+
when "F"
|
141
|
+
forward(line_length, true)
|
142
|
+
when "+"
|
143
|
+
turn(theta)
|
144
|
+
when "-"
|
145
|
+
turn(-theta)
|
146
|
+
when "["
|
147
|
+
turtle_stack.push([@turtle_pos.dup, @turtle_angle])
|
148
|
+
when "]"
|
149
|
+
@turtle_pos, @turtle_angle = turtle_stack.pop
|
150
|
+
end
|
151
|
+
end
|
152
|
+
}
|
153
|
+
end
|
data/lib/texplay.rb
CHANGED
data/src/Makefile
CHANGED
@@ -58,7 +58,7 @@ warnflags = -Wall -Wno-parentheses
|
|
58
58
|
CFLAGS = -fPIC $(cflags)
|
59
59
|
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
60
60
|
DEFS = -D_FILE_OFFSET_BITS=64
|
61
|
-
CPPFLAGS = $(DEFS) $(cppflags)
|
61
|
+
CPPFLAGS = $(DEFS) $(cppflags) -DRUBY_19
|
62
62
|
CXXFLAGS = $(CFLAGS) $(cxxflags)
|
63
63
|
ldflags = -L. -rdynamic -Wl,-export-dynamic
|
64
64
|
dldflags =
|
data/src/compat.h
CHANGED
@@ -6,9 +6,13 @@
|
|
6
6
|
#include <ruby.h>
|
7
7
|
|
8
8
|
/* this is the test we use to identify ruby 1.9.1 */
|
9
|
+
|
10
|
+
/* commenting out this test because it doesn't seem to work in 1.8.7 */
|
11
|
+
/*
|
9
12
|
#ifdef RCLASS_M_TBL
|
10
13
|
# define RUBY_19
|
11
14
|
#endif
|
15
|
+
*/
|
12
16
|
|
13
17
|
/* macros for backwards compatibility with 1.8 */
|
14
18
|
#ifndef RUBY_19
|
data/src/extconf.rb
CHANGED
data/src/utils.c
CHANGED
@@ -946,10 +946,26 @@ fact(int n)
|
|
946
946
|
}
|
947
947
|
|
948
948
|
unsigned
|
949
|
-
comb(int n, int
|
949
|
+
comb(int n, int r)
|
950
950
|
{
|
951
|
-
double temp = fact(n) / (fact(
|
951
|
+
double temp = fact(n) / (fact(r) * fact(n - r));
|
952
952
|
return temp;
|
953
|
+
/* if(r > (n / 2))
|
954
|
+
r = n - r;
|
955
|
+
|
956
|
+
return perm(n, r) / fact(r);
|
957
|
+
*/
|
958
|
+
}
|
959
|
+
|
960
|
+
unsigned
|
961
|
+
perm(int n, int r)
|
962
|
+
{
|
963
|
+
int val = n;
|
964
|
+
int i;
|
965
|
+
for(i = n - 1; i > (n - r); i--)
|
966
|
+
val *= i;
|
967
|
+
|
968
|
+
return val;
|
953
969
|
}
|
954
970
|
|
955
971
|
double
|
data/src/utils.h
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texplay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mair (banisterfiend)
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- Rakefile
|
35
35
|
- README.markdown
|
36
36
|
- CHANGELOG
|
37
|
-
- README1st
|
38
37
|
- lib/texplay.rb
|
39
38
|
- lib/texplay-contrib.rb
|
40
39
|
- src/texplay.c
|
@@ -74,6 +73,7 @@ files:
|
|
74
73
|
- examples/example_splice.rb
|
75
74
|
- examples/example_alpha_blend.rb
|
76
75
|
- examples/example_melt.rb
|
76
|
+
- examples/example_lsystem.rb
|
77
77
|
- examples/media/sand1.png
|
78
78
|
- examples/media/rose.bmp
|
79
79
|
- examples/media/maria.png
|
data/README1st
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
INSTRUCTIONS
|
2
|
-
|
3
|
-
TexPlay version 0.2.2
|
4
|
-
|
5
|
-
*Ensure that ctexplay.so and gosu.so, and texplay.rb and texplay-contrib.rb are in the working directory for your project
|
6
|
-
*require 'texplay' in your ruby program to access the TexPlay module
|
7
|
-
*see example programs, for illustration of use
|
8
|
-
|
9
|
-
|