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 Pic
s 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
Pic
s of shapes (e.g.,circle(150, Red)
orstar(100, Black)
); or - generate the pixels of a
Pic
with a function.
Moreover, many of the methods of a Pic
object create and return new Pic
s that
represent combinations or transformations of existing Pic
s.
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 Pic
s. 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
Pic
s 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:
Pic
s start out in either vector form or bitmap form, depending on which method created them. Specifically, the shape-creating methods (likerectangle
andcircle
). producePic
s in vector form.- No operation on a
Pic
ever changes an already rasterized bitmap into vector graphics. (An operation such asleftOf
can produce anPic
that 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 rasterizedPic
s 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
Pic
and the given one so that thisPic
appears immediately above the otherPic
.Combines this
Pic
and the given one so that thisPic
appears immediately above the otherPic
. The combinedPic
will be large enough to fit both originals.- lowerPic
the
Pic
that is below thisPic
in the combination- retainAnchor
true
means 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
Pic
that thePic
’s current anchor does.An Anchor.Absolute that points to the same spot in the
Pic
that thePic
’s current anchor does.- Annotations
- @inline()
- def against(background: Pic, atIts: Anchor = Center): Pic
Combines this
Pic
and the given one so that the otherPic
serves as a background and thisPic
appears in front of it but not beyond its borders.Combines this
Pic
and the given one so that the otherPic
serves as a background and thisPic
appears in front of it but not beyond its borders. The visible part of the combinedPic
is the size of the backgroundPic
. In the combination, some or even none of thisPic
is visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of thisPic
that 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 thePic
is rendered onscreen.) This version ofagainst
anchors thisPic
at its default anchor to an anchor in the background.- background
a
Pic
that serves as a background for this one and determines the size of the visible part of the resulting image- atIts
the point within
background
that thisPic
’s anchor is positioned at- returns
the combined
Pic
- def against(background: Pic, my: Anchor, atIts: Anchor): Pic
Combines this
Pic
and the given one so that the otherPic
serves as a background and thisPic
appears in front of it but not beyond its borders.Combines this
Pic
and the given one so that the otherPic
serves as a background and thisPic
appears in front of it but not beyond its borders. The visible part of the combinedPic
is the size of the backgroundPic
. In the combination, some or even none of thisPic
is visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of thisPic
that 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 thePic
is rendered onscreen.) This version ofagainst
uses the given Anchors instead of the defaultanchor
of either of the originalPic
s.- background
a
Pic
that serves as a background for this one and determines the size of the visible part of the resulting image- my
the point within this
Pic
that will be placed at the given coordinates- atIts
the point within
background
that thisPic
is positioned at- returns
the combined
Pic
- def against(background: Pic, my: Anchor, at: world.Pos): Pic
Combines this
Pic
and the given one so that the otherPic
serves as a background and thisPic
appears in front of it but not beyond its borders.Combines this
Pic
and the given one so that the otherPic
serves as a background and thisPic
appears in front of it but not beyond its borders. The visible part of the combinedPic
is the size of the backgroundPic
. In the combination, some or even none of thisPic
is visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of thisPic
that 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 thePic
is rendered onscreen.) This version ofagainst
uses the given Anchor instead of thisPic
s defaultanchor
and places it at a specific Pos in the background.- background
a
Pic
that serves as a background for this one and determines the size of the visible part of the resulting image- my
the point within this
Pic
that will be placed at the given coordinates- at
the point within
background
that thisPic
is positioned at- returns
the combined
Pic
- def against(background: Pic, at: world.Pos): Pic
Combines this
Pic
and the given one so that the otherPic
serves as a background and thisPic
appears in front of it but not beyond its borders.Combines this
Pic
and the given one so that the otherPic
serves as a background and thisPic
appears in front of it but not beyond its borders. The visible part of the combinedPic
is the size of the backgroundPic
. In the combination, some or even none of thisPic
is visible in front of the background, depending on the relative positioning and dimensions of the two images; any parts of thisPic
that 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 thePic
is rendered onscreen.) This version ofagainst
anchors thisPic
at its default anchor to a specific Pos in the background.- background
a
Pic
that serves as a background for this one and determines the size of the visible part of the resulting image- at
the point within
background
that thisPic
’s anchor is positioned at- returns
the combined
Pic
- def alternatingColumn(another: Pic, number: Int): Pic
Combines copies of this
Pic
and anotherPic
so that they alternate in a vertical column (starting with thisPic
).Combines copies of this
Pic
and anotherPic
so that they alternate in a vertical column (starting with thisPic
). The combinedPic
will 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
Pic
and anotherPic
so that they alternate in a horizontal row (starting with thisPic
).Combines copies of this
Pic
and anotherPic
so that they alternate in a horizontal row (starting with thisPic
). The combinedPic
will 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
Pic
at the given position.Anchors the
Pic
at the given position.- anchor
a new anchoring position
- returns
a new
Pic
that’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
Pic
that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePic
first.- 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
Pic
that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePic
first.- Annotations
- @inline()
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def below(abovePic: Pic, retainAnchor: Boolean = false): Pic
Combines this
Pic
and the given one so that thisPic
appears immediately below the otherPic
.Combines this
Pic
and the given one so that thisPic
appears immediately below the otherPic
. The combinedPic
will be large enough to fit both originals.- abovePic
the
Pic
that is above thisPic
in the combination- retainAnchor
true
means 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
Pic
that’s rotated clockwise around its center.Creates version of this
Pic
that’s rotated clockwise around its center. The resulting image is sized so that the entire contents of the originalPic
are visible; any empty space in the corners is Transparent.- degrees
the amount of clockwise rotation, in degrees
- returns
a new
Pic
that is a rotated version of this one; it will usually be a bitmap, but some simple vector-basedPic
s 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
Pic
so that they appear in a vertical column.Combines copies of this
Pic
so that they appear in a vertical column. The combinedPic
will 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
Pic
by combining thisPic
with the given one on a pixel-by-pixel basis.Creates a new
Pic
by combining thisPic
with the given one on a pixel-by-pixel basis. For each pair of pixel coordinates in the two originalPic
s,combine
calls 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
determinePixel
and 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, thePos
object’sx
needs to be between zero (inclusive) and thisPic
’swidth
(exclusive) and itsy
needs to be betewen zero (inclusive) and thisPic
’sheight
(exclusive). - def counterclockwise(degrees: Double = 90.0): Pic
Creates version of this
Pic
that’s rotated counterclockwise around its center.Creates version of this
Pic
that’s rotated counterclockwise around its center. The resulting image is sized so that the entire contents of the originalPic
are visible; any empty space in the corners is Transparent.- degrees
the amount of counterclockwise rotation, in degrees
- returns
a new
Pic
that is a rotated version of this one; it will usually be a bitmap, but some simple vector-basedPic
s may retain their vector form
- Annotations
- @inline()
- def crop(x: Double, y: Double, width: Double, height: Double): Pic
Returns a partial
Pic
of a rectangular area within thisPic
.Returns a partial
Pic
of 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
Pic
of a rectangular area within thisPic
.Returns a partial
Pic
of 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
Pic
of a rectangular area within thisPic
.Returns a partial
Pic
of 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
Pic
of a rectangular area within thisPic
.Returns a partial
Pic
of 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 resultingPic
and vice versa.Creates mirrored version of this
Pic
: what’s on the left in the original is on the right in the resultingPic
and 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 resultingPic
and vice versa.Creates mirrored version of this
Pic
: what’s at the top in the original is at the bottom in the resultingPic
and 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
Pic
s internal representation into bitmap form.Forces rasterization of any vector graphics in this
Pic
s 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
Pic
in 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
Pic
and available through history.A limit on the number of historical method calls that are tracked by the
Pic
and 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
Pic
is internally stored as a bitmap raster.Indicates whether this
Pic
is internally stored as a bitmap raster. See the introduction to this class for more information.- returns
true
if the entirePic
is rasterized as a bitmap;false
if 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
Pic
and the given one so that thisPic
appears immediately to the left the otherPic
.Combines this
Pic
and the given one so that thisPic
appears immediately to the left the otherPic
. The combinedPic
will be large enough to fit both originals.- rightPic
the
Pic
that is to the right of thisPic
in the combination- retainAnchor
true
means 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
Pic
and the given one so that thisPic
appears in front of the otherPic
at specific coordinates.Combines this
Pic
and the given one so that thisPic
appears in front of the otherPic
at specific coordinates. The combinedPic
will be larger than either of the two originals unless thisPic
fits completely in front of the other one. This version ofonto
uses the given Anchor instead of thisPic
s defaultanchor
.- backPic
the
Pic
that is behind this one in the combination- my
the point within this
Pic
that will be placed at the given coordinates- at
the point within
backPic
that thisPic
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, at: world.Pos): Pic
Combines this
Pic
and the given one so that thisPic
appears in front of the otherPic
at specific coordinates.Combines this
Pic
and the given one so that thisPic
appears in front of the otherPic
at specific coordinates. The combinedPic
will be larger than either of the two originals unless thisPic
fits completely in front of the other one. This version ofonto
anchors thisPic
at its default anchor.- backPic
the
Pic
that is behind this one in the combination- at
the point within
backPic
that 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
Pic
and the given one so that thisPic
appears in front of the otherPic
.Combines this
Pic
and the given one so that thisPic
appears in front of the otherPic
. The combinedPic
will be larger than either of the two originals unless thisPic
fits completely in front of the other one. This version ofonto
anchors thisPic
from its default anchor to an anchor in the other image.- backPic
the
Pic
that is behind this one in the combination- atIts
the point within
backPic
that 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
Pic
and the given one so that thisPic
appears in front of the otherPic
.Combines this
Pic
and the given one so that thisPic
appears in front of the otherPic
. The combinedPic
will be larger than either of the two originals unless thisPic
fits completely in front of the other one. This version ofonto
uses the given Anchors instead of the defaultanchor
of either of the originalPic
s.- backPic
the
Pic
that is behind this one in the combination- my
the point within this
Pic
that will be placed atatIts
- atIts
the point within
backPic
that thisPic
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 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
Pic
that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePic
first.- 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
Pic
that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePic
first.- 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
Pic
that’s not fully rasterized as a bitmap. If you have a vector graphic and need to call this method many times, consider freezing thePic
first.- Annotations
- @inline()
- def pixelsNear(pos: world.Pos, range: Double): Seq[Color]
Returns the colors of the pixels in this
Pic
that are “near” a given Pos.Returns the colors of the pixels in this
Pic
that are “near” a given Pos. A pixel counts as being near if it’s located at aPos
whose distance from the givenPos
is 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
Pic
will 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
Pic
and the given ones so that thisPic
serves as a background and the otherPic
s appear in front but not beyond thisPic
’s borders.Combines this
Pic
and the given ones so that thisPic
serves as a background and the otherPic
s appear in front but not beyond thisPic
’s borders. The visible part of the combinedPic
is the size of this backgroundPic
. This is equivalent to calling place(Pic,Pos) repeatedly.- foregroundPics
tuples containing: the
Pic
s that will be placed against this background and the points within thisPic
where their default anchors will be placed- returns
the combined
Pic
- Annotations
- @inline()
- def place(foregroundPics: Iterable[(Pic, world.Pos)]): Pic
Combines this
Pic
and the given ones so that thisPic
serves as a background and the otherPic
s appear in front but not beyond thisPic
’s borders.Combines this
Pic
and the given ones so that thisPic
serves as a background and the otherPic
s appear in front but not beyond thisPic
’s borders. The visible part of the combinedPic
is the size of this backgroundPic
. This is equivalent to calling place(Pic,Pos) repeatedly.- foregroundPics
tuples containing: the
Pic
s that will be placed against this background and the points within thisPic
where their default anchors will be placed- returns
the combined
Pic
- Annotations
- @inline()
- def place(foregroundPicAndPos: (Pic, world.Pos)): Pic
Combines this
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders.Combines this
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders. The visible part of the combinedPic
is the size of this backgroundPic
. Some or even none of the otherPic
is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPic
that 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 thePic
is rendered onscreen.) This version ofplace
anchors the otherPic
at its default anchor to a specific Pos in this background.- foregroundPicAndPos
a tuple containing: the
Pic
that will be placed against this background and the point within thisPic
thatforeground
’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
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders.Combines this
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders. The visible part of the combinedPic
is the size of this backgroundPic
. Some or even none of the otherPic
is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPic
that 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 thePic
is rendered onscreen.) This version ofplace
anchors the otherPic
at 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
Pic
thatforeground
’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
Pic
s
- def place(foreground: Pic, at: world.Pos): Pic
Combines this
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders.Combines this
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders. The visible part of the combinedPic
is the size of this backgroundPic
. Some or even none of the otherPic
is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPic
that 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 thePic
is rendered onscreen.) This version ofplace
anchors the otherPic
at its default anchor to a specific Pos in this background.- foreground
the
Pic
that will be placed against this background- at
the point within this
Pic
thatforeground
’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
Pic
s
- def place(foreground: Pic, its: Anchor, atMy: Anchor): Pic
Combines this
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders.Combines this
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders. The visible part of the combinedPic
is the size of this backgroundPic
. Some or even none of the otherPic
is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPic
that 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 thePic
is rendered onscreen.) This version ofplace
uses the given Anchors instead of the defaultanchor
of either of the originalPic
s.- foreground
the
Pic
that will be placed against this background- its
the point within
foreground
that will be placed at the given coordinates- atMy
the point within this
Pic
thatforeground
will be placed at- returns
the combined
Pic
- Annotations
- @inline()
- See also
place, which does the same but switches the order of the two
Pic
s
- def place(foreground: Pic, its: Anchor, at: world.Pos): Pic
Combines this
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders.Combines this
Pic
and the given one so that thisPic
serves as a background and the otherPic
appears in front but not beyond thisPic
’s borders. The visible part of the combinedPic
is the size of this backgroundPic
. Some or even none of the otherPic
is visible in front of this background, depending on the relative positioning and dimensions of the two images; any parts of the otherPic
that 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 thePic
is rendered onscreen.) This version ofplace
uses the given Anchor instead of the otherPic
s defaultanchor
and places it at a specific Pos in this background.- foreground
the
Pic
that will be placed against this background- its
the point within
foreground
that will be placed at the given coordinates- at
the point within this
Pic
thatforeground
will be placed at- returns
the combined
Pic
- Annotations
- @inline()
- See also
place which does the same but switches the order of the two
Pic
s
- def placeCopies(foregroundPic: Pic, at: Iterable[world.Pos]): Pic
Combines this
Pic
and copies of the given one so that thisPic
serves as a background and the copies of the otherPic
s appear in front but not beyond thisPic
’s borders.Combines this
Pic
and copies of the given one so that thisPic
serves as a background and the copies of the otherPic
s appear in front but not beyond thisPic
’s borders. The visible part of the combinedPic
is the size of this backgroundPic
. This is equivalent calling place(Pic,Pos) repeatedly, passing in the same foreground image each time.- foregroundPic
the
Pic
s whose copies will be placed against this background- at
the points within this
Pic
where 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
Pic
and the given one so that thisPic
appears immediately to the right the otherPic
.Combines this
Pic
and the given one so that thisPic
appears immediately to the right the otherPic
. The combinedPic
will be large enough to fit both originals.- leftPic
the
Pic
that is to the left of thisPic
in the combination- retainAnchor
true
means 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
Pic
so that they appear in a horizontal row.Combines copies of this
Pic
so that they appear in a horizontal row. The combinedPic
will 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
Pic
in the given file in PNG format.Saves the
Pic
in the given file in PNG format.- path
an absolute local path or a path relative to the working directory
- returns
true
if the saving was successful andfalse
if no file was created because there was no bitmap to save
- Annotations
- @inline()
- def scaleBy(factor: Double): Pic
Creates a version of this
Pic
that is larger or smaller as per the given multiplier.Creates a version of this
Pic
that 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
Pic
that is a scaled version of this one; it will usually be a bitmap, but some simple vector-basedPic
s may retain their vector form
- Annotations
- @inline()
- def scaleTo(sizingPic: Pic): Pic
Creates a scaled version of this
Pic
that has the dimensions of the givenPic
.Creates a scaled version of this
Pic
that has the dimensions of the givenPic
. The aspect ratio of the resulting image may be different from the original’s.- sizingPic
a
Pic
whose width and height are given to the scaledPic
- returns
a new
Pic
that is a scaled version of this one; it will usually be a bitmap, but some simple vector-basedPic
s may retain their vector form
- Annotations
- @inline()
- def scaleTo(targetSize: Double): Pic
Creates a scaled version of this
Pic
that has the given size and is rectangular.Creates a scaled version of this
Pic
that has the given size and is rectangular. If the originalPic
isn’t rectangular, the aspect ratio of the result will be different.- targetSize
the width and height of the output image
- returns
a new
Pic
that is a scaled version of this one; it will usually be a bitmap, but some simple vector-basedPic
s may retain their vector form
- Annotations
- @inline()
- def scaleTo(targetWidth: Double, targetHeight: Double): Pic
Creates a scaled version of this
Pic
that has the given dimensions.Creates a scaled version of this
Pic
that 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
Pic
that is a scaled version of this one; it will usually be a bitmap, but some simple vector-basedPic
s may retain their vector form
- Annotations
- @inline()
- def shiftDown(offset: Double): Pic
Shifts each pixel within the
Pic
downwards by the given amount.Shifts each pixel within the
Pic
downwards by the given amount. Retains the size of the image: any pixels that would go beyond the bottom edge of thePic
instead 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
Pic
to the left by the given amount.Shifts each pixel within the
Pic
to the left by the given amount. Retains the size of the image: any pixels that would go beyond the left edge of thePic
instead 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
Pic
to the right by the given amount.Shifts each pixel within the
Pic
to the right by the given amount. Retains the size of the image: any pixels that would go beyond the right edge of thePic
instead 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
Pic
upwards by the given amount.Shifts each pixel within the
Pic
upwards by the given amount. Retains the size of the image: any pixels that would go beyond the top edge of thePic
instead 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
Pic
in a minimalistic GUI window.Displays this
Pic
in a minimalistic GUI window. Calling this method repeatedly on the samePic
doesn’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
Pic
in the frame (where thePic
is 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
Pic
converted to a SwingIcon
). - lazy val toImage: Option[BufferedImage]
This
Pic
converted 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
Pic
to generate a differentPic
.Applies the given operation to each pixel in the
Pic
to 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
transformColors
calls on every pixel in the image to map its color to a new one- returns
the new (bitmap) image obtained by calling
transformer
and putting together the outputs
- Annotations
- @inline()
- def transformXY(newColorAt: (Int, Int) => Color): Pic
Applies the given operation to each position in the
Pic
to generate a differentPic
.Applies the given operation to each position in the
Pic
to generate a differentPic
.- newColorAt
a function that
transformXY
calls repeatedly to determine the pixels of the transformedPic
- returns
the new (bitmap) image obtained by calling
newColorAt
and 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
Pic
in 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.