smile.colors
Members list
Type members
Classlikes
Utility methods for creating and converting colors in various color spaces and formats, including HSI (Hue, Saturation, Intensity) and RGBA (Red, Green, Blue, Alpha), and for lightening or darkening colors.
Utility methods for creating and converting colors in various color spaces and formats, including HSI (Hue, Saturation, Intensity) and RGBA (Red, Green, Blue, Alpha), and for lightening or darkening colors.
Attributes
- See also
- Companion
- class
- Source
- Color.scala
- Supertypes
- Self type
-
Color.type
Represents a color with RGB and opacity components. The predefined colors in smile.colors.PresetColor are plain values of this class.
Represents a color with RGB and opacity components. The predefined colors in smile.colors.PresetColor are plain values of this class.
Value parameters
- blue
-
The blue component of the color, in the range [0, 255].
- green
-
The green component of the color, in the range [0, 255].
- opacity
-
The opacity of the color, in the range [0, 255]. Defaults to 255.
- red
-
The red component of the color, in the range [0, 255].
Attributes
- Companion
- object
- Source
- Color.scala
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Paintclass Objecttrait Matchableclass AnyShow all
Represents a linear gradient paint with two or more colors.
Represents a linear gradient paint with two or more colors.
import smile.colors.PresetColor.*
import smile.modeling.*
import smile.pictures.*
val stops = Seq(0.0 -> MidnightBlue, 0.55 -> Tomato, 1.0 -> Gold)
val sunset = Rectangle(160, 100, fillWith(LinearGradient(Pos(0, 0), Pos(0, 100), stops)), None)
val sea = Rectangle(160, 40, fillWith(LinearGradient(Pos(0, 0), Pos(160, 0), Teal, Navy)), None)

Coordinate contract
start and end are element-local coordinates whose origin is the top-left corner of the shape's own, untransformed box (a text's layout box), widened by a stroke's radius. For a shape that is not turned or scaled, Pos(0, 0) is the top-left corner of its bounds and Pos(bounds.width, bounds.height) is the opposite one, so
val gradient = LinearGradient(Pos(0, 0), Pos(width, 0), red, blue)
always paints a horizontal red-to-blue gradient across the whole shape, no matter where the shape sits in the picture. They are not world coordinates. The same gradient on two shapes paints each of them from its own corner. Every renderer (Java2D on the JVM, canvas and SVG on Scala.js) resolves the points this way.
The frame travels with the element. Coordinates outside the box are legal and place the gradient's ends outside the shape, where cycleMethod takes over. A gradient lives in its shape's own frame, and every renderer paints it under the shape's affine. So a moved, rotated, scaled or mirrored element moves, turns, stretches or mirrors its gradient rigidly with it, and the gradient's points never change.
What a gradient has to be
A gradient that can be constructed can be painted, on every backend. Its two points are finite and differ, since a gradient without a length has no direction to run in. There are at least two stops, and their fractions lie within zero to one and do not run backwards. Two stops that share a fraction make a hard edge from one color to the next.
A gradient so short that a renderer's floats cannot tell its two points apart is painted with its smile.colors.LinearGradient.averageColor.
Value parameters
- cycleMethod
-
The method used to repeat the gradient pattern if the shape to be filled is larger than the gradient defined by the start and end points.
- end
-
The ending position of the gradient, relative to the top-left corner of the shape's own, untransformed box.
- start
-
The starting position of the gradient, relative to the top-left corner of the shape's own, untransformed box.
- stops
-
The colors of the gradient, each at its fraction of the way from
starttoend.
Attributes
- Companion
- object
- Source
- LinearGradient.scala
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Paintclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Source
- LinearGradient.scala
- Supertypes
- Self type
-
LinearGradient.type
A paint pattern, usable as the fill or stroke of a shape.
A paint pattern, usable as the fill or stroke of a shape.
Attributes
- Source
- Paint.scala
- Supertypes
- Known subtypes
-
class Colorclass LinearGradient
Predefined colors, plain smile.colors.Color values, and their canonical names. Each is shown with its color and its red, green and blue as hexadecimal digits.
Predefined colors, plain smile.colors.Color values, and their canonical names. Each is shown with its color and its red, green and blue as hexadecimal digits.
Attributes
- See also
- Source
- PresetColor.scala
- Supertypes
- Self type
-
PresetColor.type
