Render Part B Assignment

From CSE425S Wiki
Jump to navigation Jump to search

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

superclass: Object

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

You will evolve your code from from Part A

superclass: 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.

ColorTransform

superclass: Transform

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.

Color

To support ColorTransforms you will want to implement Color in color.rb. You may wish to use Ruby's convenient Struct construct.

You should be able to construct a Color with red, green, and blue and be able to access those values.

Text

You will evolve your code from from Part A

superclass: ColorTransform

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.

Ellipse

You will evolve your code from from Part A

superclass: ColorTransform

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.

EquilateralTriangle

You will evolve your code from from Part A

superclass: ColorTransform

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.

BezierCurve

You will evolve your code from from Part A

superclass: ColorTransform

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.

Chord

You will evolve your code from from Part A

superclass: ColorTransform

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.

Rectangle

You will evolve your code from from Part A

superclass: ColorTransform

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.

CompositeTransform

superclass: Transform

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

The private render_transformed method should render each pushed component.

NOTE: you can inherit the constructor without change.

class Scene

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

Unit Testing

ruby/render/part_b_test/part_b_unit_test.rb

Visual Comparison

ruby/render/part_b_test/part_b_test_snapshots_web_page_generator.rb