Difference between revisions of "Render Part B Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 29: Line 29:
  
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 +
 +
NOTE: render_transformed() must be private.
  
 
==ColorTransform==
 
==ColorTransform==
Line 49: Line 51:
  
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 +
 +
NOTE: render_transformed() must be private.
  
 
==Ellipse==
 
==Ellipse==
Line 62: Line 66:
  
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 +
 +
NOTE: render_transformed() must be private.
  
 
==EquilateralTriangle==
 
==EquilateralTriangle==
Line 75: Line 81:
  
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 +
 +
NOTE: render_transformed() must be private.
  
 
==BezierCurve==
 
==BezierCurve==
Line 88: Line 96:
  
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 +
 +
NOTE: render_transformed() must be private.
  
 
==Chord==
 
==Chord==
Line 101: Line 111:
  
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 +
 +
NOTE: render_transformed() must be private.
  
 
==Rectangle==
 
==Rectangle==
Line 114: Line 126:
  
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 
NOTE: Be sure to not override render.  Implement the render_transformed method instead.
 +
 +
NOTE: render_transformed() must be private.
  
 
==CompositeTransform==
 
==CompositeTransform==
Line 120: Line 134:
 
Add a push_component method which accepts a component which will later be rendered.
 
Add a push_component method which accepts a component which will later be rendered.
  
The private render_transformed method should render each pushed component.
+
The render_transformed method should render each pushed component.
 +
 
 +
NOTE: render_transformed() must be private.
  
 
==class Scene==
 
==class Scene==

Revision as of 06:42, 30 November 2020

In this studio we will evolve our code from Render_Part_A_Assignment to leverage class hierarchies.

Render part b class hierarchy.svg

Continue editing files in the render/assignment directory.

In this studio, we will have parameters for which explicitly passed arguments are not required (for convenience and backwards compatibility). We will prefer keyword arguments over optional arguments.

Code to Implement

Transform

file: src/main/ruby/render/assignment/transform.rb Ruby logo.svg
class: Transform
superclass: Object
methods: initialize(x,y)
render()

Transform's constructor should take x and y parameters and store them in instance variables.

It should define a render method which preserves the current model view transformation, translates in the z==0 plane, passes the render_transformed message to itself, and restores the model view transformation.

All subclasses must implement a private render_transformed method.

Image

file: src/main/ruby/render/assignment/image.rb Ruby logo.svg
class: Image
superclass: Transform
methods to evolve: initialize(path, x: 0, y: 0)
methods to add: render_transformed()
methods to remove: render()

You will evolve your code from from Part A

be sure to add the following line above your class:

require_relative 'transform'

Add keyword parameters for x: 0 and y: 0 and invoke your superclass with these parameters.

NOTE: Be sure to not override render. Implement the render_transformed method instead.

NOTE: render_transformed() must be private.

ColorTransform

file: src/main/ruby/render/assignment/color_transform.rb Ruby logo.svg
class: ColorTransform
superclass: Transform
methods: initialize(x,y)
render()

ColorTransform's constructor should take x, y, and color parameters. x and y should be passed to the superclass and color should be stored in an instance variable.

NOTE: Override render. Be sure to change the color (unless it is nil) before invoking your superclass.

Text

file: src/main/ruby/render/assignment/text.rb Ruby logo.svg
class: Text
superclass: ColorTransform
methods to evolve: initialize(text, font, x: 0, y: 0, color: nil)
methods to add: render_transformed()
methods to remove: render()

You will evolve your code from from Part A

be sure to add the following line above your class:

require_relative 'color_transform'

Add keyword parameters for x: 0, y: 0, and color: nil to the constructor and pass them to the superclass.

NOTE: Be sure to not override render. Implement the render_transformed method instead.

NOTE: render_transformed() must be private.

Ellipse

file: src/main/ruby/render/assignment/ellipse.rb Ruby logo.svg
class: Ellipse
superclass: ColorTransform
methods to evolve: initialize(x_radius, y_radius, x: 0, y: 0, color: nil)
methods to add: render_transformed()
methods to remove: render()

