|
10 | 10 | * Rotatable gradients by 45 degrees with aim to add rotation by any angle in the future Utility |
11 | 11 |
|
12 | 12 | * Functions to convert between `androidx.compose.ui.graphics.Color`, HSL, HSV, `RGB`, HCT, and |
13 | | - colors with nearest **Name** based on distance is in 3D space using `Red`, `Green`, `Blue`. |
| 13 | + colors with nearest **Name** based on distance is in 3D space using `Red`, `Green`, `Blue`. |
| 14 | + |
| 15 | +| M2 Color Swatches | M3 Tone Palettes | | ----------|-----------| -----------| -----------| |
| 16 | +| <img src="./screenshots/material_design2.gif" width="250"> |
| 17 | +| <img src="./screenshots/colorpicker/material_design_3.gif" width="250"> | |
| 18 | + |
| 19 | +## Material Design 2 Colors && Swatches |
| 20 | + |
| 21 | +### Material Colors |
| 22 | + |
| 23 | +<img src="https://i.stack.imgur.com/mteGN.png"> |
| 24 | + |
| 25 | +[Material Colors](material_design2.gif material_design3.gif) can be accessed from Red to Brown. |
| 26 | +Brown, Grey, and BlueGrey swatches only have primary colors. |
| 27 | + |
| 28 | +```kotlin |
| 29 | +val Red50 = Color(0xffFFEBEE) |
| 30 | +val Red100 = Color(0xffFFCDD2) |
| 31 | +val Red200 = Color(0xffEF9A9A) |
| 32 | +val Red300 = Color(0xffE57373) |
| 33 | +val Red400 = Color(0xffEF5350) |
| 34 | +val Red500 = Color(0xffF44336) |
| 35 | +val Red600 = Color(0xffE53935) |
| 36 | +val Red700 = Color(0xffD32F2F) |
| 37 | +val Red800 = Color(0xffC62828) |
| 38 | +val Red900 = Color(0xffB71C1C) |
| 39 | + |
| 40 | +// Accent Colors |
| 41 | +val RedA100 = Color(0xffFF8A80) |
| 42 | +val RedA200 = Color(0xffFF5252) |
| 43 | +val RedA400 = Color(0xffFF1744) |
| 44 | +val RedA700 = Color(0xffD50000) |
| 45 | +``` |
| 46 | + |
| 47 | +For material Swatches |
| 48 | + |
| 49 | +Call any swatch from `ColorSwatch` for instance for Red500 with `ColorSwatch.red` which will return |
| 50 | +primary color `Map<Int,Color>` |
| 51 | + |
| 52 | +```kotlin |
| 53 | + val red by lazy { |
| 54 | + linkedMapOf( |
| 55 | + 50 to Color(0xffFFEBEE), |
| 56 | + 100 to Color(0xffFFCDD2), |
| 57 | + 200 to Color(0xffEF9A9A), |
| 58 | + 300 to Color(0xffE57373), |
| 59 | + 400 to Color(0xffEF5350), |
| 60 | + 500 to Color(0xffF44336), |
| 61 | + 600 to Color(0xffE53935), |
| 62 | + 700 to Color(0xffD32F2F), |
| 63 | + 800 to Color(0xffC62828), |
| 64 | + 900 to Color(0xffB71C1C) |
| 65 | + ) |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +to access any color from this map |
| 70 | + |
| 71 | +``` |
| 72 | +val redSwatch = ColorSwatch.red |
| 73 | +val red300 = redSwatch[300]!! |
| 74 | +``` |
| 75 | + |
| 76 | +Swatch that returns header(50 variants) |
| 77 | + |
| 78 | +```kotlin |
| 79 | +val primaryHeaderColors by lazy { |
| 80 | + listOf( |
| 81 | + Color(0xffF44336), |
| 82 | + Color(0xffE91E63), |
| 83 | + Color(0xff9C27B0), |
| 84 | + Color(0xff673AB7), |
| 85 | + Color(0xff3F51B5), |
| 86 | + Color(0xff2196F3), |
| 87 | + Color(0xff03A9F4), |
| 88 | + Color(0xff00BCD4), |
| 89 | + Color(0xff00ACC1), |
| 90 | + Color(0xff4CAF50), |
| 91 | + Color(0xff8BC34A), |
| 92 | + Color(0xffCDDC39), |
| 93 | + Color(0xffFFEB3B), |
| 94 | + Color(0xffFFC107), |
| 95 | + Color(0xffFF9800), |
| 96 | + Color(0xffFF5722), |
| 97 | + Color(0xff795548), |
| 98 | + Color(0xff9E9E9E), |
| 99 | + Color(0xff607D8B) |
| 100 | + ) |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +## Material Design 3 Tonal Palette |
| 105 | +A tonal palette consists of thirteen tones, including white and black. A tone value of 100 is equivalent to the idea of light at its maximum and results in white. Every tone value between 0 and 100 expresses the amount of light present in the color. |
| 106 | + |
| 107 | + |
| 108 | +| <img src="./screenshots/m3_tones.png" width="250"> |
| 109 | +From range 0 to 100 |
| 110 | +```kotlin |
| 111 | +val material3ToneRange = listOf( |
| 112 | + 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 99, 100 |
| 113 | +) |
| 114 | + |
| 115 | +``` |
| 116 | + |
| 117 | +Call |
| 118 | +```kotlin |
| 119 | +fun getColorTonesList(color: Color): List< Color> { |
| 120 | + |
| 121 | + val camColor = Cam16.fromInt(color.toArgb()) |
| 122 | + val palette: TonalPalette = TonalPalette.fromHueAndChroma(camColor.hue, max(48.0,camColor.chroma)) |
| 123 | + val toneList = mutableListOf<Color>() |
| 124 | + |
| 125 | + material3ToneRange.forEach { shade -> |
| 126 | + toneList.add(Color(palette.tone(shade))) |
| 127 | + } |
| 128 | + |
| 129 | + return toneList |
| 130 | +} |
| 131 | +``` |
| 132 | +that returns list of colors or |
| 133 | + |
| 134 | +```kotlin |
| 135 | +fun getColorTonesMap(color: Color): Map<Int, Color> { |
| 136 | + val palette: TonalPalette = TonalPalette.fromInt(color.toArgb()) |
| 137 | + val toneMap = linkedMapOf<Int, Color>() |
| 138 | + |
| 139 | + material3ToneRange.forEach { shade -> |
| 140 | + toneMap[shade] = Color(palette.tone(shade)) |
| 141 | + } |
| 142 | + |
| 143 | + return toneMap |
| 144 | +} |
| 145 | + |
| 146 | +``` |
| 147 | +to get Map with tone keys |
0 commit comments