Render Part B Assignment
In this studio we will evolve our code from Render (Part A) to leverage class hierarchies.
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.
Contents
Code to Implement
Transform
file: | src/main/ruby/render/assignment/transform.rb | ![]() |
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 (a.k.a. invokes a method on 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 | ![]() |
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 | ![]() |
class: | ColorTransform | |
superclass: | Transform | |
methods: | initialize(x,y,color) 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
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
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
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
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.
CircularSegment
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
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 | ![]() |
class: | CompositeTransform | |
superclass: | Transform | |
methods: | initialize(x: 0, y: 0) components push_component(component) render_transformed() |
Add a reader for components.
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.
Scene
Add an accessor (reader and writer) for background_color and a reader for components.
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 and clear the color buffer before rendering each pushed component.
glClearColor(@background_color.red, @background_color.green, @background_color.blue, 1.0) glClear(GL_COLOR_BUFFER_BIT)
Testing Your Solution
Unit Test
file: | src/test/ruby/render/part_b/part_b_test_suite.rb | ![]() |
note: ensure that you have removed all printing to receive credit for any assignment.
Visual Comparison
file to run: | src/test/ruby/render/part_b_snapshots/part_b_snapshots_web_page_generator.rb | ![]() |