# Core

The index package provides utilities, such as Color and Point, that are useful in the rest of the libraries.

In this section we just cover the most important uses. You should see the index for details.

## Imports

```
// You definitely want doodle.core
import doodle.core._
// You probably also want extension methods
import doodle.syntax.all._
```

## Angle

The Angle type represents an angle, as the name suggests.

Most of the time you'll create `Angles`

using the extension methods shown below. Degrees and radians should be familiar, but turns may not be. One turn corresponds to a full circle (i.e. 360 degrees), so using turns in a convenient way to represent simple fractions or multiples of circles.

```
45.degrees
1.radians
0.5.turns // One turn is a full circle, so this is half a circle
```

There are various methods to perform arithmetic on angles. Here are some examples. See the Angle for a complete list.

```
(45.degrees + 45.degrees) < 180.degrees
// res3: Boolean = true
(45.degrees * 2) < 90.degrees
// res4: Boolean = false
180.degrees - 0.5.turns
// res5: Angle = Angle(0.0)
```

Other useful methods are calculating the sine and cosine of an angle, and normalizing an angle to between zero and 360 degrees.

```
0.5.turns.sin
// res6: Double = 1.2246467991473532E-16
0.5.turns.cos
// res7: Double = -1.0
2.turns.normalize == 1.turns
// res8: Boolean = true
```

## Color

Working with Color is something that most images will do. There are two representations of color used in Doodle:

- hue, saturation, and lightness (HSL); and
- red, green, and blue (RGB).

The HSL representation is easier to work with, while the RGB representation is how colors are actually generated by computer screens. All colors also have an alpha value, which determines transparency. Various constructors allow creating colors

```
Color.hsl(0.degrees, 1.0, 0.5) // a vibrant red
Color.hsla(0.degrees, 1.0, 0.5, 0.5) // set the alpha to 0.5 (half transparent)
Color.rgb(0, 0, 255) // pure blue
Color.rgb(0.uByte, 0.uByte, 255.uByte) // Using the UnsignedByte type
Color.rgba(0, 0, 255, 0.5) // Setting alpha
Color.rgba(0.uByte, 0.uByte, 255.uByte, 0.5.normalized) // Setting alpha
```

On the Color all the standard CSS colors are defined. Here are a few examples.

```
Color.steelBlue // Not to be confused with blue steel
Color.beige
Color.limeGreen
```

There are many methods to modify colors, such as `spin`

, `desaturate`

, and so on. See the Color for full details.

## Point

A Point represents a location in the 2-D plane. We can construct points from cartesian (xy-coordinates) or polar (radius and angle) coordinates as shown below.

```
Point(1.0, 1.0) // cartesian coordinates
// res18: Point = Cartesian(x = 1.0, y = 1.0) // cartesian coordinates
Point(1.0, 90.degrees) // polar coordinates
// res19: Point = Polar(r = 1.0, angle = Angle(1.5707963267948966))
```

No matter how we construct a `Point`

we can still access x- and y-coordinates or radius and angle.

```
val pt1 = Point(1.0, 0.0)
// pt1: Point = Cartesian(x = 1.0, y = 0.0)
pt1.x
// res20: Double = 1.0
pt1.y
// res21: Double = 0.0
pt1.r
// res22: Double = 1.0
pt1.angle
// res23: Angle = Angle(0.0)
```

## Transform

A Transform, in Doodle, represents an affine transform in two-dimensions. The easiest way to create a `Transform`

is via the methods on the Transform. Here are some examples.

```
Transform.scale(5.0, -2.0)
Transform.rotate(90.degrees)
Transform.translate(10, 10)
```

A `Transform`

can be applied to a `Point`

to transform that point.

```
Transform.scale(5.0, -2.0)(Point(1,1))
// res27: Point = Cartesian(x = 5.0, y = -2.0)
Transform.rotate(90.degrees)(Point(1,1))
// res28: Point = Cartesian(x = -0.9999999999999999, y = 1.0)
Transform.translate(10, 10)(Point(1,1))
// res29: Point = Cartesian(x = 11.0, y = 11.0)
```

`Transforms`

can be composed together using the `andThen`

method.

```
Transform.scale(5.0, -2.0).andThen(Transform.translate(10, 10))(Point(1,1))
// res30: Point = Cartesian(x = 15.0, y = 8.0)
Transform.scale(5.0, -2.0).translate(10, 10)(Point(1,1)) // Shorter version
// res31: Point = Cartesian(x = 15.0, y = 8.0)
```

## Vec

A Vec represents a two-dimensional vector. You can construct `Vecs`

from cartesian (xy-coordinates) or polar (length and angle) coordinates, just like `Point`

.

```
Vec(0, 1)
// res32: Vec = Vec(x = 0.0, y = 1.0)
Vec(1, 90.degrees)
// res33: Vec = Vec(x = 6.123233995736766E-17, y = 1.0)
```