• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.ux.material.libmonet.scheme;
18 
19 import static java.lang.Math.max;
20 
21 import com.google.ux.material.libmonet.dislike.DislikeAnalyzer;
22 import com.google.ux.material.libmonet.dynamiccolor.DynamicScheme;
23 import com.google.ux.material.libmonet.dynamiccolor.Variant;
24 import com.google.ux.material.libmonet.hct.Hct;
25 import com.google.ux.material.libmonet.palettes.TonalPalette;
26 import com.google.ux.material.libmonet.temperature.TemperatureCache;
27 
28 /**
29  * A scheme that places the source color in Scheme.primaryContainer.
30  *
31  * <p>Primary Container is the source color, adjusted for color relativity. It maintains constant
32  * appearance in light mode and dark mode. This adds ~5 tone in light mode, and subtracts ~5 tone in
33  * dark mode.
34  *
35  * <p>Tertiary Container is an analogous color, specifically, the analog of a color wheel divided
36  * into 6, and the precise analog is the one found by increasing hue. This is a scientifically
37  * grounded equivalent to rotating hue clockwise by 60 degrees. It also maintains constant
38  * appearance.
39  */
40 public class SchemeContent extends DynamicScheme {
SchemeContent(Hct sourceColorHct, boolean isDark, double contrastLevel)41   public SchemeContent(Hct sourceColorHct, boolean isDark, double contrastLevel) {
42     super(
43         sourceColorHct,
44         Variant.CONTENT,
45         isDark,
46         contrastLevel,
47         TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), sourceColorHct.getChroma()),
48         TonalPalette.fromHueAndChroma(
49             sourceColorHct.getHue(),
50             max(sourceColorHct.getChroma() - 32.0, sourceColorHct.getChroma() * 0.5)),
51         TonalPalette.fromHct(
52             DislikeAnalyzer.fixIfDisliked(
53                 new TemperatureCache(sourceColorHct)
54                     .getAnalogousColors(/* count= */ 3, /* divisions= */ 6)
55                     .get(2))),
56         TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), sourceColorHct.getChroma() / 8.0),
57         TonalPalette.fromHueAndChroma(
58             sourceColorHct.getHue(), (sourceColorHct.getChroma() / 8.0) + 4.0));
59   }
60 }
61