# Core

The core 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 ScalaDoc for details.

## Imports

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

## 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 ScalaDoc 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 companion object 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 ScalaDoc 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(1.0, 1.0) // cartesian coordinates
Point(1.0, 90.degrees) // polar coordinates
// res19: Point = Polar(1.0, 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(1.0, 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)
```