You will evolve your code from from Part A

be sure to add the following line above your class:

require_relative 'color_transform'

Add keyword parameters for x: 0, y: 0, and color: nil to the constructor and pass them to the superclass.

NOTE: Be sure to not override render. Implement the render_transformed method instead.

NOTE: render_transformed() must be private.

EquilateralTriangle

file: src/main/ruby/render/assignment/equilateral_triangle.rb Ruby logo.svg
class: EquilateralTriangle
superclass: ColorTransform
methods to evolve: initialize(half_side_length, x: 0, y: 0, color: nil)
methods to add: render_transformed()
methods to remove: render()

You will evolve your code from from Part A

be sure to add the following line above your class:

require_relative 'color_transform'

Add keyword parameters for x: 0, y: 0, and color: nil to the constructor and pass them to the superclass.

NOTE: Be sure to not override render. Implement the render_transformed method instead.

NOTE: render_transformed() must be private.

BezierCurve

file: src/main/ruby/render/assignment/bezier_curve.rb Ruby logo.svg
class: BezierCurve
superclass: ColorTransform
methods to evolve: initialize(control_points, x: 0, y: 0, color: nil)
methods to add: render_transformed()
methods to remove: render()

You will evolve your code from from Part A

be sure to add the following line above your class:

require_relative 'color_transform'

Add keyword parameters for x: 0, y: 0, and color: nil to the constructor and pass them to the superclass.

NOTE: Be sure to not override render. Implement the render_transformed method instead.

NOTE: render_transformed() must be private.

Chord

file: src/main/ruby/render/assignment/chord.rb Ruby logo.svg
class: Chord
superclass: ColorTransform
methods to evolve: initialize(x_radius, y_radius, theta_a, theta_z, x: 0, y: 0, color: nil)
methods to add: render_transformed()
methods to remove: render()

You will evolve your code from from Part A

be sure to add the following line above your class:

require_relative 'color_transform'

Add keyword parameters for x: 0, y: 0, and color: nil to the constructor and pass them to the superclass.

NOTE: Be sure to not override render. Implement the render_transformed method instead.

NOTE: render_transformed() must be private.

Rectangle

file: src/main/ruby/render/assignment/rectangle.rb Ruby logo.svg
class: Rectangle
superclass: ColorTransform
methods to evolve: initialize(half_width, half_height, x: 0, y: 0, color: nil)
methods to add: render_transformed()
methods to remove: render()

You will evolve your code from from Part A

be sure to add the following line above your class:

require_relative 'color_transform'

Add keyword parameters for x: 0, y: 0, and color: nil to the constructor and pass them to the superclass.

NOTE: Be sure to not override render. Implement the render_transformed method instead.

NOTE: render_transformed() must be private.

CompositeTransform

file: src/main/ruby/render/assignment/composite_transform.rb Ruby logo.svg
class: CompositeTransform
superclass: Transform
methods: initialize(x: 0, y: 0)
push_component(component)
render_transformed()

Add a push_component method which accepts a component which will later be rendered.

The render_transformed method should render each pushed component.

NOTE: render_transformed() must be private.

class Scene

file: src/main/ruby/render/assignment/scene.rb Ruby logo.svg
class: Scene
superclass: Object
methods: initialize(background_color: Color.new(0,0,0))
push_component(component)
render()

superclass: Object

Scene's constructor should take a keyword parameter background_color: Color.new(0,0,0) and store it in an instance variable.

Add a push_component method which accepts a component which will later be rendered.

The render method should set the clear color before rendering each pushed component.

Testing Your Solution

Visual Comparison

file to run: src/test/ruby/render/part_b/part_b_test_snapshots_web_page_generator.rb Ruby logo.svg

Unit Test

file: src/test/ruby/render/part_b/part_b_unit_test.rb Ruby logo.svg UnitTest

note: ensure that you have removed all printing to receive credit for any assignment.