texplay 0.2.800-i386-mswin32 → 0.2.900-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,69 +1,69 @@
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
- # When using color_control the pixel the draw action is currently manipulating is yielded
16
- # to the proc. This gives you pixel-level control over the drawing.
17
- # (NOTE: the return value of the proc is used as the pixel color, so it should be a 4 element array or
18
- # a valid color symbol)
19
-
20
- # color_control accepts procs of 4 types:
21
- # arity of 0: nothing is yielded and color is set by return value of block
22
- # arity of 1: just the destination pixel color is yielded
23
- # arity of 2: both the destination and the source pixel colors are yielded (in that order)
24
- # arity of 3: the destination pixel color is yielded along with the x and y coords of the current pixel
25
- # arity of 4: both the destination and the source pixel colours are yielded as well as the x and y vals
26
-
27
- # just drawing an area to fill
28
- @img.polyline [30, 30, 100, 100, 200, 76, 300, 9, 50, 200], :color => :random, :closed => true
29
-
30
- # below we are 'faking' a texture fill using color_control
31
- @img.fill 42, 70, :color_control => proc { |c, x, y|
32
- @tp.get_pixel(x % @tp.width, y % @tp.height)
33
- }
34
-
35
- # merging two images together
36
- @img.rect 100, 200, 400, 300, :fill => true, :texture => @gosu,
37
- :color_control => proc { |c1, c2, x, y|
38
- c1 = @tp.get_pixel(x % @tp.width, y % @tp.height)
39
- c1[0] = (c1[0] + c2[0]) / 2
40
- c1[1] = (c1[1] + c2[1]) / 2
41
- c1[2] = (c1[2] + c2[2]) / 2
42
- c1[3] = 1
43
- c1
44
- }
45
-
46
- # we can even use color_control just for the use of the (x, y) values.
47
- # here we simply use the x, y values to make our own circle with a rough edge
48
- @img.circle 200,400, 70,
49
- :color_control => proc { |c,x,y|
50
- @img.pixel(x + (rand(4) - 2), y + (rand(4) - 2))
51
- :none # this ensures that the 'actual' circle isn't drawn, instead its coordinates are
52
- # simply utilized to draw a ragged edge of another circle (using @img.pixel)
53
- }
54
-
55
- # this just fills a rect with random colours
56
- @img.rect 400, 400, 470, 470, :fill => true, :color_control => proc { :rand }
57
- end
58
-
59
- def draw
60
-
61
- @img.draw 100, 50,1
62
- end
63
-
64
- end
65
-
66
-
67
- w = W.new
68
- w.show
69
-
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
+ # When using color_control the pixel the draw action is currently manipulating is yielded
16
+ # to the proc. This gives you pixel-level control over the drawing.
17
+ # (NOTE: the return value of the proc is used as the pixel color, so it should be a 4 element array or
18
+ # a valid color symbol)
19
+
20
+ # color_control accepts procs of 4 types:
21
+ # arity of 0: nothing is yielded and color is set by return value of block
22
+ # arity of 1: just the destination pixel color is yielded
23
+ # arity of 2: both the destination and the source pixel colors are yielded (in that order)
24
+ # arity of 3: the destination pixel color is yielded along with the x and y coords of the current pixel
25
+ # arity of 4: both the destination and the source pixel colours are yielded as well as the x and y vals
26
+
27
+ # just drawing an area to fill
28
+ @img.polyline [30, 30, 100, 100, 200, 76, 300, 9, 50, 200], :color => :random, :closed => true
29
+
30
+ # below we are 'faking' a texture fill using color_control
31
+ @img.fill 42, 70, :color_control => proc { |c, x, y|
32
+ @tp.get_pixel(x % @tp.width, y % @tp.height)
33
+ }
34
+
35
+ # merging two images together
36
+ @img.rect 100, 200, 400, 300, :fill => true, :texture => @gosu,
37
+ :color_control => proc { |c1, c2, x, y|
38
+ c1 = @tp.get_pixel(x % @tp.width, y % @tp.height)
39
+ c1[0] = (c1[0] + c2[0]) / 2
40
+ c1[1] = (c1[1] + c2[1]) / 2
41
+ c1[2] = (c1[2] + c2[2]) / 2
42
+ c1[3] = 1
43
+ c1
44
+ }
45
+
46
+ # we can even use color_control just for the use of the (x, y) values.
47
+ # here we simply use the x, y values to make our own circle with a rough edge
48
+ @img.circle 200,400, 70,
49
+ :color_control => proc { |c,x,y|
50
+ @img.pixel(x + (rand(4) - 2), y + (rand(4) - 2))
51
+ :none # this ensures that the 'actual' circle isn't drawn, instead its coordinates are
52
+ # simply utilized to draw a ragged edge of another circle (using @img.pixel)
53
+ }
54
+
55
+ # this just fills a rect with random colours
56
+ @img.rect 400, 400, 470, 470, :fill => true, :color_control => proc { :rand }
57
+ end
58
+
59
+ def draw
60
+
61
+ @img.draw 100, 50,1
62
+ end
63
+
64
+ end
65
+
66
+
67
+ w = W.new
68
+ w.show
69
+
@@ -1,67 +1,64 @@
1
- require 'rubygems'
2
- require 'common'
3
- require 'gosu'
4
- require 'texplay'
5
- #require 'devil/gosu'
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
- @x = 100
12
- @y = 100
13
-
14
- @x2 = 400
15
- @y2 = 100
16
- @rad = 50
17
- @s = true
18
-
19
- @copy = TexPlay.create_blank_image(self, @rad * 2 + 1, @rad * 2 + 1)
20
- @copy2 = TexPlay.create_blank_image(self, @rad * 2 + 1, @rad * 2 + 1)
21
- end
22
-
23
- def draw
24
-
25
-
26
- @x += 1
27
- @y += 1
28
-
29
- @x2 -= 1
30
- @y2 += 1
31
-
32
-
33
- @copy2.splice @img, 0, 0, :crop => [@x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad], :sync_mode => :no_sync
34
- @copy.splice @img, 0, 0, :crop => [@x - @rad, @y - @rad, @x + @rad, @y + @rad], :sync_mode => :no_sync
35
- @img.
36
- circle @x, @y, @rad, :fill => true, :lerp => 0.3, :color => :red
37
-
38
- @img.circle @x2, @y2, @rad, :fill => true, :lerp => 0.3, :color => :blue
39
- # :color_control => { :mult => [0.3, 0.9, 0.3, 1] }
40
-
41
-
42
- # @img.force_sync [0,0, @img.width, @img.height]
43
-
44
- @img.draw 10, 10,1
45
-
46
- if button_down?(Gosu::KbEscape)
47
- IL.Enable(IL::ORIGIN_SET)
48
- IL.OriginFunc(IL::ORIGIN_UPPER_LEFT)
49
- # screenshot.crop(0,0, 500, 500).save("screenshot.jpg").free
50
- exit
51
- end
52
-
53
- end
54
-
55
- def update
56
- @img.splice @copy, @x - @rad, @y - @rad if !@s
57
- @img.splice @copy2, @x2 - @rad, @y2 - @rad if !@s
58
- @s = nil if @s
59
-
60
- end
61
-
62
- end
63
-
64
-
65
- w = W.new
66
- w.show
67
-
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+ #require 'devil/gosu'
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
+ @x = 100
12
+ @y = 100
13
+
14
+ @x2 = 400
15
+ @y2 = 100
16
+ @rad = 70
17
+ @s = true
18
+
19
+ @copy = TexPlay.create_image(self, @rad * 2 + 1, @rad * 2 + 1)
20
+ @copy2 = TexPlay.create_image(self, @rad * 2 + 1, @rad * 2 + 1)
21
+ end
22
+
23
+ def draw
24
+
25
+
26
+ @x += 3
27
+ @y += 3
28
+
29
+ @x2 -= 3
30
+ @y2 += 3
31
+
32
+
33
+ @copy2.splice @img, 0, 0, :crop => [@x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad], :sync_mode => :no_sync
34
+ @copy.splice @img, 0, 0, :crop => [@x - @rad, @y - @rad, @x + @rad, @y + @rad], :sync_mode => :no_sync
35
+ @img.rect @x - @rad, @y - @rad, @x + @rad, @y + @rad, :fill => true, :mode => :overlay, :color => :red
36
+
37
+ @img.rect @x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad, :fill => true, :mode => :overlay, :color => :blue
38
+
39
+ # @img.force_sync [0,0, @img.width, @img.height]
40
+
41
+ @img.draw 10, 10,1
42
+
43
+ if button_down?(Gosu::KbEscape)
44
+ IL.Enable(IL::ORIGIN_SET)
45
+ IL.OriginFunc(IL::ORIGIN_UPPER_LEFT)
46
+ # screenshot.crop(0,0, 500, 500).save("screenshot.jpg").free
47
+ exit
48
+ end
49
+
50
+ end
51
+
52
+ def update
53
+ @img.splice @copy, @x - @rad, @y - @rad if !@s
54
+ @img.splice @copy2, @x2 - @rad, @y2 - @rad if !@s
55
+ @s = nil if @s
56
+
57
+ end
58
+
59
+ end
60
+
61
+
62
+ w = W.new
63
+ w.show
64
+
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+ #require 'devil/gosu'
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
+ @x = 100
12
+ @y = 100
13
+
14
+ @x2 = 400
15
+ @y2 = 100
16
+ @rad = 70
17
+ @s = true
18
+
19
+ @copy = TexPlay.create_image(self, @rad * 2 + 1, @rad * 2 + 1)
20
+ @copy2 = TexPlay.create_image(self, @rad * 2 + 1, @rad * 2 + 1)
21
+ end
22
+
23
+ def draw
24
+
25
+
26
+ @x += 3
27
+ @y += 3
28
+
29
+ @x2 -= 3
30
+ @y2 += 3
31
+
32
+
33
+ @copy2.splice @img, 0, 0, :crop => [@x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad], :sync_mode => :no_sync
34
+ @copy.splice @img, 0, 0, :crop => [@x - @rad, @y - @rad, @x + @rad, @y + @rad], :sync_mode => :no_sync
35
+
36
+ @img.circle @x, @y, @rad, :fill => true, :mode => :overlay, :color => :red
37
+
38
+ @img.rect @x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad, :fill => true, :mode => :overlay, :color => :blue
39
+
40
+ # @img.force_sync [0,0, @img.width, @img.height]
41
+
42
+ @img.draw 10, 10,1
43
+
44
+ if button_down?(Gosu::KbEscape)
45
+ IL.Enable(IL::ORIGIN_SET)
46
+ IL.OriginFunc(IL::ORIGIN_UPPER_LEFT)
47
+ # screenshot.crop(0,0, 500, 500).save("screenshot.jpg").free
48
+ exit
49
+ end
50
+
51
+ end
52
+
53
+ def update
54
+ @img.splice @copy, @x - @rad, @y - @rad if !@s
55
+ @img.splice @copy2, @x2 - @rad, @y2 - @rad if !@s
56
+ @s = nil if @s
57
+
58
+ end
59
+
60
+ end
61
+
62
+
63
+ w = W.new
64
+ w.show
65
+
@@ -1,75 +1,75 @@
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
- @img.rect 0,0, @img.width - 1, @img.height - 1
12
-
13
- # testing Gosu::Image#dup
14
- # adding an ivar
15
- @img.instance_variable_set(:@horse, :love)
16
-
17
- # adding a method on the singleton
18
- class << @img
19
- def little
20
- :little
21
- end
22
- end
23
-
24
- # clone the image.
25
- # NB #clone also copies singleton
26
- @bunk = @img.clone
27
-
28
- # should output :love
29
- puts @bunk.instance_variable_get(:@horse)
30
-
31
- # should output :little
32
- puts @bunk.little
33
-
34
- # add a red line to the copy to identify it
35
- #@bunk.line 0, 0, 1024, 1024, :color => :red
36
-
37
- @bunk.each(:region =>[200,200,350,350]) { |c,x,y|
38
-
39
- num_pixels = 0
40
- total = [0, 0, 0, 0]
41
- @bunk.circle x, y, 2,
42
- :color_control => proc { |v|
43
- if v
44
- total[0] += v[0]
45
- total[1] += v[1]
46
- total[2] += v[2]
47
- total[3] += v[3]
48
-
49
- num_pixels += 1
50
- end
51
- :none
52
- }
53
-
54
- c[0] = total[0] / num_pixels.to_f
55
- c[1] = total[1] / num_pixels.to_f
56
- c[2] = total[2] / num_pixels.to_f
57
- c[3] = total[3] / num_pixels.to_f
58
- }
59
-
60
- end
61
-
62
- def draw
63
- x = @img.width * rand
64
- y = @img.height * rand
65
-
66
- @img.draw 100, 50,1
67
- @bunk.draw 500, 300,1
68
- end
69
-
70
- end
71
-
72
-
73
- w = W.new
74
- w.show
75
-
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
+ @img.rect 0,0, @img.width - 1, @img.height - 1
12
+
13
+ # testing Gosu::Image#dup
14
+ # adding an ivar
15
+ @img.instance_variable_set(:@horse, :love)
16
+
17
+ # adding a method on the singleton
18
+ class << @img
19
+ def little
20
+ :little
21
+ end
22
+ end
23
+
24
+ # clone the image.
25
+ # NB #clone also copies singleton
26
+ @bunk = @img.clone
27
+
28
+ # should output :love
29
+ puts @bunk.instance_variable_get(:@horse)
30
+
31
+ # should output :little
32
+ puts @bunk.little
33
+
34
+ # add a red line to the copy to identify it
35
+ #@bunk.line 0, 0, 1024, 1024, :color => :red
36
+
37
+ @bunk.each(:region =>[200,200,350,350]) { |c,x,y|
38
+
39
+ num_pixels = 0
40
+ total = [0, 0, 0, 0]
41
+ @bunk.circle x, y, 2,
42
+ :color_control => proc { |v|
43
+ if v
44
+ total[0] += v[0]
45
+ total[1] += v[1]
46
+ total[2] += v[2]
47
+ total[3] += v[3]
48
+
49
+ num_pixels += 1
50
+ end
51
+ :none
52
+ }
53
+
54
+ c[0] = total[0] / num_pixels.to_f
55
+ c[1] = total[1] / num_pixels.to_f
56
+ c[2] = total[2] / num_pixels.to_f
57
+ c[3] = total[3] / num_pixels.to_f
58
+ }
59
+
60
+ end
61
+
62
+ def draw
63
+ x = @img.width * rand
64
+ y = @img.height * rand
65
+
66
+ @img.draw 100, 50,1
67
+ @bunk.draw 500, 300,1
68
+ end
69
+
70
+ end
71
+
72
+
73
+ w = W.new
74
+ w.show
75
+
@@ -1,42 +1,42 @@
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
-
12
- # each can accept a block of two types of arity:
13
- # arity 1 - yields just the pixel color
14
- # arity 3 - yield the pixel color, and the x and y
15
-
16
- # max out the blue component of every pixel
17
- @img.each { |v| v[2] = 1 }
18
-
19
- # a gradient from 0 red to 1 red
20
- @img.each(:region => [100, 100, 200, 200]) do |c, x, y|
21
- c[0] = (x - 100) / 100.0
22
- end
23
-
24
- # another gradient, this time blocking out everything except red (and alpha)
25
- @img.each(:region => [100, 250, 200, 350]) do |c, x, y|
26
- c[0] = (x - 100) / 100.0
27
- c[1] = 0
28
- c[2] = 0
29
- end
30
- end
31
-
32
- def draw
33
-
34
- @img.draw 100, 50,1
35
- end
36
-
37
- end
38
-
39
-
40
- w = W.new
41
- w.show
42
-
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
+
12
+ # each can accept a block of two types of arity:
13
+ # arity 1 - yields just the pixel color
14
+ # arity 3 - yield the pixel color, and the x and y
15
+
16
+ # max out the blue component of every pixel
17
+ @img.each { |v| v[2] = 1 }
18
+
19
+ # a gradient from 0 red to 1 red
20
+ @img.each(:region => [100, 100, 200, 200]) do |c, x, y|
21
+ c[0] = (x - 100) / 100.0
22
+ end
23
+
24
+ # another gradient, this time blocking out everything except red (and alpha)
25
+ @img.each(:region => [100, 250, 200, 350]) do |c, x, y|
26
+ c[0] = (x - 100) / 100.0
27
+ c[1] = 0
28
+ c[2] = 0
29
+ end
30
+ end
31
+
32
+ def draw
33
+
34
+ @img.draw 100, 50,1
35
+ end
36
+
37
+ end
38
+
39
+
40
+ w = W.new
41
+ w.show
42
+
@@ -1,35 +1,35 @@
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
- def draw
18
-
19
- # quite a cool effect, very slow of course, because it's using turtle and fill
20
- @img.paint {
21
- forward(@length, true, :color => :red)
22
- turn(170)
23
- @length += 5
24
- fill (@img.width * rand), (@img.height * rand), :color => :random, :glow => true
25
- }
26
-
27
- @img.draw 100, 50,1
28
- end
29
-
30
- end
31
-
32
-
33
- w = W.new
34
- w.show
35
-
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
+ def draw
18
+
19
+ # quite a cool effect, very slow of course, because it's using turtle and fill
20
+ @img.paint {
21
+ forward(@length, true, :color => :red)
22
+ turn(170)
23
+ @length += 5
24
+ fill (@img.width * rand), (@img.height * rand), :color => :random, :glow => true
25
+ }
26
+
27
+ @img.draw 100, 50,1
28
+ end
29
+
30
+ end
31
+
32
+
33
+ w = W.new
34
+ w.show
35
+