banister-texplay 0.2.0
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 +63 -0
- data/README +21 -0
- data/README1st +9 -0
- data/Rakefile +84 -0
- data/lib/texplay-contrib.rb +77 -0
- data/lib/texplay.rb +134 -0
- data/src/extconf.rb +18 -0
- metadata +58 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
31/8/09
|
2
|
+
version 0.2.0
|
3
|
+
* added each iterator
|
4
|
+
* added alternative to proc for :color_control proc (allowing static linear transforms to pixels)
|
5
|
+
* no longer segfaulting on windows (no idea why not)
|
6
|
+
* rewrote EmptyImageStub in ruby, using philomory's code. now alot faster.
|
7
|
+
* implemented 'shadow' in terms of static :color_control pixel transform
|
8
|
+
* added more example code demonstrating each iterator (example_each.rb) and new color_control behaviour
|
9
|
+
i.e example_color_transform.rb
|
10
|
+
* should be relatively stable now!
|
11
|
+
|
12
|
+
28/8/09
|
13
|
+
version 0.1.9.1 (still BETA)
|
14
|
+
* experimental features: Gosu::Image#dup and Gosu::Image#clone
|
15
|
+
* also TexPlay::create_blank_image(window, width, height)
|
16
|
+
* I noticed these features SEG FAULT on my setup in windows, so be warned
|
17
|
+
* This is a BETA release
|
18
|
+
|
19
|
+
14/8/09
|
20
|
+
version 0.1.9.0 (BETA)
|
21
|
+
* major rewrite. TP now supports beziers, polylines, polygons, and more
|
22
|
+
* also supports alpha_blending (though still tempermental)
|
23
|
+
* This is a BETA release
|
24
|
+
|
25
|
+
1/7/09
|
26
|
+
version 0.1.6.2
|
27
|
+
* fixed another subtle bug in constrain_local_boundaries(). Function was
|
28
|
+
unable to deal with drawing actions that were 100% outside the image
|
29
|
+
boundaries.
|
30
|
+
|
31
|
+
28/6/09
|
32
|
+
version 0.1.6
|
33
|
+
* gen_eval now working as a replacement for instance_eval in the #paint block. Allows for more user-friendly interface.
|
34
|
+
* #paint can now be called without a block; if invoked this way it executes any commands in the action queue, e.g
|
35
|
+
@img.circle 20, 20, 40
|
36
|
+
@img.pixel 30, 30
|
37
|
+
@img.paint
|
38
|
+
* above will function as if: @img.paint { circle 20, 20, 40; pixel 30, 30 }
|
39
|
+
* collected 1.8.6/1.9.1 compatibility into compat.h
|
40
|
+
|
41
|
+
16/6/09
|
42
|
+
version 0.1.4.6
|
43
|
+
* allowed arity of 0 (as well as -1) for ruby 1.9 compatibility
|
44
|
+
|
45
|
+
13/6/09
|
46
|
+
version 0.1.4.5
|
47
|
+
* major bugfix with TexPlay#splice method (segfaut). Also added new color format parameter: color [1, 1, 0, 1] (e.g purple with full alpha).
|
48
|
+
Also fixed subtle edge-case bug in constrain_local_boundaries().
|
49
|
+
|
50
|
+
9/6/09
|
51
|
+
version 0.1.4
|
52
|
+
* improved error checking. should work better with later gosu releases
|
53
|
+
|
54
|
+
20/2/09
|
55
|
+
version 0.1.1
|
56
|
+
* rerelease of this version fixing the oversized image bug for refresh_cache (i.e images over 500 x 500
|
57
|
+
|
58
|
+
version 0.1.1
|
59
|
+
* oops, bug in leftshift/rightshift functions, fixed!
|
60
|
+
|
61
|
+
version 0.1.0
|
62
|
+
* release!
|
63
|
+
|
data/README
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
INSTRUCTIONS
|
2
|
+
|
3
|
+
TexPlay version 0.2.0
|
4
|
+
|
5
|
+
To compile TexPlay, ensure you are in the directory with the Rakefile and type:
|
6
|
+
=> rake
|
7
|
+
OR
|
8
|
+
=> rake19 (assuming this is the name of your 1.9.1 version of rake)
|
9
|
+
|
10
|
+
!!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!!
|
11
|
+
|
12
|
+
If all goes well, run the example programs:
|
13
|
+
=> cd examples
|
14
|
+
=> ruby example_melt.rb
|
15
|
+
=> ruby example_simple.rb
|
16
|
+
=> ..etc
|
17
|
+
|
18
|
+
*like any gosu application, gosu.so must be in the current directory (or the gosu gem installed) when running the examples.
|
19
|
+
|
20
|
+
Enjoy!
|
21
|
+
(note that TexPlay has only been tested on 32 bit linux systems and WindowsXP using VS 6.0)
|
data/README1st
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
INSTRUCTIONS
|
2
|
+
|
3
|
+
TexPlay version 0.2.0
|
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
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
$dlext = Config::CONFIG['DLEXT']
|
5
|
+
|
6
|
+
CLEAN.include("src/*.#{$dlext}", "src/*.log", "src/*.o", "src/*~", "src/*#*", "src/*.obj", "src/*.def", "src/*.pdb")
|
7
|
+
CLOBBER.include("**/*.#{$dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
|
8
|
+
|
9
|
+
$make_program = if RUBY_PLATFORM =~ /win/
|
10
|
+
"nmake"
|
11
|
+
else
|
12
|
+
"make"
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => [:build]
|
16
|
+
|
17
|
+
desc "Build TexPlay"
|
18
|
+
task :build => :clean do
|
19
|
+
puts "(2) building Makefile..."
|
20
|
+
chdir("./src/") do
|
21
|
+
ruby "extconf.rb"
|
22
|
+
puts "(3) building ctexplay.#{$dlext}..."
|
23
|
+
sh "#{$make_program}"
|
24
|
+
puts "(4) copying ctexplay.#{$dlext} to current directory..."
|
25
|
+
cp "ctexplay.#{$dlext}", "../lib" , :verbose => true
|
26
|
+
|
27
|
+
if RUBY_PLATFORM =~ /mswin/
|
28
|
+
if RUBY_VERSION =~ /1.9/
|
29
|
+
File.rename("../lib/ctexplay.#{dlext}", "../lib/ctexplay19.#{$dlext}")
|
30
|
+
else
|
31
|
+
File.rename("../lib/ctexplay.#{dlext}", "../lib/ctexplay18.#{$dlext}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
puts "(5) ...done!"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
specification = Gem::Specification.new do |s|
|
39
|
+
s.name = "texplay"
|
40
|
+
s.summary = "TexPlay is a light-weight image manipulation framework for Ruby and Gosu"
|
41
|
+
s.version = "0.2.0"
|
42
|
+
s.date = "2009-09-02"
|
43
|
+
s.author = "John Mair (banisterfiend)"
|
44
|
+
s.email = 'jrmair@gmail.com'
|
45
|
+
s.description = s.summary
|
46
|
+
s.require_path = 'lib'
|
47
|
+
s.homepage = "http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/"
|
48
|
+
s.has_rdoc = false
|
49
|
+
s.files = ["Rakefile", "README", "CHANGELOG", "README1st",
|
50
|
+
"lib/texplay.rb", "lib/texplay-contrib.rb"] +
|
51
|
+
FileList["src/*", "examples/*.rb", "examples/media/*"].to_a
|
52
|
+
|
53
|
+
if RUBY_PLATFORM =~ /mswin/
|
54
|
+
s.platform = Gem::Platform::WIN32
|
55
|
+
s.files += ["lib/ctexplay18.so", "lib/ctexplay19.so"]
|
56
|
+
|
57
|
+
else
|
58
|
+
s.platform = Gem::Platform::RUBY
|
59
|
+
s.extensions = ["src/extconf.rb"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
Rake::GemPackageTask.new(specification) do |package|
|
63
|
+
package.need_zip = false
|
64
|
+
package.need_tar = false
|
65
|
+
end
|
66
|
+
|
67
|
+
SELENE = '/home/john/ruby/projects/selene'
|
68
|
+
desc "update selene's version of texplay"
|
69
|
+
task :selene => ["#{SELENE}/lib/texplay.rb", "#{SELENE}/lib/texplay-contrib.rb",
|
70
|
+
"#{SELENE}/lib/ctexplay.so"] do
|
71
|
+
puts "...done!"
|
72
|
+
end
|
73
|
+
|
74
|
+
file "#{SELENE}/lib/texplay.rb" => "texplay.rb" do |t|
|
75
|
+
cp t.prerequisites.first, t.name, :verbose => true
|
76
|
+
end
|
77
|
+
|
78
|
+
file "#{SELENE}/lib/texplay-contrib.rb" => "texplay-contrib.rb" do |t|
|
79
|
+
cp t.prerequisites.first, t.name, :verbose => true
|
80
|
+
end
|
81
|
+
|
82
|
+
file "#{SELENE}/lib/ctexplay.#{$dlext}" => "ctexplay.#{$dlext}" do |t|
|
83
|
+
cp t.prerequisites.first, t.name, :verbose => true
|
84
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'texplay'
|
7
|
+
|
8
|
+
# setup will be executed straight after Gosu::Image instantiation
|
9
|
+
TexPlay.on_setup do
|
10
|
+
@turtle_pos = TexPlay::TPPoint.new(width / 2, height / 2 )
|
11
|
+
@turtle_angle = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
TexPlay.create_macro(:move_to) do |x, y|
|
15
|
+
capture {
|
16
|
+
@turtle_pos.x = x
|
17
|
+
@turtle_pos.y = y
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
TexPlay.create_macro(:move_rel) do |dx, dy|
|
22
|
+
capture {
|
23
|
+
@turtle_pos.x += dx
|
24
|
+
@turtle_pos.y += dy
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
TexPlay.create_macro(:line_to) do |x, y, *other|
|
29
|
+
capture {
|
30
|
+
line(@turtle_pos.x, @turtle_pos.y, x, y, *other)
|
31
|
+
|
32
|
+
@turtle_pos.x, @turtle_pos.y = x, y
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
TexPlay.create_macro(:line_rel) do |dx, dy, *other|
|
37
|
+
capture {
|
38
|
+
x = @turtle_pos.x + dx
|
39
|
+
y = @turtle_pos.y + dy
|
40
|
+
|
41
|
+
line(@turtle_pos.x, @turtle_pos.y, x, y, *other)
|
42
|
+
|
43
|
+
@turtle_pos.x, @turtle_pos.y = x, y
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
TexPlay.create_macro(:turn_to) do |a|
|
48
|
+
capture {
|
49
|
+
@turtle_angle = a
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
TexPlay.create_macro(:turn) do |da|
|
54
|
+
capture {
|
55
|
+
@turtle_angle += da
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
TexPlay.create_macro(:forward) do |dist, *other|
|
60
|
+
capture {
|
61
|
+
visible = other.shift
|
62
|
+
|
63
|
+
radians_per_degree = 0.0174532925199433
|
64
|
+
|
65
|
+
x = @turtle_pos.x + dist * Math::cos(radians_per_degree * @turtle_angle)
|
66
|
+
y = @turtle_pos.y + dist * Math::sin(radians_per_degree * @turtle_angle)
|
67
|
+
|
68
|
+
if(visible) then
|
69
|
+
line_to(x, y, *other)
|
70
|
+
else
|
71
|
+
move_to(x, y)
|
72
|
+
end
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
data/lib/texplay.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# (C) John Mair 2009, under the MIT licence
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
# include gosu first
|
9
|
+
require 'rbconfig'
|
10
|
+
require 'gosu'
|
11
|
+
|
12
|
+
module TexPlay
|
13
|
+
TEXPLAY_VERSION = "0.2.0"
|
14
|
+
|
15
|
+
def self.on_setup(&block)
|
16
|
+
raise "need a block" if !block
|
17
|
+
|
18
|
+
@__init_procs__ ||= []
|
19
|
+
@__init_procs__.push(block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.setup(receiver)
|
23
|
+
if @__init_procs__ then
|
24
|
+
@__init_procs__.each do |init_proc|
|
25
|
+
receiver.instance_eval(&init_proc)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.create_blank_image(window, width, height)
|
31
|
+
Gosu::Image.new(window, EmptyImageStub.new(width, height))
|
32
|
+
end
|
33
|
+
|
34
|
+
module Colors
|
35
|
+
Red = [1, 0, 0, 1]
|
36
|
+
Green = [0, 1, 0, 1]
|
37
|
+
Blue = [0, 0, 1, 1]
|
38
|
+
Black = [0, 0, 0, 1]
|
39
|
+
White = [1, 1, 1, 1]
|
40
|
+
Grey = [0.5, 0.5, 0.5, 0.5]
|
41
|
+
Alpha = [0, 0, 0, 0]
|
42
|
+
Purple = [1, 0, 1, 1]
|
43
|
+
Yellow = [1, 1, 0, 1]
|
44
|
+
Cyan = [0, 1, 1, 1]
|
45
|
+
Orange = [1, 0.5, 0, 1]
|
46
|
+
Brown = [0.39, 0.26, 0.13, 1]
|
47
|
+
Turquoise = [1, 0.6, 0.8, 1]
|
48
|
+
Tyrian = [0.4, 0.007, 0.235, 1]
|
49
|
+
end
|
50
|
+
include Colors
|
51
|
+
end
|
52
|
+
|
53
|
+
# credit to philomory for this class
|
54
|
+
class EmptyImageStub
|
55
|
+
def initialize(w,h)
|
56
|
+
@w, @h = w, h;
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_blob
|
60
|
+
"\0" * @w * @h * 4
|
61
|
+
end
|
62
|
+
|
63
|
+
def rows
|
64
|
+
@h
|
65
|
+
end
|
66
|
+
|
67
|
+
def columns
|
68
|
+
@w
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# bring in user-defined extensions to TexPlay
|
73
|
+
direc = File.dirname(__FILE__)
|
74
|
+
dlext = Config::CONFIG['DLEXT']
|
75
|
+
begin
|
76
|
+
if RUBY_VERSION && RUBY_VERSION =~ /1.9/
|
77
|
+
require "#{direc}/ctexplay19.#{dlext}"
|
78
|
+
else
|
79
|
+
require "#{direc}/ctexplay18.#{dlext}"
|
80
|
+
end
|
81
|
+
rescue LoadError => e
|
82
|
+
require "#{direc}/ctexplay.#{dlext}"
|
83
|
+
end
|
84
|
+
|
85
|
+
require "#{direc}/texplay-contrib"
|
86
|
+
|
87
|
+
# monkey patching the Gosu::Image class to add image manipulation functionality
|
88
|
+
module Gosu
|
89
|
+
class Image
|
90
|
+
|
91
|
+
# bring in the TexPlay image manipulation methods
|
92
|
+
include TexPlay
|
93
|
+
|
94
|
+
class << self
|
95
|
+
alias_method :original_new, :new
|
96
|
+
|
97
|
+
def new(*args, &block)
|
98
|
+
|
99
|
+
# invoke old behaviour
|
100
|
+
obj = original_new(*args, &block)
|
101
|
+
|
102
|
+
# refresh the TexPlay image cache
|
103
|
+
if obj.width <= (TexPlay::TP_MAX_QUAD_SIZE - 2) &&
|
104
|
+
obj.height <= (TexPlay::TP_MAX_QUAD_SIZE - 2) && obj.quad_cached? then
|
105
|
+
|
106
|
+
obj.refresh_cache
|
107
|
+
end
|
108
|
+
|
109
|
+
# run custom setup
|
110
|
+
TexPlay::setup(obj)
|
111
|
+
|
112
|
+
obj.instance_variable_set(:@__window__, args.first)
|
113
|
+
|
114
|
+
# return the new image
|
115
|
+
obj
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def __window__
|
120
|
+
@__window__
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# a bug in ruby 1.8.6 rb_eval_string() means i must define this here (rather than in texplay.c)
|
126
|
+
class Proc
|
127
|
+
def __context__
|
128
|
+
eval('self', self.binding)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
data/src/extconf.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
|
4
|
+
# linux
|
5
|
+
if RUBY_PLATFORM =~ /linux/ then
|
6
|
+
exit unless have_library("glut")
|
7
|
+
|
8
|
+
# macosx
|
9
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
10
|
+
$LDFLAGS += " -framework GLUT"
|
11
|
+
$CPPFLAGS += " -I/System/Library/Frameworks/GLUT.framework/Headers"
|
12
|
+
|
13
|
+
# windows
|
14
|
+
else
|
15
|
+
exit unless have_library("glut32")
|
16
|
+
end
|
17
|
+
|
18
|
+
create_makefile('ctexplay')
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: banister-texplay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Mair (banisterfiend)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-02 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: TexPlay is a light-weight image manipulation framework for Ruby and Gosu
|
17
|
+
email: jrmair@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- src/extconf.rb
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- Rakefile
|
26
|
+
- README
|
27
|
+
- CHANGELOG
|
28
|
+
- README1st
|
29
|
+
- lib/texplay.rb
|
30
|
+
- lib/texplay-contrib.rb
|
31
|
+
has_rdoc: false
|
32
|
+
homepage: http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: TexPlay is a light-weight image manipulation framework for Ruby and Gosu
|
57
|
+
test_files: []
|
58
|
+
|