|
|||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Class Summary | |
---|---|
Circle | A Class representing an Circle Image. |
ColorDatabase | Manages color names and translation to implementation-dependent Color structures. |
Ellipse | Represents an Image of an Ellipse. |
EmptyScene |
Represents the empty (blank) Scene (a cropped Image ). |
FromFile | Represents an Image from a file. |
FromResource | Represents an Image from an Android Project Resource. |
FromURL | Represents an image from a URL. |
Image | An abstract class representing an Image. |
Line | Class representing a Line from (0,0) to the given (X,Y). |
Overlay | Represents the Overlaying of two or more images. |
OverlayXY | Represents the Overlaying of two images with the given offset. |
RasterImage | Represents an raster Image drawn into a Buffer. |
Rectangle | Represents an Image of a Rectangle. |
RegularPolygon | Represents an Image of a Regular Polygon. |
RoundRectangle | Represents an Image of a Rectangle with rounded corners. |
Scene |
An abstract Class representing a Scene (a cropped Image ). |
Square | Represents an Image of a Square. |
Star | Represents an Image of a Star. |
Text | A Class representing an Image of a String. |
Triangle | Represents an Image of a Triangle. |
An image creation package mimics the Racket's 2htdp/image
library. Instead of functions we have specific instances of
Image
subclasses that serve the same purpose(s).
One of the main differences between this library and
2htdp/image
(besides the implementation language)
is that we draw a distinction between normal
Image
s, and Scene
s. The latter being a
special form of image that is cropped to a specific size when
drawn. But the uses will be clearer with a few examples.
The examples presented here were mostly taken from the original 2htdp/image documentation, which, for the most part, can be used as a supplement, though not all the fancy features are supported.
Image mode
Each closed image (e.g.,Circle
, orRegularPolygon
, but notLine
orOverlay
) has an associated modeString
, which is either"outline"
or"solid"
. This refers whether the image is simply drawn as a single stroke (outline), or is filled (solid). If an image is constructed with a mode string other than outline or solid then an appropriateRuntimeException
is thrown.Colors
All basic images have an associated color, also given as aString
. Color names are managed by theColorDatabase
class, which has a comprehensive list of predefined colors. Names are case-insensitive.Custom Colors
Besides the named colors like"blue"
or"goldenrod"
, the color string may also be a custom RGB color (in 6-digit hexidecimal format) by placing a pound/hash character (#
) at the front of the string. For instance, an alternative to"blue"
would be"#0000FF"
, and an alternative to"goldenrod"
would be"#DAA520"
. If transparency is required you may use an 8 digit hexidecimal number where the first component is Alpha and the following 6 characters are RGB, e.g., "#FFFF0000" for Opaque Red, or "#8800FF00" for Half-Transparent Green.
Shapes
Theimage
package contains lots of different basic shapes.new Circle(30, "outline", "red")
new Circle(20, "solid", "blue")
new Ellipse(40, 20, "outline", "black")
new Ellipse(20, 40, "solid", "blue")
new Line(30, 30, "black")
new Line(-30, 20, "red")
new Line(30, -20, "red")
new Text("Hello", 24, "olive")
new Text("Goodbye", 36, "indigo")
new Triangle(40, "solid", "tan")
new Triangle(60, "outline", "purple")
new Square(40, "solid", "slateblue")
new Square(50, "outline", "darkmagenta")
new Rectangle(40, 20, "outline", "black")
new Rectangle(20, 40, "solid", "blue")
new Star(40, 5, "solid", "gray")
new Star(40, 7, "outline", "red")
new Star(40, 30, 10, "solid", "cornflowerblue")
new RegularPolygon(50, 3, "outline", "red")
new RegularPolygon(40, 4, "outline", "blue")
new RegularPolygon(20, 8, "solid", "red")
Image Combinations
new Overlay(new Rectangle(30, 60, "solid", "orange"), new Ellipse(60, 30, "solid", "purple"))
new Overlay(new Ellipse(10, 10, "solid", "red"), new Ellipse(20, 20, "solid", "black"), new Ellipse(30, 30, "solid", "red"), new Ellipse(40, 40, "solid", "black"), new Ellipse(50, 50, "solid", "red"), new Ellipse(60, 60, "solid", "black"))
new Overlay(new RegularPolygon(20, 5, "solid", "#3232FF"), new RegularPolygon(26, 5, "solid", "#6464FF"), new RegularPolygon(32, 5, "solid", "#9696FF"), new RegularPolygon(38, 5, "solid", "#C8C8FF"), new RegularPolygon(44, 5, "solid", "#FAFAFF"))
new OverlayXY(new Rectangle(20, 20, "outline", "black"), 20, 0, new Rectangle(20, 20, "outline", "black"))
new OverlayXY(new Rectangle(20, 20, "solid", "red"), 20, 20, new Rectangle(20, 20, "solid", "black"))
new OverlayXY(new Rectangle(20, 20, "solid", "red"), -20, -20, new Rectangle(20, 20, "solid", "black"))
new OverlayXY( new OverlayXY(new Ellipse(40, 40, "outline", "black"), 10, 15, new Ellipse(10, 10, "solid", "forestgreen")), 20, 15, new Ellipse(10, 10, "solid", "forestgreen"))
Image overlays are also available as methods onImage
s.new Ellipse(60, 30, "solid", "purple") .overlay(new Rectangle(30, 60, "solid", "orange"))
new Ellipse(60, 60, "solid", "black") .overlay(new Ellipse(10, 10, "solid", "red"), new Ellipse(20, 20, "solid", "black"), new Ellipse(30, 30, "solid", "red"), new Ellipse(40, 40, "solid", "black"), new Ellipse(50, 50, "solid", "red"))
new RegularPolygon(44, 5, "solid", "#FAFAFF") .overlay(new RegularPolygon(20, 5, "solid", "#3232FF"), new RegularPolygon(26, 5, "solid", "#6464FF"), new RegularPolygon(32, 5, "solid", "#9696FF"), new RegularPolygon(38, 5, "solid", "#C8C8FF"))
new Rectangle(20, 20, "outline", "black") .overlayxy(new Rectangle(20, 20, "outline", "black"), 20, 0)
new Rectangle(20, 20, "solid", "black") .overlayxy(new Rectangle(20, 20, "solid", "red"), 20, 20)
new Rectangle(20, 20, "solid", "black") .overlayxy(new Rectangle(20, 20, "solid", "red"), -20, -20)
new Ellipse(10, 10, "solid", "forestgreen") .overlayxy(20, 15, new Ellipse(10, 10, "solid", "forestgreen") .overlayxy(10, 15, new Ellipse(40, 40, "outline", "black"))
Transparency/Alpha
new Circle(25, "solid", "#55FF0000") .overlayxy(new Circle(25, "solid", "#5500FF00") .overlayxy(new Circle(25, "solid", "#550000FF"), -30, 0), 15, -15)
new Circle(25, "solid", ColorDatabase.makeColor(0.7, 1.0, 0, 0)) .overlayxy(new Circle(25, "solid", ColorDatabase.makeColor(179, 0, 255, 0)) .overlayxy(new Circle(25, "solid", "#B30000FF"), -30, 0), 15, -15)
Image Rotation and Transformation
new Rectangle(60, 20, "solid", "black").rotate(10)
new Star(20, "outline", "blue").rotate(30)
new Star(20, "solid", "chartreuse").rotate(60)
new Triangle(30, "solid", "tomato").rotate(-30)
new OverlayXY(new Text("Up...", 30, "deepskyblue").rotate(90), 20, 0, new Text("Down", 30, "magenta").rotate(-90))
new Text("Horizontal", 20, "blue").flipHorizontal()
new Text("Vertical", 20, "red").flipVertical()
Scenes
new EmptyScene(160, 90)
new EmptyScene(48, 48).placeImage(new Triangle(32, "solid", "red"), 24, 24)
new EmptyScene(48, 48).placeImage(new Triangle(64, "solid", "red"), 24, 24)
new EmptyScene(48, 48).addLine(0, 0, 48, 48, "blue")
new EmptyScene(48, 48).addLine(4, 24, 44, 24, "green")
new EmptyScene(50, 50) .placeImage(new Overlay(new Circle(20, "outline", "black"), new Circle(20, "solid", "wheat")), 25, 25) .placeImage(new Circle(5, "solid", "lightblue"), 18, 20) .placeImage(new Rectangle(10, 3, "solid", "lightblue"), 33, 20) .placeImage(new Ellipse(20, 8, "solid", "red"), 25, 35)
|
|||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |