From e81d32b470cdead1c114b6d1b5b6bda958d6b1ad Mon Sep 17 00:00:00 2001 From: Tom Black Date: Sat, 24 Dec 2016 22:17:34 -0600 Subject: Merge all tests into `test/` directory --- .gitmodules | 4 +- .rspec | 3 +- Rakefile | 14 ++-- spec/color_spec.rb | 37 ----------- spec/dsl_spec.rb | 29 -------- spec/spec_helper.rb | 23 ------- spec/sprite_spec.rb | 11 --- test/color_spec.rb | 37 +++++++++++ test/controller.rb | 47 +++++++++++++ test/dsl_spec.rb | 29 ++++++++ test/input.rb | 49 ++++++++++++++ test/spec_helper.rb | 23 +++++++ test/sprite_spec.rb | 11 +++ test/testcard.rb | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/controller.rb | 37 ----------- tests/input.rb | 67 ------------------- tests/media | 1 - tests/testcard.rb | 188 ---------------------------------------------------- 18 files changed, 395 insertions(+), 403 deletions(-) delete mode 100644 spec/color_spec.rb delete mode 100644 spec/dsl_spec.rb delete mode 100644 spec/spec_helper.rb delete mode 100644 spec/sprite_spec.rb create mode 100644 test/color_spec.rb create mode 100644 test/controller.rb create mode 100644 test/dsl_spec.rb create mode 100644 test/input.rb create mode 100644 test/spec_helper.rb create mode 100644 test/sprite_spec.rb create mode 100644 test/testcard.rb delete mode 100644 tests/controller.rb delete mode 100644 tests/input.rb delete mode 160000 tests/media delete mode 100644 tests/testcard.rb diff --git a/.gitmodules b/.gitmodules index a123c40..2ad3adc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ -[submodule "tests/media"] - path = tests/media +[submodule "test/media"] + path = test/media url = https://github.com/simple2d/test_media.git [submodule "assets"] path = assets diff --git a/.rspec b/.rspec index 83e16f8..fc3c9e9 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,3 @@ ---color +--default-path test --require spec_helper +--color diff --git a/Rakefile b/Rakefile index bc22822..fc4cdc1 100644 --- a/Rakefile +++ b/Rakefile @@ -27,8 +27,8 @@ def run_cmd(cmd) end def run_test(file) - print_task "Running tests/#{file}.rb" - system "( cd tests/ ; ruby #{file}.rb )" + print_task "Running test/#{file}.rb" + system "( cd test/ ; ruby #{file}.rb )" end # Tasks @@ -56,7 +56,7 @@ end desc "Run the RSpec tests" RSpec::Core::RakeTask.new do |t| print_task "Running RSpec" - t.pattern = "spec/*spec.rb" + t.pattern = "test/*spec.rb" end desc "Run testcard" @@ -72,15 +72,15 @@ end desc "Run native build test" task :native do print_task "Running native build test" - run_cmd "ruby2d build native tests/testcard.rb" - print_task "Running native tests/testcard.rb" - system "( cd tests/ ; ../build/app )" + run_cmd "ruby2d build native test/testcard.rb" + print_task "Running native test/testcard.rb" + system "( cd test/ ; ../build/app )" end desc "Run web build test" task :web do print_task "Running web build test" - run_cmd "ruby2d build web tests/testcard.rb" + run_cmd "ruby2d build web test/testcard.rb" end desc "Uninstall, build, install, and test" diff --git a/spec/color_spec.rb b/spec/color_spec.rb deleted file mode 100644 index ed23712..0000000 --- a/spec/color_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'ruby2d' - -RSpec.describe Ruby2D::Color do - - describe '#is_valid?' do - it 'determines if a color string is valid' do - expect(Ruby2D::Color.is_valid? 'red').to eq true - expect(Ruby2D::Color.is_valid? 'balloons').to eq false - end - - it 'determines if a color string is valid hex value: # follow by 6 letters/numbers' do - expect(Ruby2D::Color.is_valid? '#c0c0c0').to eq true - expect(Ruby2D::Color.is_valid? '#00000').to eq false - expect(Ruby2D::Color.is_valid? '123456').to eq false - end - - it 'determines if an array is a valid color' do - expect(Ruby2D::Color.is_valid? [1.0, 0, 0, 1.0]).to eq true - expect(Ruby2D::Color.is_valid? [1.0, 0, 0]).to eq false - end - - it 'prevents allow color values out of range' do - expect(Ruby2D::Color.is_valid? [1.0, 0, 0.0, 255]).to eq true - expect(Ruby2D::Color.is_valid? [1.2, 0, 0, 0]).to eq false - expect(Ruby2D::Color.is_valid? [-0.1, 0, 0, 0]).to eq false - expect(Ruby2D::Color.is_valid? [255, 255, 256, 255]).to eq false - expect(Ruby2D::Color.is_valid? [-1, 0, 127, 255]).to eq false - end - end - - describe '#new' do - it 'raises error on bad color' do - expect { Ruby2D::Color.new 42 }.to raise_error Ruby2D::Error - end - end - -end diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb deleted file mode 100644 index 6d3d8b4..0000000 --- a/spec/dsl_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'ruby2d' - -RSpec.describe Ruby2D::DSL do - - describe '#get' do - it 'gets the default window attributes' do - expect(get :width).to eq 640 - expect(get :height).to eq 480 - expect(get :title).to eq "Ruby 2D" - end - end - - describe '#set' do - it 'sets a single window attribute' do - set width: 300 - expect(get :width).to eq 300 - expect(get :height).to eq 480 - expect(get :title).to eq "Ruby 2D" - end - - it 'sets multiple window attributes at a time' do - set width: 800, height: 600, title: "Hello tests!" - expect(get :width).to eq 800 - expect(get :height).to eq 600 - expect(get :title).to eq "Hello tests!" - end - end - -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index d93bff8..0000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,23 +0,0 @@ -RSpec.configure do |config| - config.expect_with :rspec do |expectations| - expectations.include_chain_clauses_in_custom_matcher_descriptions = true - end - - config.mock_with :rspec do |mocks| - mocks.verify_partial_doubles = true - end - - # Silence output when running tests - original_stderr = $stderr - original_stdout = $stdout - config.before(:all) do - # Redirect stderr and stdout - $stderr = File.open(File::NULL, "w") - $stdout = File.open(File::NULL, "w") - end - config.after(:all) do - # Restore - $stderr = original_stderr - $stdout = original_stdout - end -end diff --git a/spec/sprite_spec.rb b/spec/sprite_spec.rb deleted file mode 100644 index 42268be..0000000 --- a/spec/sprite_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'ruby2d' - -RSpec.describe Ruby2D::Sprite do - - describe '#new' do - it 'creates a new sprite' do - Ruby2D::Sprite.new(0, 0, "tests/media/sprite_sheet.png") - end - end - -end diff --git a/test/color_spec.rb b/test/color_spec.rb new file mode 100644 index 0000000..ed23712 --- /dev/null +++ b/test/color_spec.rb @@ -0,0 +1,37 @@ +require 'ruby2d' + +RSpec.describe Ruby2D::Color do + + describe '#is_valid?' do + it 'determines if a color string is valid' do + expect(Ruby2D::Color.is_valid? 'red').to eq true + expect(Ruby2D::Color.is_valid? 'balloons').to eq false + end + + it 'determines if a color string is valid hex value: # follow by 6 letters/numbers' do + expect(Ruby2D::Color.is_valid? '#c0c0c0').to eq true + expect(Ruby2D::Color.is_valid? '#00000').to eq false + expect(Ruby2D::Color.is_valid? '123456').to eq false + end + + it 'determines if an array is a valid color' do + expect(Ruby2D::Color.is_valid? [1.0, 0, 0, 1.0]).to eq true + expect(Ruby2D::Color.is_valid? [1.0, 0, 0]).to eq false + end + + it 'prevents allow color values out of range' do + expect(Ruby2D::Color.is_valid? [1.0, 0, 0.0, 255]).to eq true + expect(Ruby2D::Color.is_valid? [1.2, 0, 0, 0]).to eq false + expect(Ruby2D::Color.is_valid? [-0.1, 0, 0, 0]).to eq false + expect(Ruby2D::Color.is_valid? [255, 255, 256, 255]).to eq false + expect(Ruby2D::Color.is_valid? [-1, 0, 127, 255]).to eq false + end + end + + describe '#new' do + it 'raises error on bad color' do + expect { Ruby2D::Color.new 42 }.to raise_error Ruby2D::Error + end + end + +end diff --git a/test/controller.rb b/test/controller.rb new file mode 100644 index 0000000..0007ddd --- /dev/null +++ b/test/controller.rb @@ -0,0 +1,47 @@ +require 'ruby2d' + +set width: 200, height: 100, title: "Ruby 2D – Controller" + +on controller: 'left' do + puts "conroller left" +end + +on controller: 'right' do + puts "conroller right" +end + +on controller: 'up' do + puts "conroller up" +end + +on controller: 'down' do + puts "conroller down" +end + +on controller: 0 do + puts "conroller btn 0" +end + +on controller: 1 do + puts "conroller btn 1" +end + +on controller: 2 do + puts "conroller btn 2" +end + +on controller: 3 do + puts "conroller btn 3" +end + +on_controller do |which, is_axis, axis, val, is_btn, btn| + puts "=== Controller Pressed ===", + "which: which", + "is_axis: #{is_axis}", + "axis: #{axis}", + "val: #{val}", + "is_btn: #{is_btn}", + "btn: #{btn}" +end + +show diff --git a/test/dsl_spec.rb b/test/dsl_spec.rb new file mode 100644 index 0000000..6d3d8b4 --- /dev/null +++ b/test/dsl_spec.rb @@ -0,0 +1,29 @@ +require 'ruby2d' + +RSpec.describe Ruby2D::DSL do + + describe '#get' do + it 'gets the default window attributes' do + expect(get :width).to eq 640 + expect(get :height).to eq 480 + expect(get :title).to eq "Ruby 2D" + end + end + + describe '#set' do + it 'sets a single window attribute' do + set width: 300 + expect(get :width).to eq 300 + expect(get :height).to eq 480 + expect(get :title).to eq "Ruby 2D" + end + + it 'sets multiple window attributes at a time' do + set width: 800, height: 600, title: "Hello tests!" + expect(get :width).to eq 800 + expect(get :height).to eq 600 + expect(get :title).to eq "Hello tests!" + end + end + +end diff --git a/test/input.rb b/test/input.rb new file mode 100644 index 0000000..9c8d7b2 --- /dev/null +++ b/test/input.rb @@ -0,0 +1,49 @@ +require 'ruby2d' + +set width: 200, height: 100, title: "Ruby 2D – Input" + +on key_down: 'a' do + puts "Key 'a' pressed" +end + +on key: 'a' do + puts "Key 'a' held down" +end + +on key_up: 'a' do + puts "Key 'a' released" +end + +on key_down: 'any' do + puts "A key was pressed" +end + +on_key do |key| + puts "on_key: #{key}" +end + +on mouse: 'left' do + puts "mouse left" +end + +on mouse: 'right' do + puts "mouse right" +end + +on mouse: 'down' do + puts "mouse down" +end + +on mouse: 'up' do + puts "mouse up" +end + +on mouse: 'any' do + puts "mouse any" +end + +on key: 'escape' do + close +end + +show diff --git a/test/spec_helper.rb b/test/spec_helper.rb new file mode 100644 index 0000000..d93bff8 --- /dev/null +++ b/test/spec_helper.rb @@ -0,0 +1,23 @@ +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + + # Silence output when running tests + original_stderr = $stderr + original_stdout = $stdout + config.before(:all) do + # Redirect stderr and stdout + $stderr = File.open(File::NULL, "w") + $stdout = File.open(File::NULL, "w") + end + config.after(:all) do + # Restore + $stderr = original_stderr + $stdout = original_stdout + end +end diff --git a/test/sprite_spec.rb b/test/sprite_spec.rb new file mode 100644 index 0000000..42268be --- /dev/null +++ b/test/sprite_spec.rb @@ -0,0 +1,11 @@ +require 'ruby2d' + +RSpec.describe Ruby2D::Sprite do + + describe '#new' do + it 'creates a new sprite' do + Ruby2D::Sprite.new(0, 0, "tests/media/sprite_sheet.png") + end + end + +end diff --git a/test/testcard.rb b/test/testcard.rb new file mode 100644 index 0000000..dfe049b --- /dev/null +++ b/test/testcard.rb @@ -0,0 +1,188 @@ +unless RUBY_ENGINE == 'opal' + require 'ruby2d' +end + +if RUBY_ENGINE == 'opal' + media = "../tests/media" +else + media = "media" +end + +set diagnostics: true + +set width: 700, height: 500, title: "Ruby 2D – Test Card" + +# Read window attributes +puts "=== Window Attributes === +Title: #{get :title} +Width: #{get :width} +Height: #{get :height} +FPS: #{get :fps} +Self: #{get :window}\n\n" + +# Primary colors +Rectangle.new(0, 0, 50, 100, [1, 0, 0, 1]) +Rectangle.new(50, 0, 50, 100, [0, 1, 0, 1]) +Rectangle.new(100, 0, 50, 100, [0, 0, 1, 1]) + +# Color strings +Square.new( 150, 0, 50, 'black') +Square.new( 200, 0, 50, 'gray') +Square.new( 250, 0, 50, 'silver') +Square.new( 300, 0, 50, 'white') +Rectangle.new(350, 0, 50, 50, 'navy') +Rectangle.new(400, 0, 50, 50, 'blue') +Rectangle.new(450, 0, 50, 50, 'aqua') +Rectangle.new(500, 0, 50, 50, 'teal') +Rectangle.new(550, 0, 50, 50, 'olive') + +Rectangle.new(150, 50, 50, 50, 'green') +Rectangle.new(200, 50, 50, 50, 'lime') +Rectangle.new(250, 50, 50, 50, 'yellow') +Rectangle.new(300, 50, 50, 50, 'orange') +Rectangle.new(350, 50, 50, 50, 'red') +Rectangle.new(400, 50, 50, 50, 'maroon') +Rectangle.new(450, 50, 50, 50, 'fuchsia') +Rectangle.new(500, 50, 50, 50, 'purple') +Rectangle.new(550, 50, 50, 50, 'brown') + +# Mix of named colors and numbers +Rectangle.new(600, 0, 50, 50, +[ + 'red', + 'green', + 'blue', + 'yellow' +]) +Rectangle.new(650, 0, 50, 50, +[ + [1.0, 0, 0, 1], + 'green', + [0.0, 0, 1, 1.0], + 'yellow' +]) +Rectangle.new(600, 50, 50, 50, 'random') +Rectangle.new(650, 50, 50, 50, 'random') + +# White to black gradient +Rectangle.new(0, 100, 700, 25, +[ + [1.0, 1.0, 1.0, 1.0], + [0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0], + [1.0, 1.0, 1.0, 1.0] +]) + +# Color gradient +Rectangle.new(0, 125, 700, 50, +[ + [1.0, 0.0, 0.0, 1.0], + [0.0, 1.0, 0.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [1.0, 1.0, 0.0, 1.0] +]) + +# Transparancy +Rectangle.new(0, 165, 700, 35, +[ + [1.0, 1.0, 1.0, 0.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 0.0] +]) + +# Triangles +Triangle.new(25, 200, 50, 250, 0, 250, [1.0, 0, 0, 1.0]) +Triangle.new(75, 200, 100, 250, 50, 250, [ 0, 1.0, 0, 1.0]) +Triangle.new(125, 200, 150, 250, 100, 250, [ 0, 0, 1.0, 1.0]) +Triangle.new(175, 200, 200, 250, 150, 250, +[ + [1.0, 0, 0, 1.0], + [0, 1.0, 0, 1.0], + [0, 0, 1.0, 1.0] +]) +Rectangle.new(200, 200, 50, 50, [0.5, 0.5, 0.5, 1.0]) # add background for transparancy +Triangle.new(225, 200, 250, 250, 200, 250, +[ + [1.0, 1.0, 1.0, 1.0], + [0.0, 0.0, 0.0, 1.0], + [1.0, 1.0, 1.0, 0.0] +]) + +# Quadrilaterals +Quad.new( + 300, 200, + 350, 200, + 300, 250, + 250, 250, + [ + [1.0, 0.0, 0.0, 1.0], + [0.0, 1.0, 0.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [1.0, 1.0, 0.0, 1.0] + ] +) + +Quad.new( + 250, 200, + 300, 200, + 350, 250, + 300, 250, + [ + [1.0, 1.0, 1.0, 0.0], + [1.0, 1.0, 1.0, 0.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 0.0] + ] +) + +# Images +Image.new(590, 180, "#{media}/image.png") +Image.new(590, 290, "#{media}/image.jpg") +Image.new(590, 400, "#{media}/image.bmp") +img_r = Image.new(350, 200, "#{media}/colors.png") +img_r.width, img_r.height = 50, 50 +# img_r.color = [1.0, 0.3, 0.3, 1.0] +img_g = Image.new(400, 200, "#{media}/colors.png") +img_g.width, img_g.height = 50, 50 +# img_g.color = [0.3, 1.0, 0.3, 1.0] +img_b = Image.new(450, 200, "#{media}/colors.png") +img_b.width, img_b.height = 50, 50 +# img_b.color = [0.3, 0.3, 1.0, 1.0] + +# Text +txt_r = Text.new( 44, 202, 20, "R", "#{media}/bitstream_vera/vera.ttf") +# txt_r.color = [1.0, 0.0, 0.0, 1.0] +txt_g = Text.new( 92, 202, 20, "G", "#{media}/bitstream_vera/vera.ttf") +# txt_g.color = [0.0, 1.0, 0.0, 1.0] +txt_b = Text.new(144, 202, 20, "B", "#{media}/bitstream_vera/vera.ttf") +# txt_b.color = [0.0, 0.0, 1.0, 1.0] + +# Frames per second +fps = Text.new(10, 470, 20, "", "#{media}/bitstream_vera/vera.ttf") + +# Sprites +s1 = Sprite.new(500, 200, "#{media}/sprite_sheet.png") +s1.add(forwards: [ + [ 0, 0, 50, 50, 30], + [ 50, 0, 50, 50, 40], + [100, 0, 50, 50, 50], + [150, 0, 50, 50, 60] +]) + +# Pointer for mouse +pointer = Square.new(0, 0, 10, 'white') + +on key: 'escape' do + close +end + +update do + pointer.x = (get :mouse_x) - 5 + pointer.y = (get :mouse_y) - 7 + s1.animate(:forwards) + # puts get :fps + fps.text = "FPS: #{(get :fps).round(3)}" +end + +show diff --git a/tests/controller.rb b/tests/controller.rb deleted file mode 100644 index e54df9d..0000000 --- a/tests/controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'ruby2d' - -set width: 200, height: 100, title: "Ruby 2D – Controller" - -on controller: 'left' do - puts "conroller left" -end - -on controller: 'right' do - puts "conroller right" -end - -on controller: 'up' do - puts "conroller up" -end - -on controller: 'down' do - puts "conroller down" -end - -on controller: 0 do - puts "conroller btn 0" -end - -on controller: 1 do - puts "conroller btn 1" -end - -on controller: 2 do - puts "conroller btn 2" -end - -on controller: 3 do - puts "conroller btn 3" -end - -show diff --git a/tests/input.rb b/tests/input.rb deleted file mode 100644 index fbf0530..0000000 --- a/tests/input.rb +++ /dev/null @@ -1,67 +0,0 @@ -require 'ruby2d' - -set width: 200, height: 100, title: "Ruby 2D – Input" - -on key: 'a' do - puts "on key: 'a'" -end - -on key_up: 's' do - puts "on key_up: 's'" -end - -on key_down: 'd' do - puts "on key_down: 'd'" -end - -on key: 'any' do - puts "on key: 'any'" -end - -on key_down: 'any' do - puts "on key_down: 'any'" -end - -on key_up: 'any' do - puts "on key_up: 'any'" -end - -on_key do |key| - puts "on_key: #{key}" -end - -on_controller do |which, is_axis, axis, val, is_btn, btn| - puts "=== Controller Pressed ===", - "which: which", - "is_axis: #{is_axis}", - "axis: #{axis}", - "val: #{val}", - "is_btn: #{is_btn}", - "btn: #{btn}" -end - -on mouse: 'left' do - puts "mouse left" -end - -on mouse: 'right' do - puts "mouse right" -end - -on mouse: 'down' do - puts "mouse down" -end - -on mouse: 'up' do - puts "mouse up" -end - -on mouse: 'any' do - puts "mouse any" -end - -on key: 'escape' do - close -end - -show diff --git a/tests/media b/tests/media deleted file mode 160000 index fd57d1c..0000000 --- a/tests/media +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fd57d1c22c11b1cc84b160236718b7e26c438a36 diff --git a/tests/testcard.rb b/tests/testcard.rb deleted file mode 100644 index dfe049b..0000000 --- a/tests/testcard.rb +++ /dev/null @@ -1,188 +0,0 @@ -unless RUBY_ENGINE == 'opal' - require 'ruby2d' -end - -if RUBY_ENGINE == 'opal' - media = "../tests/media" -else - media = "media" -end - -set diagnostics: true - -set width: 700, height: 500, title: "Ruby 2D – Test Card" - -# Read window attributes -puts "=== Window Attributes === -Title: #{get :title} -Width: #{get :width} -Height: #{get :height} -FPS: #{get :fps} -Self: #{get :window}\n\n" - -# Primary colors -Rectangle.new(0, 0, 50, 100, [1, 0, 0, 1]) -Rectangle.new(50, 0, 50, 100, [0, 1, 0, 1]) -Rectangle.new(100, 0, 50, 100, [0, 0, 1, 1]) - -# Color strings -Square.new( 150, 0, 50, 'black') -Square.new( 200, 0, 50, 'gray') -Square.new( 250, 0, 50, 'silver') -Square.new( 300, 0, 50, 'white') -Rectangle.new(350, 0, 50, 50, 'navy') -Rectangle.new(400, 0, 50, 50, 'blue') -Rectangle.new(450, 0, 50, 50, 'aqua') -Rectangle.new(500, 0, 50, 50, 'teal') -Rectangle.new(550, 0, 50, 50, 'olive') - -Rectangle.new(150, 50, 50, 50, 'green') -Rectangle.new(200, 50, 50, 50, 'lime') -Rectangle.new(250, 50, 50, 50, 'yellow') -Rectangle.new(300, 50, 50, 50, 'orange') -Rectangle.new(350, 50, 50, 50, 'red') -Rectangle.new(400, 50, 50, 50, 'maroon') -Rectangle.new(450, 50, 50, 50, 'fuchsia') -Rectangle.new(500, 50, 50, 50, 'purple') -Rectangle.new(550, 50, 50, 50, 'brown') - -# Mix of named colors and numbers -Rectangle.new(600, 0, 50, 50, -[ - 'red', - 'green', - 'blue', - 'yellow' -]) -Rectangle.new(650, 0, 50, 50, -[ - [1.0, 0, 0, 1], - 'green', - [0.0, 0, 1, 1.0], - 'yellow' -]) -Rectangle.new(600, 50, 50, 50, 'random') -Rectangle.new(650, 50, 50, 50, 'random') - -# White to black gradient -Rectangle.new(0, 100, 700, 25, -[ - [1.0, 1.0, 1.0, 1.0], - [0.0, 0.0, 0.0, 0.0], - [0.0, 0.0, 0.0, 0.0], - [1.0, 1.0, 1.0, 1.0] -]) - -# Color gradient -Rectangle.new(0, 125, 700, 50, -[ - [1.0, 0.0, 0.0, 1.0], - [0.0, 1.0, 0.0, 1.0], - [0.0, 0.0, 1.0, 1.0], - [1.0, 1.0, 0.0, 1.0] -]) - -# Transparancy -Rectangle.new(0, 165, 700, 35, -[ - [1.0, 1.0, 1.0, 0.0], - [1.0, 1.0, 1.0, 1.0], - [1.0, 1.0, 1.0, 1.0], - [1.0, 1.0, 1.0, 0.0] -]) - -# Triangles -Triangle.new(25, 200, 50, 250, 0, 250, [1.0, 0, 0, 1.0]) -Triangle.new(75, 200, 100, 250, 50, 250, [ 0, 1.0, 0, 1.0]) -Triangle.new(125, 200, 150, 250, 100, 250, [ 0, 0, 1.0, 1.0]) -Triangle.new(175, 200, 200, 250, 150, 250, -[ - [1.0, 0, 0, 1.0], - [0, 1.0, 0, 1.0], - [0, 0, 1.0, 1.0] -]) -Rectangle.new(200, 200, 50, 50, [0.5, 0.5, 0.5, 1.0]) # add background for transparancy -Triangle.new(225, 200, 250, 250, 200, 250, -[ - [1.0, 1.0, 1.0, 1.0], - [0.0, 0.0, 0.0, 1.0], - [1.0, 1.0, 1.0, 0.0] -]) - -# Quadrilaterals -Quad.new( - 300, 200, - 350, 200, - 300, 250, - 250, 250, - [ - [1.0, 0.0, 0.0, 1.0], - [0.0, 1.0, 0.0, 1.0], - [0.0, 0.0, 1.0, 1.0], - [1.0, 1.0, 0.0, 1.0] - ] -) - -Quad.new( - 250, 200, - 300, 200, - 350, 250, - 300, 250, - [ - [1.0, 1.0, 1.0, 0.0], - [1.0, 1.0, 1.0, 0.0], - [1.0, 1.0, 1.0, 1.0], - [1.0, 1.0, 1.0, 0.0] - ] -) - -# Images -Image.new(590, 180, "#{media}/image.png") -Image.new(590, 290, "#{media}/image.jpg") -Image.new(590, 400, "#{media}/image.bmp") -img_r = Image.new(350, 200, "#{media}/colors.png") -img_r.width, img_r.height = 50, 50 -# img_r.color = [1.0, 0.3, 0.3, 1.0] -img_g = Image.new(400, 200, "#{media}/colors.png") -img_g.width, img_g.height = 50, 50 -# img_g.color = [0.3, 1.0, 0.3, 1.0] -img_b = Image.new(450, 200, "#{media}/colors.png") -img_b.width, img_b.height = 50, 50 -# img_b.color = [0.3, 0.3, 1.0, 1.0] - -# Text -txt_r = Text.new( 44, 202, 20, "R", "#{media}/bitstream_vera/vera.ttf") -# txt_r.color = [1.0, 0.0, 0.0, 1.0] -txt_g = Text.new( 92, 202, 20, "G", "#{media}/bitstream_vera/vera.ttf") -# txt_g.color = [0.0, 1.0, 0.0, 1.0] -txt_b = Text.new(144, 202, 20, "B", "#{media}/bitstream_vera/vera.ttf") -# txt_b.color = [0.0, 0.0, 1.0, 1.0] - -# Frames per second -fps = Text.new(10, 470, 20, "", "#{media}/bitstream_vera/vera.ttf") - -# Sprites -s1 = Sprite.new(500, 200, "#{media}/sprite_sheet.png") -s1.add(forwards: [ - [ 0, 0, 50, 50, 30], - [ 50, 0, 50, 50, 40], - [100, 0, 50, 50, 50], - [150, 0, 50, 50, 60] -]) - -# Pointer for mouse -pointer = Square.new(0, 0, 10, 'white') - -on key: 'escape' do - close -end - -update do - pointer.x = (get :mouse_x) - 5 - pointer.y = (get :mouse_y) - 7 - s1.animate(:forwards) - # puts get :fps - fps.text = "FPS: #{(get :fps).round(3)}" -end - -show -- cgit v1.2.3