Graphics Abstractions The main goals of this assignment are to gain experience with the decorator and composite patterns, and to explore testing objects with more complex behaviors. And to get a little more practice with arrays. Before writing code of your own, you will likely want to look over the code that is provided. Most of this you should have seen before, either in the previous problem set or in lecture, but there are a few things that are different: Many methods that work with points and colors now take The This problem set builds on the previous problem set—it depends on the The first part of your task is to implement the In addition to implementing the There are additional details in the Implement the Modify the The There are additional details in the In class, we wrote a static method Now it’s time to write a version of In an implementation of this algorithm, the recursion should stop early in the case where the Use the library we are building to write a program that renders something interesting to the screen. Can you do more interesting things by factoring out some functionality, and perhaps parameterizing it? If you make something especially neat, post a screen shot to Piazza. (There is no deliverable associated with this task.)2 Getting Started
BoundingBox
(Javadoc) is now a class rather than an interface, because a need for other implementations seems unlikely, and a final class makes it easier to preserve invariants. There’s a new constant, EMPTY
, for representing the empty bounding box.Point<Integer>
, Point<Double>
, and Color
objects instead. However, the colors written to Raster
s are still represented as (32-bit) int
s because that’s what must eventually be written to the PixelSurface
.CirclesDemo
class contains some commented-out code that will exercise the code you need to write, once it’s ready. (But this is no substitute for actual testing.)IntegerPoint
, DoublePoint
, and Colors
classes that you implemented. You are free to use your implementations of these classes, but if you prefer to use mine, compiled binary class files are available in pset07.jar
.3 Your Task
3.1
ArrayRaster
Raster
interface with a more efficient representation than the ArrayList<ArrayList<Integer>>
representation that we’ve been using. To this end, you will write a class ArrayRaster
that implements the Raster
interface, while representing the raster as a single row-major int[]
of length width() * height()
.Raster
interface, ArrayRaster
should have two public constructors and one additional method:
public ArrayRaster(int width, int height)
constructs an ArrayRaster
with the given width and height, allocating a buffer of the appropriate size.public ArrayRaster(int width, int height, int[] buffer)
allows the client to supply the buffer for the new ArrayRaster
to use. This is useful if we already have an array that we wish to render into and wish to avoid copying.public int[] getBuffer()
returns the ArrayRaster
’s buffer to the client. Because it does not make a copy, the ArrayRaster
continues to hold a reference to the returned buffer, and changes via one reference will be visible via the other.ArrayRaster
Javadoc, so I recommend that you read it carefully.
ArrayRaster
class, as described above. You may extend the AbstractRaster
class if you wish. Be sure to test your code thoroughly.RasterApplication
class to use your ArrayRaster
rather than ListRaster
.3.2
addTransparency
Sampleable
interface is simple—just two methods—but it gives us a lot of flexibility to compose and transform image elements by defining decorators, which dynamically extend an object with different behavior. We saw some geometric transformations in class, such as the Sampleables.scale(double, Sampleable)
method that scales a Sampleable
. It is also possible to write decorators that modify the colors of the decorated image element. As an example, you will write aSampleable
decorator that makes the decorated Sampleable
more transparent.
Sampleables
, write a public static
method Sampleable addTransparency(double alpha, Sampleable base)
that multiplies the alpha of each point in base
by the provided alpha
. Be sure to test your method.Sampleables.addTransparency
Javadoc that may be helpful.3.3
overlay
Sampleable overlay(Sampleable... layers)
(renamed opaqueOverlay
in the version of Sampleables.java
that I’ve provided you) that composes several Sampleable
s by overlaying them from front to back.2 This method respects full transparency, in the sense that when rendering a pixel in a layer where the alpha is 0, it goes to the layer behind it, and so on, until running out of layers.overlay
that properly handles partial transparency as well. You’ve already written an overlay method for two colors, and we can define the overlay of ColorBlender
class like in lecture. Talk to me if you want to try this.)
Sampleables
, write a public static
method Sampleable overlay(Sampleable... layers)
that overlays the layers front-to-back while respecting each layer’s alpha channel. Be sure to test your method.3.4 Make a Pretty Picture