Skip to content

Commit 799b6ba

Browse files
Material Engcopybara-github
authored andcommitted
Add documentation on making schemes.
PiperOrigin-RevId: 562776630
1 parent 3233451 commit 799b6ba

File tree

3 files changed

+156
-1
lines changed

3 files changed

+156
-1
lines changed

extract_colors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Extracting colors from an image
22

3-
[TOC]
3+
44

55
To extract colors from an image that are suitable for generating schemes, use
66
the `quantize` and `score` libraries.

make_schemes.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Making and using schemes
2+
3+
4+
5+
With a seed color, you may create a dynamic color scheme using the
6+
`DynamicScheme` class and its subclasses.
7+
8+
Then, you can get color roles from the scheme using the `DynamicColor` class.
9+
10+
## What a `DynamicScheme` is
11+
12+
A `DynamicScheme` object contains all the information you need to generate all
13+
color roles.
14+
15+
It includes the following information:
16+
17+
- The source color (seed color) of the theme
18+
* `sourceColorArgb` is the color in ARGB format, and `sourceColorHct` is
19+
in HCT format.
20+
- The variant this scheme uses - `variant`
21+
- Whether the scheme is in light mode or dark mode
22+
* using the boolean `isDark`
23+
- The current contrast level
24+
* stored in `contrastLevel` as a `double`
25+
* `0.0` is the default contrast level
26+
* `0.5` is medium
27+
* `1.0` is high
28+
* `-1.0` is reduced
29+
- Six tonal palettes:
30+
* `primaryPalette`
31+
* `secondaryPalette`
32+
* `tertiaryPalette`
33+
* `neutralPalette`
34+
* `neutralVariantPalette`
35+
* `errorPalette`
36+
37+
A `DynamicScheme` object does not store the ARGB or HCT values of individual
38+
color roles; they are generated upon demand (see below for more information)
39+
40+
## Step 1 — Generating a scheme
41+
42+
### Method 1 — Using a variant
43+
44+
The easiest way to generate a scheme from a seed color is using a variant scheme
45+
constructor, such as `SchemeTonalSpot`.
46+
47+
All you need is to specify: - a source color, as an `Hct` object; - a boolean
48+
indicating whether the scheme is in dark mode; - the contrast level.
49+
50+
The following example uses an HCT object `hct` as seed, and generates a
51+
`SchemeTonalSpot` in light mode with default contrast.
52+
53+
<section>
54+
55+
###### Dart
56+
57+
```dart
58+
final scheme = SchemeTonalSpot(sourceColorHct: hct, isDark: false, contrastLevel: 0.0);
59+
```
60+
61+
###### Java
62+
63+
```java
64+
DynamicScheme scheme = new SchemeTonalSpot(hct, false, 0.0);
65+
```
66+
67+
###### TypeScript
68+
69+
```typescript
70+
const scheme = new SchemeTonalSpot(hct, false, 0.0);
71+
```
72+
73+
###### C++
74+
75+
```cpp
76+
DynamicScheme scheme = SchemeTonalSpot(hct, false, 0.0);
77+
```
78+
79+
###### Swift
80+
81+
```swift
82+
let scheme = SchemeTonalSpot(
83+
sourceColorHct: hct,
84+
isDark: false,
85+
contrastLevel: 0.0)
86+
```
87+
88+
</section>
89+
90+
Currently the following variants are available:
91+
92+
* Content
93+
* Expressive
94+
* Fidelity
95+
* Fruit salad
96+
* Monochrome
97+
* Neutral
98+
* Rainbow
99+
* Tonal spot
100+
* Vibrant
101+
102+
### Method 2 — Specifying palettes
103+
104+
## Step 2 — Obtaining colors
105+
106+
To obtain a color from a dynamic scheme, use a `DynamicColor` object on a
107+
`DynamicScheme`.
108+
109+
Use the `getArgb` method to get the desired color as an integer in ARGB format,
110+
or the `getHct` method for the color as an `Hct` object.
111+
112+
Dynamic colors used in Material Design are defined in the
113+
`MaterialDynamicColors` class. Below are examples of obtaining the `primary`
114+
color from a given `scheme`.
115+
116+
<section>
117+
118+
###### Dart
119+
120+
```dart
121+
final argb = MaterialDynamicColors.primary.getArgb(scheme);
122+
final hct = MaterialDynamicColors.primary.getHct(scheme);
123+
```
124+
125+
###### Java
126+
127+
```java
128+
MaterialDynamicColors materialDynamicColors = new MaterialDynamicColors();
129+
int argb = materialDynamicColors.primary().getArgb(scheme);
130+
Hct hct = materialDynamicColors.primary().getHct(scheme);
131+
```
132+
133+
###### TypeScript
134+
135+
```typescript
136+
const argb = MaterialDynamicColors.primary.getArgb(scheme);
137+
const hct = MaterialDynamicColors.primary.getHct(scheme);
138+
```
139+
140+
###### C++
141+
142+
```cpp
143+
Argb argb = MaterialDynamicColors::Primary().GetArgb(s);
144+
Hct hct = MaterialDynamicColors::Primary().GetHct(s);
145+
```
146+
147+
###### Swift
148+
149+
```swift
150+
let argb = MaterialDynamicColors.primary.getArgb(scheme)
151+
let hct = MaterialDynamicColors.primary.getHct(scheme)
152+
```
153+
154+
</section>

sitemap.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Sitemap
55
* I want to …
66

77
- [Extract colors from an image](extract_colors.md)
8+
- [Make and use schemes](make_schemes.md)

0 commit comments

Comments
 (0)