From 23fea974a4369282905abf36f051bbbfc7e36863 Mon Sep 17 00:00:00 2001 From: Tom Black Date: Thu, 20 Sep 2018 21:09:43 -0700 Subject: Add `Circle` class --- test/circle_spec.rb | 16 ++++++++++++++++ test/contains.rb | 1 + test/testcard.rb | 43 ++++++++++++++++++++----------------------- 3 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 test/circle_spec.rb (limited to 'test') diff --git a/test/circle_spec.rb b/test/circle_spec.rb new file mode 100644 index 0000000..f100cde --- /dev/null +++ b/test/circle_spec.rb @@ -0,0 +1,16 @@ +require 'ruby2d' + +RSpec.describe Ruby2D::Circle do + + describe '#new' do + it "creates a white circle by default" do + circle = Circle.new + expect(circle.color).to be_a(Ruby2D::Color) + expect(circle.color.r).to eq(1) + expect(circle.color.g).to eq(1) + expect(circle.color.b).to eq(1) + expect(circle.color.a).to eq(1) + end + end + +end diff --git a/test/contains.rb b/test/contains.rb index f3b3c15..c5c6686 100644 --- a/test/contains.rb +++ b/test/contains.rb @@ -16,6 +16,7 @@ objects.push Rectangle.new(x: 200, y: 50, width: 100, height: 75) objects.push Quad.new(x1: 350, y1: 50, x2: 500, y2: 75, x3: 450, y3: 150, x4: 375, y4: 125) objects.push Triangle.new(x1: 550, y1: 50, x2: 600, y2: 125, x3: 500, y3: 150) objects.push Line.new(x1: 225, y1: 175, x2: 375, y2: 225, width: 20) +objects.push Circle.new(x: 225, y: 275, radius: 50) objects.push Image.new(x: 50, y: 200, path: "#{media}/colors.png") objects.push Text.new(x: 450, y: 200, text: "Hello", size: 50, font: font) diff --git a/test/testcard.rb b/test/testcard.rb index 876c5c4..c433aa4 100644 --- a/test/testcard.rb +++ b/test/testcard.rb @@ -35,7 +35,6 @@ Rectangle.new(x: 400, width: 50, height: 50, color: 'blue') Rectangle.new(x: 450, width: 50, height: 50, color: 'aqua') Rectangle.new(x: 500, width: 50, height: 50, color: 'teal') Rectangle.new(x: 550, width: 50, height: 50, color: 'olive') - Rectangle.new(x: 150, y: 50, width: 50, height: 50, color: 'green') Rectangle.new(x: 200, y: 50, width: 50, height: 50, color: 'lime') Rectangle.new(x: 250, y: 50, width: 50, height: 50, color: 'yellow') @@ -49,17 +48,6 @@ Rectangle.new(x: 550, y: 50, width: 50, height: 50, color: 'brown') # Mix of named colors and numbers Rectangle.new( x: 600, - width: 50, - height: 50, - color: [ - 'red', - 'green', - 'blue', - 'yellow' - ] -) -Rectangle.new( - x: 650, y: 0, width: 50, height: 50, @@ -70,8 +58,18 @@ Rectangle.new( 'yellow' ] ) + +# Check opacity +opacity_square = Square.new( + x: 650, + y: 0, + size: 50, + color: ['red', 'green', 'blue', 'yellow'] +) + +# Fill remaining area with random colors Rectangle.new(x: 600, y: 50, width: 50, height: 50, color: 'random') -Rectangle.new(x: 650, y: 50, width: 50, height: 50, color: 'random') +Square.new(x: 650, y: 50, size: 50, color: 'random') # White to black gradient Rectangle.new( @@ -199,12 +197,18 @@ Line.new( ] ); +# Circles + +Circle.new(x: 525, y: 225, radius: 25, color: [1.0, 0.2, 0.2, 1.0]) +Circle.new(x: 575, y: 225, radius: 25, sectors: 8, color: [0.2, 1.0, 0.2, 1.0]) +Circle.new(x: 575, y: 225, radius: 17, sectors: 16, color: [0, 0, 0, 0.6]) + rotate = false # Images -img_png = Image.new(x: 590, y: 180, path: "#{media}/image.png") -img_jpg = Image.new(x: 590, y: 290, path: "#{media}/image.jpg") -img_bmp = Image.new(x: 590, y: 400, path: "#{media}/image.bmp") +img_png = Image.new(x: 600, y: 180, path: "#{media}/image.png") +img_jpg = Image.new(x: 600, y: 290, path: "#{media}/image.jpg") +img_bmp = Image.new(x: 600, y: 400, path: "#{media}/image.bmp") img_r = Image.new(x: 400, y: 200, width: 50, height: 25, path: "#{media}/colors.png") img_r.color = [1.0, 0.3, 0.3, 1.0] img_g = Image.new(x: 400, y: 225, path: "#{media}/colors.png") @@ -237,13 +241,6 @@ pointer = Square.new(size: 10) pointer_outline = Square.new(size: 18, color: [0, 1, 0, 0]) flash = 0 -# Updating opacity -opacity_square = Square.new( - x: 500, - y: 200, - size: 50, - color: ["red", "green", "blue", "yellow"] -) time_start = Time.now # Text size -- cgit v1.2.3