final class Pic extends HasAnchor
Each instance of this class represents a picture: an immutable two-dimensional image.
You don’t instantiate Pic directly; instead, you create Pics with the methods on the
Pic companion object. For instance, you can:
- load existing images:
Pic("mypic.png")orPic("http://address.of/mypic.png")), - create
Pics of shapes (e.g.,circle(150, Red)orstar(100, Black)); or - generate the pixels of a
Picwith a function.
Moreover, many of the methods of a Pic object create and return new Pics that
represent combinations or transformations of existing Pics.
This class has an alias in the top-level package o1, so it’s accessible to students
simply via import o1._.
The examples below illustrate a few of the methods (assuming the above import):
val background = rectangle(400, 300, Red) val rotatedSquare = square(50, Blue).clockwise(30) val squareAgainstBg = background.place(rotatedSquare, Pos(100, 100)) squareAgainstBg.show() val ladybug = Pic("ladybug.png").scaleTo(100).flipHorizontal val combination = circle(100, Red).leftOf(ladybug) val part = combination.crop(Pos(10, 10), 180, 80) val negative = part.transformColors( _.negative ) negative.show()
Some of the methods of a Pic that use Pos objects or plain x and y coordinates to
indicate positions within the Pic (e.g., place and crop above). All these methods
consider the origo to be at the top left-hand corner or the Pic, with x values increasing
downwards and y values rightwards. The coordinates are in pixels.
Each image has an anchor that defines where it connects to other Pics. By default,
the anchor is Center; for example, the place method call above puts the center of
the square at Pos(100, 100) within the background.
Here is a of the main types of operations as methods on a Pic, and examples of each type:
- Combining
Pics by positioning them relative to each other:above,below,leftOf,rightOf,onto,against,place. - Rotations (*):
clockwise,counterclockwise - Changing size (*):
scaleBy,scaleTo - Selecting and moving pixels (**):
crop,shift,flipHOrizontal,flipVertical - Examining and manipulating individual pixels (**):
pixelColor,transformXY,transformColors,combine - Convenience methods for experimentation and
debugging:
show,hide.
Notes on implementation and efficiency:
Internally, a Pic stores its contents either as vector-based graphics, as a bitmap (raster),
or as a combination of the two. By design, that internal representation is meant to be largely
opaque to the user of the Pic class: students in O1 working on O1’s standard assignments
generally shouldn’t need to know or care about it. Nevertheless, whether a particular Pic
is stored in vector or bitmap form does have very substantial effect on efficiency in some
contexts; Pic, like the rest of O1Library, is not designed for high-performance graphics.
Some users of this class may wish to know the following:
Pics start out in either vector form or bitmap form, depending on which method created them. Specifically, the shape-creating methods (likerectangleandcircle). producePics in vector form.- No operation on a
Picever changes an already rasterized bitmap into vector graphics. (An operation such asleftOfcan produce anPicthat is stored as a combination of a vector graphic and a bitmap.) - Some operations always produce a rasterized
Pic. These are marked with a double asterisk (**) in the list above. Some operations sometimes produce rasterizedPics but may retain the vector-based representation in simple cases. These are marked with a single asterisk (*). - You can call freeze to force rasterization.
- Alphabetic
- By Inheritance
- Pic
- HasAnchor
- HasSize
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def above(lowerPic: Pic, retainAnchor: Boolean = false): Pic
Combines this
Picand the given one so that thisPicappears immediately above the otherPic.Combines this
Picand the given one so that thisPicappears immediately above the otherPic. The combinedPicwill be large enough to fit both originals.- lowerPic
the
Picthat is below thisPicin the combination- retainAnchor
truemeans that the anchor of the combination should be equally far from the top left-hand corner as thisPic’s anchor is;false(the default) means that the combination should follow the same general anchoring policy has thisPic(e.g., to anchor from its center)- returns
the combined
Pic
- def absoluteAnchor: Anchor
An Anchor.Absolute that points to the same spot in the
Picthat thePic’s current anchor does.An Anchor.Absolute that points to the same spot in the
Picthat thePic’s current anchor does.- Annotations
- @inline()
- def against(background: Pic, atIts: Anchor = Center): Pic
Combines this
Picand the given one so that the otherPicserves as a background and thisPicappears in front of it but not beyond its borders.Combines this
Picand the given one so that the otherPicserves as a background and thisPicappears in front of it but not beyond its borders. The visible part of the combinedPicis the size of the backgroundPic. In the combination, some or even none of thisPicis visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of thisPicthat don’t fit against the background are left out. (The left-out parts are still part of thePic’s data but not visible; only the part within the framing background image will be shown when thePicis rendered onscreen.) This version ofagainstanchors thisPicat its default anchor to an anchor in the background.- background
a
Picthat serves as a background for this one and determines the size of the visible part of the resulting image- atIts
the point within
backgroundthat thisPic’s anchor is positioned at- returns
the combined
Pic
- def against(background: Pic, my: Anchor, atIts: Anchor): Pic
Combines this
Picand the given one so that the otherPicserves as a background and thisPicappears in front of it but not beyond its borders.Combines this
Picand the given one so that the otherPicserves as a background and thisPicappears in front of it but not beyond its borders. The visible part of the combinedPicis the size of the backgroundPic. In the combination, some or even none of thisPicis visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of thisPicthat don’t fit against the background are left out. (The left-out parts are still part of thePic’s data but not visible; only the part within the framing background image will be shown when thePicis rendered onscreen.) This version ofagainstuses the given Anchors instead of the defaultanchorof either of the originalPics.- background
a
Picthat serves as a background for this one and determines the size of the visible part of the resulting image- my
the point within this
Picthat will be placed at the given coordinates- atIts
the point within
backgroundthat thisPicis positioned at- returns
the combined
Pic
- def against(background: Pic, my: Anchor, at: world.Pos): Pic
Combines this
Picand the given one so that the otherPicserves as a background and thisPicappears in front of it but not beyond its borders.Combines this
Picand the given one so that the otherPicserves as a background and thisPicappears in front of it but not beyond its borders. The visible part of the combinedPicis the size of the backgroundPic. In the combination, some or even none of thisPicis visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of thisPicthat don’t fit against the background are left out. (The left-out parts are still part of thePic’s data but not visible; only the part within the framing background image will be shown when thePicis rendered onscreen.) This version ofagainstuses the given Anchor instead of thisPics defaultanchorand places it at a specific Pos in the background.- background
a
Picthat serves as a background for this one and determines the size of the visible part of the resulting image- my
the point within this
Picthat will be placed at the given coordinates- at
the point within
backgroundthat thisPicis positioned at- returns
the combined
Pic
- def against(background: Pic, at: world.Pos): Pic
Combines this
Picand the given one so that the otherPicserves as a background and thisPicappears in front of it but not beyond its borders.Combines this
Picand the given one so that the otherPicserves as a background and thisPicappears in front of it but not beyond its borders. The visible part of the combinedPicis the size of the backgroundPic. In the combination, some or even none of thisPicis visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of thisPicthat don’t fit against the background are left out. (The left-out parts are still part of thePic’s data but not visible; only the part within the framing background image will be shown when thePicis rendered onscreen.) This version ofagainstanchors thisPicat its default anchor to a specific Pos in the background.- background
a
Picthat serves as a background for this one and determines the size of the visible part of the resulting image- at
the point within
backgroundthat thisPic’s anchor is positioned at- returns
the combined
Pic
- def alternatingColumn(another: Pic, number: Int): Pic
Combines copies of this
Picand anotherPicso that they alternate in a vertical column (starting with thisPic).Combines copies of this
Picand anotherPicso that they alternate in a vertical column (starting with thisPic). The combinedPicwill be large enough to fit all the copies.- number
the total number of
Pic\s in the column (e.g., 6 means the result has three copies of eachPic)
- Annotations
- @inline()
- See also
- def alternatingRow(another: Pic, number: Int): Pic
Combines copies of this
Picand anotherPicso that they alternate in a horizontal row (starting with thisPic).Combines copies of this
Picand anotherPicso that they alternate in a horizontal row (starting with thisPic). The combinedPicwill be large enough to fit all the copies.- number
the total number of
Pic\s in the row (e.g., 6 means the result has three copies of eachPic)
- Annotations
- @inline()
- See also
- val anchor: Anchor
the object’s anchoring point
- def anchorAt(anchor: Anchor): Pic
Anchors the
Picat the given position.Anchors the
Picat the given position.- anchor
a new anchoring position
- returns
a new
Picthat’s identical to the original but anchored at the given position
- Annotations
- @inline()
- def apply(pixelPos: world.Pos): Color
Returns the color of the pixel at the given coordinates within the image.
Returns the color of the pixel at the given coordinates within the image. (This is equivalent to calling
pixelColor.)N.B. This is inefficient on a
Picthat’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePicfirst.- Annotations
- @inline()
- def apply(pixelX: Int, pixelY: Int): Color
Returns the color of the pixel at the given coordinates within the image.
Returns the color of the pixel at the given coordinates within the image. (This is equivalent to calling
pixelColor.)N.B. This is inefficient on a
Picthat’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePicfirst.- Annotations
- @inline()
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def below(abovePic: Pic, retainAnchor: Boolean = false): Pic
Combines this
Picand the given one so that thisPicappears immediately below the otherPic.Combines this
Picand the given one so that thisPicappears immediately below the otherPic. The combinedPicwill be large enough to fit both originals.- abovePic
the
Picthat is above thisPicin the combination- retainAnchor
truemeans that the anchor of the combination should be equally far from the top left-hand corner as thisPic’s anchor is;false(the default) means that the combination should follow the same general anchoring policy has thisPic(e.g., to anchor from its center)- returns
the combined
Pic
- def centerFromTopLeft: world.Pos
the location of this object’s center: the average point between its edges, expressed in coordinates relative to the object’s top left-hand corner
the location of this object’s center: the average point between its edges, expressed in coordinates relative to the object’s top left-hand corner
- Definition Classes
- HasSize
- def clockwise(degrees: Double = 90.0): Pic
Creates version of this
Picthat’s rotated clockwise around its center.Creates version of this
Picthat’s rotated clockwise around its center. The resulting image is sized so that the entire contents of the originalPicare visible; any empty space in the corners is Transparent.- degrees
the amount of clockwise rotation, in degrees
- returns
a new
Picthat is a rotated version of this one; it will usually be a bitmap, but some simple vector-basedPics may retain their vector form
- Annotations
- @inline()
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def columnOf(number: Int): Pic
Combines copies of this
Picso that they appear in a vertical column.Combines copies of this
Picso that they appear in a vertical column. The combinedPicwill be large enough to fit all the copies.- number
the number of copies in the column (e.g., 3 means the result has three identical images)
- Annotations
- @inline()
- See also
- def combine(another: Pic, determinePixel: (Color, Color) => Color): Pic
Creates a new
Picby combining thisPicwith the given one on a pixel-by-pixel basis.Creates a new
Picby combining thisPicwith the given one on a pixel-by-pixel basis. For each pair of pixel coordinates in the two originalPics,combinecalls the given function to compute the color of the corresponding pixel in the newPic. The newPic’s width equals the lesser of the two originals’ widths; the same goes for height.- determinePixel
a function generates a pixel for the combination, given two pixel colors from the same location in the originals
- returns
the new (bitmap) image obtained by calling
determinePixeland putting together the outputs
- Annotations
- @inline()
- def contains(pixel: world.Pos): Boolean
Determines if the given Pos is within this
Pic’s borders.Determines if the given Pos is within this
Pic’s borders. For that to be the case, thePosobject’sxneeds to be between zero (inclusive) and thisPic’swidth(exclusive) and itsyneeds to be betewen zero (inclusive) and thisPic’sheight(exclusive). - def counterclockwise(degrees: Double = 90.0): Pic
Creates version of this
Picthat’s rotated counterclockwise around its center.Creates version of this
Picthat’s rotated counterclockwise around its center. The resulting image is sized so that the entire contents of the originalPicare visible; any empty space in the corners is Transparent.- degrees
the amount of counterclockwise rotation, in degrees
- returns
a new
Picthat is a rotated version of this one; it will usually be a bitmap, but some simple vector-basedPics may retain their vector form
- Annotations
- @inline()
- def crop(x: Double, y: Double, width: Double, height: Double): Pic
Returns a partial
Picof a rectangular area within thisPic.Returns a partial
Picof a rectangular area within thisPic.- x
the x coordinate of left edge of the cropping frame within this
Pic- y
the y coordinate of top edge of the cropping frame within this
Pic- width
the width of the cropping frame
- height
the height of the cropping frame
- returns
a new
Pic(a bitmap) that contains a part of the original
- Annotations
- @inline()
- def crop(topLeft: world.Pos, width: Double, height: Double): Pic
Returns a partial
Picof a rectangular area within thisPic.Returns a partial
Picof a rectangular area within thisPic.- topLeft
the top-left corner of the cropping frame within this
Pic- width
the width of the cropping frame
- height
the height of the cropping frame
- returns
a new
Pic(a bitmap) that contains a part of the original
- Annotations
- @inline()
- def crop(topLeft: world.Pos, bottomRight: world.Pos): Pic
Returns a partial
Picof a rectangular area within thisPic.Returns a partial
Picof a rectangular area within thisPic.- topLeft
the top-left corner of the cropping frame within this
Pic- bottomRight
the bottom-right corner of the cropping frame within this
Pic- returns
a new
Pic(a bitmap) that contains a part of the original
- Annotations
- @inline()
- def crop(boundary: world.Bounds): Pic
Returns a partial
Picof a rectangular area within thisPic.Returns a partial
Picof a rectangular area within thisPic.- boundary
the cropping frame within this
Pic- returns
a new
Pic(a bitmap) that contains a part of the original
- Annotations
- @inline()
- lazy val dimensions: (Double, Double)
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def flipDiagonal: Pic
Creates mirrored version of this
Pic: what’s in each corner of the original is in the opposite corner of the resultingPic.Creates mirrored version of this
Pic: what’s in each corner of the original is in the opposite corner of the resultingPic.- returns
a new
Pic(a bitmap) that is a flipped version of this one
- Annotations
- @inline()
- def flipHorizontal: Pic
Creates mirrored version of this
Pic: what’s on the left in the original is on the right in the resultingPicand vice versa.Creates mirrored version of this
Pic: what’s on the left in the original is on the right in the resultingPicand vice versa.- returns
a new
Pic(a bitmap) that is a flipped version of this one
- Annotations
- @inline()
- def flipVertical: Pic
Creates mirrored version of this
Pic: what’s at the top in the original is at the bottom in the resultingPicand vice versa.Creates mirrored version of this
Pic: what’s at the top in the original is at the bottom in the resultingPicand vice versa.- returns
a new
Pic(a bitmap) that is a flipped version of this one
- Annotations
- @inline()
- def freeze: Pic
Forces rasterization of any vector graphics in this
Pics internal representation into bitmap form.Forces rasterization of any vector graphics in this
Pics internal representation into bitmap form. See the introduction to this class for more information.- returns
the same picture, stored entirely in bitmap form
- Annotations
- @inline()
- See also
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- lazy val height: Double
The height of the
Picin pixels. - def hide(): Unit
Hides the window that has been created (with show) to display the
Pic. - lazy val history: List[String]
A list of method names used for creating this
Pic.A list of method names used for creating this
Pic. Only the most recently applied methods are listed (up to historyLength. This method may be useful for demonstrative purposes, debugging, and/or automatic assessment. - val historyLength: Int
A limit on the number of historical method calls that are tracked by the
Picand available through history.A limit on the number of historical method calls that are tracked by the
Picand available through history. Defaults to 10. Can be changed via withHistoryLength. - def internalAnchorPos: world.Pos
Returns the Pos of the anchoring point within this object, expressed as coordinates relative to the object’s top left-hand corner.
- def internalAnchorX: Double
Returns the x coordinate of the anchoring point within this object, relative to the object’s left edge.
Returns the x coordinate of the anchoring point within this object, relative to the object’s left edge.
- Definition Classes
- HasAnchor
- def internalAnchorY: Double
Returns the y coordinate of the anchoring point within this object, relative to the object’s top edge.
Returns the y coordinate of the anchoring point within this object, relative to the object’s top edge.
- Definition Classes
- HasAnchor
- def isBitmap: Boolean
Indicates whether this
Picis internally stored as a bitmap raster.Indicates whether this
Picis internally stored as a bitmap raster. See the introduction to this class for more information.- returns
trueif the entirePicis rasterized as a bitmap;falseif thePic’s internal representation uses any vector graphics
- Annotations
- @inline()
- See also
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def leftOf(rightPic: Pic, retainAnchor: Boolean = false): Pic
Combines this
Picand the given one so that thisPicappears immediately to the left the otherPic.Combines this
Picand the given one so that thisPicappears immediately to the left the otherPic. The combinedPicwill be large enough to fit both originals.- rightPic
the
Picthat is to the right of thisPicin the combination- retainAnchor
truemeans that the anchor of the combination should be equally far from the top left-hand corner as thisPic’s anchor is;false(the default) means that the combination should follow the same general anchoring policy has thisPic(e.g., to anchor from its center)- returns
the combined
Pic
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def onto(backPic: Pic, my: Anchor, at: world.Pos): Pic
Combines this
Picand the given one so that thisPicappears in front of the otherPicat specific coordinates.Combines this
Picand the given one so that thisPicappears in front of the otherPicat specific coordinates. The combinedPicwill be larger than either of the two originals unless thisPicfits completely in front of the other one. This version ofontouses the given Anchor instead of thisPics defaultanchor.- backPic
the
Picthat is behind this one in the combination- my
the point within this
Picthat will be placed at the given coordinates- at
the point within
backPicthat thisPicis positioned at- returns
the combined
Pic
- Annotations
- @inline()
- See also
against, which does the same but leaves out any “hanging” parts of the foreground image
- def onto(backPic: Pic, at: world.Pos): Pic
Combines this
Picand the given one so that thisPicappears in front of the otherPicat specific coordinates.Combines this
Picand the given one so that thisPicappears in front of the otherPicat specific coordinates. The combinedPicwill be larger than either of the two originals unless thisPicfits completely in front of the other one. This version ofontoanchors thisPicat its default anchor.- backPic
the
Picthat is behind this one in the combination- at
the point within
backPicthat thisPic’s anchor is positioned at- returns
the combined
Pic
- Annotations
- @inline()
- See also
against, which does the same but leaves out any “hanging” parts of the foreground image
- def onto(backPic: Pic, atIts: Anchor = Center): Pic
Combines this
Picand the given one so that thisPicappears in front of the otherPic.Combines this
Picand the given one so that thisPicappears in front of the otherPic. The combinedPicwill be larger than either of the two originals unless thisPicfits completely in front of the other one. This version ofontoanchors thisPicfrom its default anchor to an anchor in the other image.- backPic
the
Picthat is behind this one in the combination- atIts
the point within
backPicthat thisPic’s anchor is positioned at- returns
the combined
Pic
- Annotations
- @inline()
- See also
against, which does the same but leaves out any “hanging” parts of the foreground image
- def onto(backPic: Pic, my: Anchor, atIts: Anchor): Pic
Combines this
Picand the given one so that thisPicappears in front of the otherPic.Combines this
Picand the given one so that thisPicappears in front of the otherPic. The combinedPicwill be larger than either of the two originals unless thisPicfits completely in front of the other one. This version ofontouses the given Anchors instead of the defaultanchorof either of the originalPics.- backPic
the
Picthat is behind this one in the combination- my
the point within this
Picthat will be placed atatIts- atIts
the point within
backPicthat thisPicis positioned at- returns
the combined
Pic
- Annotations
- @inline()
- See also
against, which does the same but leaves out any “hanging” parts of the foreground image
- def pixelColor(x: Double, y: Double): Color
Returns the color of the pixel at the given coordinates within the image.
Returns the color of the pixel at the given coordinates within the image.
N.B. This is inefficient on a
Picthat’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePicfirst.- Annotations
- @inline()
- def pixelColor(x: Int, y: Int): Color
Returns the color of the pixel at the given position within the image.
Returns the color of the pixel at the given position within the image.
N.B. This is inefficient on a
Picthat’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePicfirst.- Annotations
- @inline()
- def pixelColor(pos: world.Pos): Color
Returns the color of the pixel at the given position within the image.
Returns the color of the pixel at the given position within the image.
N.B. This is inefficient on a
Picthat’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePicfirst.- Annotations
- @inline()
- def pixelsNear(pos: world.Pos, range: Double): Seq[Color]
Returns the colors of the pixels in this
Picthat are “near” a given Pos.Returns the colors of the pixels in this
Picthat are “near” a given Pos. A pixel counts as being near if it’s located at aPoswhose distance from the givenPosis less than or equal to the givenrange. This includes the pixel at the givenPos(if there is one).- pos
a position whose nearby pixels in this
Picwill be returned- range
the maximum distance of a returned pixel from
pos(must be non-negative)- returns
a collection of the pixel colors, in arbitrary order
- def place(foregroundPics: (Pic, world.Pos)*): Pic
Combines this
Picand the given ones so that thisPicserves as a background and the otherPics appear in front but not beyond thisPic’s borders.Combines this
Picand the given ones so that thisPicserves as a background and the otherPics appear in front but not beyond thisPic’s borders. The visible part of the combinedPicis the size of this backgroundPic. This is equivalent to calling place(Pic,Pos) repeatedly.- foregroundPics
tuples containing: the
Pics that will be placed against this background and the points within thisPicwhere their default anchors will be placed- returns
the combined
Pic
- Annotations
- @inline()
- def place(foregroundPics: Iterable[(Pic, world.Pos)]): Pic
Combines this
Picand the given ones so that thisPicserves as a background and the otherPics appear in front but not beyond thisPic’s borders.Combines this
Picand the given ones so that thisPicserves as a background and the otherPics appear in front but not beyond thisPic’s borders. The visible part of the combinedPicis the size of this backgroundPic. This is equivalent to calling place(Pic,Pos) repeatedly.- foregroundPics
tuples containing: the
Pics that will be placed against this background and the points within thisPicwhere their default anchors will be placed- returns
the combined
Pic
- Annotations
- @inline()
- def place(foregroundPicAndPos: (Pic, world.Pos)): Pic
Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders.Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders. The visible part of the combinedPicis the size of this backgroundPic. Some or even none of the otherPicis visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPicthat don’t fit against this background are left out. (The left-out parts are still part of thisPic’s data but not visible; only the part within this framing background image will be shown when thePicis rendered onscreen.) This version ofplaceanchors the otherPicat its default anchor to a specific Pos in this background.- foregroundPicAndPos
a tuple containing: the
Picthat will be placed against this background and the point within thisPicthatforeground’s anchor will be placed at- returns
the combined
Pic
- Annotations
- @inline()
- See also
place, which does the same but without the tuple
- def place(foreground: Pic, atMy: Anchor): Pic
Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders.Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders. The visible part of the combinedPicis the size of this backgroundPic. Some or even none of the otherPicis visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPicthat don’t fit against this background are left out. (The left-out parts are still part of thisPic’s data but not visible; only the part within this framing background image will be shown when thePicis rendered onscreen.) This version ofplaceanchors the otherPicat its default anchor to a specified anchor in this background.- foreground
the Pic
that will be placed against this background- atMy
the point within this
Picthatforeground’s anchor will be placed at- returns
the combined
Pic
- Annotations
- @inline()
- See also
place, which does the same but switches the order of the two
Pics
- def place(foreground: Pic, at: world.Pos): Pic
Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders.Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders. The visible part of the combinedPicis the size of this backgroundPic. Some or even none of the otherPicis visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPicthat don’t fit against this background are left out. (The left-out parts are still part of thisPic’s data but not visible; only the part within this framing background image will be shown when thePicis rendered onscreen.) This version ofplaceanchors the otherPicat its default anchor to a specific Pos in this background.- foreground
the
Picthat will be placed against this background- at
the point within this
Picthatforeground’s anchor will be placed at- returns
the combined
Pic
- Annotations
- @inline()
- See also
place, which does the same but switches the order of the two
Pics
- def place(foreground: Pic, its: Anchor, atMy: Anchor): Pic
Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders.Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders. The visible part of the combinedPicis the size of this backgroundPic. Some or even none of the otherPicis visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPicthat don’t fit against this background are left out. (The left-out parts are still part of thisPic’s data but not visible; only the part within this framing background image will be shown when thePicis rendered onscreen.) This version ofplaceuses the given Anchors instead of the defaultanchorof either of the originalPics.- foreground
the
Picthat will be placed against this background- its
the point within
foregroundthat will be placed at the given coordinates- atMy
the point within this
Picthatforegroundwill be placed at- returns
the combined
Pic
- Annotations
- @inline()
- See also
place, which does the same but switches the order of the two
Pics
- def place(foreground: Pic, its: Anchor, at: world.Pos): Pic
Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders.Combines this
Picand the given one so that thisPicserves as a background and the otherPicappears in front but not beyond thisPic’s borders. The visible part of the combinedPicis the size of this backgroundPic. Some or even none of the otherPicis visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPicthat don’t fit against this background are left out. (The left-out parts are still part of thisPic’s data but not visible; only the part within this framing background image will be shown when thePicis rendered onscreen.) This version ofplaceuses the given Anchor instead of the otherPics defaultanchorand places it at a specific Pos in this background.- foreground
the
Picthat will be placed against this background- its
the point within
foregroundthat will be placed at the given coordinates- at
the point within this
Picthatforegroundwill be placed at- returns
the combined
Pic
- Annotations
- @inline()
- See also
place which does the same but switches the order of the two
Pics
- def placeCopies(foregroundPic: Pic, at: Iterable[world.Pos]): Pic
Combines this
Picand copies of the given one so that thisPicserves as a background and the copies of the otherPics appear in front but not beyond thisPic’s borders.Combines this
Picand copies of the given one so that thisPicserves as a background and the copies of the otherPics appear in front but not beyond thisPic’s borders. The visible part of the combinedPicis the size of this backgroundPic. This is equivalent calling place(Pic,Pos) repeatedly, passing in the same foreground image each time.- foregroundPic
the
Pics whose copies will be placed against this background- at
the points within this
Picwhere the default anchors of the copies should be placed- returns
the combined
Pic
- Annotations
- @inline()
- def rightOf(leftPic: Pic, retainAnchor: Boolean = false): Pic
Combines this
Picand the given one so that thisPicappears immediately to the right the otherPic.Combines this
Picand the given one so that thisPicappears immediately to the right the otherPic. The combinedPicwill be large enough to fit both originals.- leftPic
the
Picthat is to the left of thisPicin the combination- retainAnchor
truemeans that the anchor of the combination should be equally far from the top left-hand corner as thisPic’s anchor is;false(the default) means that the combination should follow the same general anchoring policy has thisPic(e.g., to anchor from its center)- returns
the combined
Pic
- def rowOf(number: Int): Pic
Combines copies of this
Picso that they appear in a horizontal row.Combines copies of this
Picso that they appear in a horizontal row. The combinedPicwill be large enough to fit all the copies.- number
the number of copies in the row (e.g., 3 means the result has three identical images)
- Annotations
- @inline()
- See also
- def save(path: String): Boolean
Saves the
Picin the given file in PNG format.Saves the
Picin the given file in PNG format.- path
an absolute local path or a path relative to the working directory
- returns
trueif the saving was successful andfalseif no file was created because there was no bitmap to save
- Annotations
- @inline()
- def scaleBy(factor: Double): Pic
Creates a version of this
Picthat is larger or smaller as per the given multiplier.Creates a version of this
Picthat is larger or smaller as per the given multiplier. A value between 0 and 1 produces a smallerPic, a value above 1 a larger one. Retains the aspect ratio of the original image.- factor
the ratio between the sizes of the result and the original
- returns
a new
Picthat is a scaled version of this one; it will usually be a bitmap, but some simple vector-basedPics may retain their vector form
- Annotations
- @inline()
- def scaleTo(sizingPic: Pic): Pic
Creates a scaled version of this
Picthat has the dimensions of the givenPic.Creates a scaled version of this
Picthat has the dimensions of the givenPic. The aspect ratio of the resulting image may be different from the original’s.- sizingPic
a
Picwhose width and height are given to the scaledPic- returns
a new
Picthat is a scaled version of this one; it will usually be a bitmap, but some simple vector-basedPics may retain their vector form
- Annotations
- @inline()
- def scaleTo(targetSize: Double): Pic
Creates a scaled version of this
Picthat has the given size and is rectangular.Creates a scaled version of this
Picthat has the given size and is rectangular. If the originalPicisn’t rectangular, the aspect ratio of the result will be different.- targetSize
the width and height of the output image
- returns
a new
Picthat is a scaled version of this one; it will usually be a bitmap, but some simple vector-basedPics may retain their vector form
- Annotations
- @inline()
- def scaleTo(targetWidth: Double, targetHeight: Double): Pic
Creates a scaled version of this
Picthat has the given dimensions.Creates a scaled version of this
Picthat has the given dimensions. The aspect ratio of the resulting image may be different from the original’s.- targetWidth
the width of the output image
- targetHeight
the height of the output image
- returns
a new
Picthat is a scaled version of this one; it will usually be a bitmap, but some simple vector-basedPics may retain their vector form
- Annotations
- @inline()
- def shiftDown(offset: Double): Pic
Shifts each pixel within the
Picdownwards by the given amount.Shifts each pixel within the
Picdownwards by the given amount. Retains the size of the image: any pixels that would go beyond the bottom edge of thePicinstead wrap around to the top.- offset
the number of pixels the image shifts down
- returns
a new
Pic(a bitmap) that contains a shifted version of the original
- Annotations
- @inline()
- def shiftLeft(offset: Double): Pic
Shifts each pixel within the
Picto the left by the given amount.Shifts each pixel within the
Picto the left by the given amount. Retains the size of the image: any pixels that would go beyond the left edge of thePicinstead wrap around to the right-hand side.- offset
the number of pixels the image shifts to the left
- returns
a new
Pic(a bitmap) that contains a shifted version of the original
- Annotations
- @inline()
- def shiftRight(offset: Double): Pic
Shifts each pixel within the
Picto the right by the given amount.Shifts each pixel within the
Picto the right by the given amount. Retains the size of the image: any pixels that would go beyond the right edge of thePicinstead wrap around to the left-hand side.- offset
the number of pixels the image shifts to the right
- returns
a new
Pic(a bitmap) that contains a shifted version of the original
- Annotations
- @inline()
- def shiftUp(offset: Double): Pic
Shifts each pixel within the
Picupwards by the given amount.Shifts each pixel within the
Picupwards by the given amount. Retains the size of the image: any pixels that would go beyond the top edge of thePicinstead wrap around to the bottom.- offset
the number of pixels the image shifts up
- returns
a new
Pic(a bitmap) that contains a shifted version of the original
- Annotations
- @inline()
- def show(background: Color = colors.White, border: Int = 1): Unit
Displays this
Picin a minimalistic GUI window.Displays this
Picin a minimalistic GUI window. Calling this method repeatedly on the samePicdoesn’t display multiple windows but reuses the existing one. This method is meant only for experimentation and debugging; not for GUI construction (cf. views).Students may alternatively use the
show(pic)variant in the top-level package o1.- background
the color to appear behind the
Picin the frame (where thePicis transparent)- border
the width of the simple black window frame, in pixels
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- lazy val toIcon: Option[Icon]
This
Picconverted to a SwingIcon). - lazy val toImage: Option[BufferedImage]
This
Picconverted to a Java AWTBufferedImage(for use in Swing GUIs). - def toString: String
Returns a very simple string description of this
Pic.Returns a very simple string description of this
Pic. Examples:"ladybug.png"circle-shape"ladybug.png" (transformed)circle-shape (transformed)combined pic
- Definition Classes
- Pic → AnyRef → Any
- Annotations
- @inline()
- def transformColors(transformer: (Color) => Color): Pic
Applies the given operation to each pixel in the
Picto generate a differentPic.Applies the given operation to each pixel in the
Picto generate a differentPic. That is, every color in the image will be replaced by another color in the generated image, as specified by the given function.- transformer
a function that
transformColorscalls on every pixel in the image to map its color to a new one- returns
the new (bitmap) image obtained by calling
transformerand putting together the outputs
- Annotations
- @inline()
- def transformXY(newColorAt: (Int, Int) => Color): Pic
Applies the given operation to each position in the
Picto generate a differentPic.Applies the given operation to each position in the
Picto generate a differentPic.- newColorAt
a function that
transformXYcalls repeatedly to determine the pixels of the transformedPic- returns
the new (bitmap) image obtained by calling
newColorAtand putting together the outputs
- Annotations
- @inline()
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- lazy val width: Double
The width of the
Picin pixels. - def withHistoryLength(maxLength: Int): Pic
Sets a new limit to the history length on the
Pic.Sets a new limit to the history length on the
Pic.- maxLength
a new historyLength (>= 0)
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
- Deprecated
(Since version ) see corresponding Javadoc for more information.