### Build and Install from Source Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Install the library directly from the master branch of the GitHub repository. ```console pip3 install https://github.com/T-Dynamos/materialyoucolor-python/archive/master.zip ``` -------------------------------- ### Install with Pip Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Install the library using pip for easy integration. ```console pip3 install materialyoucolor --upgrade ``` -------------------------------- ### Install on Arch Linux (Stable v2) Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Install the legacy stable version using the AUR helper 'yay'. ```console yay -S python-materialyoucolor ``` -------------------------------- ### Install on Arch Linux (Material You v3) Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Install the latest version (v3) using the AUR helper 'yay'. ```console yay -S python-materialyoucolor3 ``` -------------------------------- ### Generate Dynamic Colors Setup Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Imports necessary for generating dynamic Material You color schemes using HCT and MaterialDynamicColors. Note: The full dynamic color generation code is not provided in the snippet. ```python # Color in hue, chroma, tone form from materialyoucolor.hct import Hct from materialyoucolor.dynamiccolor.color_spec import COLOR_NAMES from materialyoucolor.dynamiccolor.material_dynamic_colors import MaterialDynamicColors # There are 9 different variants of scheme. from materialyoucolor.scheme.scheme_tonal_spot import SchemeTonalSpot ``` -------------------------------- ### Generate Material You color scheme in Python Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Initializes a color scheme using a source color and prints the RGBA and hex values for defined color names. ```python scheme = SchemeTonalSpot( # choose any scheme here Hct.from_int(0xff4181EE), # source color in hct form True, # dark mode 0.0, # contrast spec_version="2025" ) mdc = MaterialDynamicColors(spec="2025") for color in COLOR_NAMES: _color = getattr(mdc, color) print(color, _color.get_rgba(scheme), _color.get_hex(scheme)) ``` -------------------------------- ### Build with Kivy-ios for iOS Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Use the kivy-ios toolchain to build the materialyoucolor library for iOS. ```console toolchain build materialyoucolor ``` -------------------------------- ### Generate Tonal Palettes Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Demonstrates how to create a TonalPalette from a base color or HCT object and retrieve colors at different tones. ```python from materialyoucolor.palettes import TonalPalette from materialyoucolor.hct import Hct from materialyoucolor.utils.color_utils import hex_from_argb # Get colors at different tones (lightness levels) print("Blue Tonal Palette:") for tone in [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100]: argb = blue_palette.tone(tone) hex_color = hex_from_argb(argb) print(f" Tone {tone:3d}: {hex_color}") # Output: # Blue Tonal Palette: # Tone 0: #000000FF # Tone 10: #001B3DFF # Tone 20: #002F65FF # Tone 30: #00458FFF # Tone 40: #005CBBFF # Tone 50: #2077D9FF # Tone 60: #4C91F4FF # Tone 70: #82ACFFFF # Tone 80: #ADC7FFFF # Tone 90: #D7E3FFFF # Tone 95: #ECF0FFFF # Tone 100: #FFFFFFFF # Create palette from existing color source_argb = 0xff4181EE palette_from_color = TonalPalette.from_int(source_argb) print(f"\nPalette hue: {palette_from_color.hue:.1f}") print(f"Palette chroma: {palette_from_color.chroma:.1f}") # Create palette from HCT object hct_color = Hct.from_int(0xffFF5722) # Deep orange palette_from_hct = TonalPalette.from_hct(hct_color) # Get HCT object at specific tone hct_at_tone_60 = palette_from_hct.get_hct(60.0) print(f"\nOrange at tone 60: {hct_at_tone_60}") print(f" ARGB: {hex(hct_at_tone_60.to_int())}") ``` -------------------------------- ### Convert ARGB to other color spaces Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Demonstrates conversion from ARGB to L* (lightness), XYZ, and CIELAB color spaces, and back. Requires an initial ARGB color value. ```python new_argb = argb_from_rgb(65, 129, 238) # Alpha defaults to 255 print(f"From RGB: {hex(new_argb)}") # 0xff4181ee new_argb_alpha = argb_from_rgba([65, 129, 238, 200]) # Custom alpha print(f"From RGBA: {hex(new_argb_alpha)}") # Convert to/from L* (lightness in CIELAB) lstar = lstar_from_argb(color_argb) # ~53.5 print(f"L* value: {lstar:.2f}") gray_argb = argb_from_lstar(50.0) # Gray at L*=50 print(f"Gray at L*50: {hex_from_argb(gray_argb)}") # Convert to/from XYZ color space xyz = xyz_from_argb(color_argb) print(f"XYZ: {[f'{v:.2f}' for v in xyz]}") # Convert to/from CIELAB color space lab = lab_from_argb(color_argb) print(f"LAB: L={lab[0]:.1f}, a={lab[1]:.1f}, b={lab[2]:.1f}") restored_argb = argb_from_lab(lab[0], lab[1], lab[2]) print(f"Restored: {hex_from_argb(restored_argb)}") ``` -------------------------------- ### Generate Complete Material You Theme Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Use `theme_from_source_color` to generate a full Material You theme, including schemes, palettes, and custom colors. Custom colors can be harmonized with the theme or kept original. ```python from materialyoucolor.utils.theme_utils import ( theme_from_source_color, CustomColor, Theme ) from materialyoucolor.utils.color_utils import hex_from_argb # Generate complete theme from source color source = 0xff4181EE theme = theme_from_source_color(source) # Access light and dark schemes print("Light Scheme Primary:", theme.schemes["light"].primary) print("Dark Scheme Primary:", theme.schemes["dark"].primary) # Access tonal palettes print("\nPrimary Palette (key tones):") print(f" Tone 40: {hex_from_argb(theme.palettes['primary'].tone(40))}") print(f" Tone 80: {hex_from_argb(theme.palettes['primary'].tone(80))}") print("\nSecondary Palette (key tones):") print(f" Tone 40: {hex_from_argb(theme.palettes['secondary'].tone(40))}") print(f" Tone 80: {hex_from_argb(theme.palettes['secondary'].tone(80))}") # Create theme with custom brand colors custom_colors = [ CustomColor( value=0xffFF5722, # Brand orange name="brand", blend=True # Harmonize with theme ), CustomColor( value=0xff00BCD4, # Accent cyan name="accent", blend=True ), CustomColor( value=0xffB00020, # Error red (unblended) name="error", blend=False # Keep original ), ] themed = theme_from_source_color(source, custom_colors) print("\nCustom Colors:") for custom_group in themed.custom_colors: print(f"\n{custom_group.color.name}:") print(f" Original: {hex_from_argb(custom_group.color.value)}") print(f" Harmonized: {hex_from_argb(custom_group.value)}") print(f" Light - color: {custom_group.light.color}") print(f" Light - container: {custom_group.light.color_container}") print(f" Dark - color: {custom_group.dark.color}") print(f" Dark - container: {custom_group.dark.color_container}") ``` -------------------------------- ### Hct Class - Create and Manipulate HCT Colors Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Demonstrates creating HCT color objects from ARGB integers or HCT values, modifying their properties, and checking color categories. Requires importing the Hct class. ```python from materialyoucolor.hct import Hct # Create HCT from ARGB integer (0xff + hex code) # Format: 0xff4181EE where 4181EE is the hex color color_argb = 0xff4181EE hct = Hct.from_int(color_argb) print(f"Hue: {hct.hue:.1f}") # Hue: 227.0 (degrees 0-360) print(f"Chroma: {hct.chroma:.1f}") # Chroma: 67.2 (colorfulness) print(f"Tone: {hct.tone:.1f}") # Tone: 50.8 (lightness 0-100) # Create HCT from specific hue, chroma, tone values custom_hct = Hct.from_hct(hue=240.0, chroma=50.0, tone=60.0) print(f"Custom color ARGB: {custom_hct.to_int()}") # Custom color ARGB: 4287402751 print(f"Custom color RGBA: {custom_hct.to_rgba()}") # Custom color RGBA: [138, 143, 255, 255] # Modify HCT properties directly hct.hue = 180.0 # Shift to cyan hct.tone = 80.0 # Make lighter print(f"Modified: {hct}") # Modified: HCT(180, 67, 80) print(f"New ARGB: {hex(hct.to_int())}") # New ARGB: 0xffa9efed # Check color categories print(f"Is blue: {Hct.is_blue(hct.hue)}") # Is blue: False print(f"Is cyan: {Hct.is_cyan(hct.hue)}") # Is cyan: True print(f"Is yellow: {Hct.is_yellow(hct.hue)}") # Is yellow: False ``` -------------------------------- ### Configure Buildozer for Android Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Specify the materialyoucolor requirement and p4a branch in the buildozer.spec file for Android builds. ```python requirements = materialyoucolor==3.0.2 p4a.branch = develop ``` -------------------------------- ### Create Dynamic TonalSpot Scheme (Android Default) Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Creates a TonalSpot color scheme for dark mode using the 2025 spec and phone platform. Accesses colors via MaterialDynamicColors. ```python from materialyoucolor.hct import Hct from materialyoucolor.dynamiccolor.material_dynamic_colors import MaterialDynamicColors from materialyoucolor.scheme.scheme_tonal_spot import SchemeTonalSpot source_color = Hct.from_int(0xff4181EE) # Create TonalSpot scheme (Android default) with 2025 spec scheme_dark = SchemeTonalSpot( source_color_hct=source_color, is_dark=True, contrast_level=0.0, # Normal contrast (-1.0 to 1.0) spec_version="2025", # Use latest spec platform="phone" # or "watch" ) scheme_light = SchemeTonalSpot( source_color_hct=source_color, is_dark=False, contrast_level=0.0, spec_version="2025" ) # Access colors through MaterialDynamicColors mdc = MaterialDynamicColors(spec="2025") print("Dynamic TonalSpot Dark Scheme:") print(f" Primary RGBA: {mdc.primary.get_rgba(scheme_dark)}") print(f" Primary HEX: {mdc.primary.get_hex(scheme_dark)}") print(f" Surface: {mdc.surface.get_rgba(scheme_dark)}") print(f" On Surface: {mdc.onSurface.get_rgba(scheme_dark)}") ``` -------------------------------- ### Generate Material You Theme from Image Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt This function demonstrates the complete workflow of extracting colors from an image, scoring them, and generating a dynamic Material You theme for both dark and light modes. It requires an image file path and optionally a boolean for dark mode. ```python from materialyoucolor.quantize import ImageQuantizeCelebi from materialyoucolor.score.score import Score from materialyoucolor.hct import Hct from materialyoucolor.scheme.scheme_tonal_spot import SchemeTonalSpot from materialyoucolor.dynamiccolor.material_dynamic_colors import MaterialDynamicColors from materialyoucolor.dynamiccolor.color_spec import COLOR_NAMES from materialyoucolor.utils.color_utils import hex_from_argb def generate_theme_from_image(image_path: str, is_dark: bool = False): """Generate a complete Material You theme from an image.""" # Step 1: Extract colors from image quantized = ImageQuantizeCelebi(image_path, quality=5, max_colors=128) print(f"Extracted {len(quantized)} colors from image") # Step 2: Score and select best theme colors selected = Score.score(quantized) source_argb = selected[0] # Primary theme color print(f"Selected source color: {hex_from_argb(source_argb)}") # Step 3: Create HCT representation source_hct = Hct.from_int(source_argb) print(f"Source HCT: {source_hct}") # Step 4: Generate dynamic scheme scheme = SchemeTonalSpot( source_color_hct=source_hct, is_dark=is_dark, contrast_level=0.0, spec_version="2025" ) # Step 5: Get all dynamic colors mdc = MaterialDynamicColors(spec="2025") theme = {} for color_name in COLOR_NAMES: dynamic_color = getattr(mdc, color_name) theme[color_name] = { "rgba": dynamic_color.get_rgba(scheme), "hex": dynamic_color.get_hex(scheme), "argb": dynamic_color.get_argb(scheme) } return theme, selected # Generate themes dark_theme, colors = generate_theme_from_image("wallpaper.jpg", is_dark=True) light_theme, _ = generate_theme_from_image("wallpaper.jpg", is_dark=False) # Display key colors print("\nDark Theme:") for key in ["primary", "secondary", "tertiary", "surface", "background"]: print(f" {key}: {dark_theme[key]['hex']}") print("\nLight Theme:") for key in ["primary", "secondary", "tertiary", "surface", "background"]: print(f" {key}: {light_theme[key]['hex']}") # Export for CSS print("\n/* CSS Custom Properties */") print(":root {") for name, values in light_theme.items(): r, g, b, a = values["rgba"] print(f" --md-sys-color-{name}: rgb({r}, {g}, {b});") print("}") print("[data-theme='dark'] {") for name, values in dark_theme.items(): r, g, b, a = values["rgba"] print(f" --md-sys-color-{name}: rgb({r}, {g}, {b});") print("}") ``` -------------------------------- ### Compare Different Dynamic Color Scheme Variants Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Creates and compares primary colors from various scheme variants (TonalSpot, Expressive, Vibrant, Neutral, Fidelity) using MaterialDynamicColors. ```python from materialyoucolor.hct import Hct from materialyoucolor.dynamiccolor.material_dynamic_colors import MaterialDynamicColors from materialyoucolor.scheme.scheme_tonal_spot import SchemeTonalSpot from materialyoucolor.scheme.scheme_expressive import SchemeExpressive from materialyoucolor.scheme.scheme_fidelity import SchemeFidelity from materialyoucolor.scheme.scheme_vibrant import SchemeVibrant from materialyoucolor.scheme.scheme_neutral import SchemeNeutral source_color = Hct.from_int(0xff4181EE) mdc = MaterialDynamicColors(spec="2025") # Create different scheme variants for comparison schemes = { "TonalSpot": SchemeTonalSpot(source_color, True, 0.0, "2025"), "Expressive": SchemeExpressive(source_color, True, 0.0, "2025"), "Vibrant": SchemeVibrant(source_color, True, 0.0, "2025"), "Neutral": SchemeNeutral(source_color, True, 0.0, "2025"), "Fidelity": SchemeFidelity(source_color, True, 0.0), # 2021 only } for name, scheme in schemes.items(): print(f"{name} Primary: {mdc.primary.get_hex(scheme)}") ``` -------------------------------- ### Select Theme Colors with Score Class Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Analyzes quantized colors to select the best candidates for theme colors based on chroma, proportion, and hue diversity. Allows for custom scoring options. ```python from materialyoucolor.score.score import Score, ScoreOptions from materialyoucolor.utils.color_utils import hex_from_argb # Sample quantized colors (ARGB: population) quantized_colors = { 0xFF4181EE: 15000, # Blue 0xFFFF5722: 8000, # Orange 0xFF4CAF50: 5000, # Green 0xFFE91E63: 3000, # Pink 0xFF9E9E9E: 12000, # Gray (low chroma, likely filtered) 0xFF2196F3: 7000, # Light blue (similar hue to first) } # Default scoring - returns up to 4 diverse colors selected = Score.score(quantized_colors) print("Default selection:") for argb in selected: print(f" {hex_from_argb(argb)}") # Output: # Default selection: # #4181EEFF # #FF5722FF # #4CAF50FF # #E91E63FF # Custom scoring options options = ScoreOptions( desired=2, # Number of colors to return fallback_color_argb=0xFF6200EE, # Default if no valid colors filter=True # Filter low chroma colors ) selected_custom = Score.score(quantized_colors, options) print(f"\nCustom selection ({len(selected_custom)} colors):") for argb in selected_custom: print(f" {hex_from_argb(argb)}") # Disable filtering to include low-chroma colors options_no_filter = ScoreOptions(desired=4, filter=False) selected_unfiltered = Score.score(quantized_colors, options_no_filter) print(f"\nUnfiltered selection:") for argb in selected_unfiltered: print(f" {hex_from_argb(argb)}") ``` -------------------------------- ### Scheme Class - Generate Static Material Design Color Schemes Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Generates complete light and dark Material Design color schemes from a source color. Access all generated colors via the 'props' dictionary or convert the entire scheme to JSON. Requires importing the Scheme class. ```python from materialyoucolor.scheme import Scheme # Source color as ARGB integer source_color = 0xff4181EE # Blue color # Generate light scheme light_scheme = Scheme.light(source_color) print("Light Scheme Colors:") print(f" Primary: {light_scheme.props['primary']}") # RGBA list print(f" On Primary: {light_scheme.props['onPrimary']}") print(f" Primary Container: {light_scheme.props['primaryContainer']}") print(f" Background: {light_scheme.props['background']}") print(f" Surface: {light_scheme.props['surface']}") # Output: # Light Scheme Colors: # Primary: [0, 90, 195, 255] # On Primary: [255, 255, 255, 255] # Primary Container: [214, 227, 255, 255] # Background: [252, 252, 255, 255] # Surface: [252, 252, 255, 255] # Generate dark scheme dark_scheme = Scheme.dark(source_color) print("\nDark Scheme Colors:") print(f" Primary: {dark_scheme.props['primary']}") print(f" On Primary: {dark_scheme.props['onPrimary']}") print(f" Background: {dark_scheme.props['background']}") # Output: # Dark Scheme Colors: # Primary: [170, 199, 255, 255] # On Primary: [0, 46, 105, 255] # Background: [26, 27, 30, 255] # Access all properties via dictionary all_colors = light_scheme.to_json() for color_name, rgba_value in all_colors.items(): print(f" {color_name}: {rgba_value}") # Content-based schemes (preserves source color characteristics) light_content = Scheme.light_content(source_color) dark_content = Scheme.dark_content(source_color) ``` -------------------------------- ### Test Script Usage Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Command-line usage for the test script, detailing available dynamic color schemes and image processing options. ```console usage: test_all.py [-h] [--tonal-spot] [--expressive] [--fidelity] [--fruit-salad] [--monochrome] [--neutral] [--rainbow] [--vibrant] [--content] [--all] [--image IMAGE] [--quality QUALITY] [--method {pillow,cpp}] Material You Color Scheme Test options: -h, --help show this help message and exit --tonal-spot Print the tonal-spot dynamic scheme --expressive Print the expressive dynamic scheme --fidelity Print the fidelity dynamic scheme --fruit-salad Print the fruit-salad dynamic scheme --monochrome Print the monochrome dynamic scheme --neutral Print the neutral dynamic scheme --rainbow Print the rainbow dynamic scheme --vibrant Print the vibrant dynamic scheme --content Print the content dynamic scheme --all Print all dynamic schemes (default) --image IMAGE Path to an image file for color extraction --quality QUALITY Quality for image quantization (default: 5) --method {pillow,cpp} Method for color quantization (default: cpp) ``` -------------------------------- ### Generate High Contrast Dynamic Scheme Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Creates a TonalSpot color scheme with maximum contrast (contrast_level=1.0) for dark mode using the 2025 spec. ```python from materialyoucolor.hct import Hct from materialyoucolor.dynamiccolor.material_dynamic_colors import MaterialDynamicColors from materialyoucolor.scheme.scheme_tonal_spot import SchemeTonalSpot source_color = Hct.from_int(0xff4181EE) mdc = MaterialDynamicColors(spec="2025") # High contrast mode high_contrast_scheme = SchemeTonalSpot( source_color_hct=source_color, is_dark=True, contrast_level=1.0, # Maximum contrast spec_version="2025" ) print(f"High Contrast Primary: {mdc.primary.get_hex(high_contrast_scheme)}") ``` -------------------------------- ### Generate Android Light and Dark Schemes Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Generates and prints colors for Android light and dark schemes using a source color. Supports creating schemes from RGB lists. ```python from materialyoucolor.scheme.scheme_android import SchemeAndroid source_color = "0xff4181EE" # ARGB hex string # Generate Android light scheme android_light = SchemeAndroid.light(source_color) print("Android Light Scheme:") print(f" colorAccentPrimary: {android_light.props['colorAccentPrimary']}") print(f" colorAccentSecondary: {android_light.props['colorAccentSecondary']}") print(f" textColorPrimary: {android_light.props['textColorPrimary']}") print(f" colorBackground: {android_light.props['colorBackground']}") print(f" colorSurface: {android_light.props['colorSurface']}") # Generate Android dark scheme android_dark = SchemeAndroid.dark(source_color) print("\nAndroid Dark Scheme:") print(f" colorAccentPrimary: {android_dark.props['colorAccentPrimary']}") print(f" colorBackground: {android_dark.props['colorBackground']}") print(f" textColorPrimary: {android_dark.props['textColorPrimary']}") # Create from RGB list instead of ARGB rgb_color = [65, 129, 238] # RGB values android_light_rgb = SchemeAndroid.light_from_rgb(rgb_color) android_dark_rgb = SchemeAndroid.dark_from_rgb(rgb_color) # Export as JSON scheme_json = android_light.to_json() ``` -------------------------------- ### Create Tonal Palette from Hue and Chroma Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Generates a TonalPalette from a specified hue and chroma value. This palette can be used as a building block for color schemes. ```python from materialyoucolor.palettes.tonal_palette import TonalPalette from materialyoucolor.hct import Hct from materialyoucolor.utils.color_utils import rgba_from_argb, hex_from_argb # Create palette from hue and chroma blue_palette = TonalPalette.from_hue_and_chroma(hue=220.0, chroma=48.0) ``` -------------------------------- ### Color Utility Functions for ARGB Conversion Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Provides functions to convert ARGB integers to/from RGBA lists, HEX strings, and extract individual color channels (red, green, blue, alpha). Also includes utilities for L*, XYZ, and LAB color spaces. ```python from materialyoucolor.utils.color_utils import ( argb_from_rgb, argb_from_rgba, rgba_from_argb, hex_from_argb, red_from_argb, green_from_argb, blue_from_argb, alpha_from_argb, lstar_from_argb, argb_from_lstar, xyz_from_argb, argb_from_xyz, lab_from_argb, argb_from_lab, ) # ARGB integer format: 0xAARRGGBB color_argb = 0xff4181EE # Extract individual channels r = red_from_argb(color_argb) # 65 g = green_from_argb(color_argb) # 129 b = blue_from_argb(color_argb) # 238 a = alpha_from_argb(color_argb) # 255 print(f"RGBA components: ({r}, {g}, {b}, {a})") # Convert to RGBA list rgba = rgba_from_argb(color_argb) # [65, 129, 238, 255] print(f"RGBA list: {rgba}") # Convert to HEX string hex_color = hex_from_argb(color_argb) # "#4181EEFF" print(f"HEX: {hex_color}") ``` -------------------------------- ### Iterate Dynamic Color Tokens Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Iterates through the first 10 color tokens defined in COLOR_NAMES and prints their HEX values for a given dark scheme. ```python from materialyoucolor.hct import Hct from materialyoucolor.dynamiccolor.material_dynamic_colors import MaterialDynamicColors from materialyoucolor.scheme.scheme_tonal_spot import SchemeTonalSpot from materialyoucolor.dynamiccolor.color_spec import COLOR_NAMES source_color = Hct.from_int(0xff4181EE) scheme_dark = SchemeTonalSpot(source_color_hct=source_color, is_dark=True, contrast_level=0.0, spec_version="2025") mdc = MaterialDynamicColors(spec="2025") # Iterate all 60+ color tokens for color_name in COLOR_NAMES[:10]: # First 10 colors dynamic_color = getattr(mdc, color_name) print(f" {color_name}: {dynamic_color.get_hex(scheme_dark)}") ``` -------------------------------- ### SchemeAndroid Class - Generate Android-Specific Color Schemes Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Generates color schemes optimized for Android system UI, following Material You theming guidelines. Requires importing the SchemeAndroid class. ```python from materialyoucolor.scheme.scheme_android import SchemeAndroid source_color = 0xff4181EE ``` -------------------------------- ### Extract and score theme colors from an image Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Uses Celebi quantization to process an image and score the resulting colors to select the best theme palette. ```python from materialyoucolor.quantize import QuantizeCelebi, ImageQuantizeCelebi from materialyoucolor.score.score import Score # Pixel subsampling factor (quality = 1 processes all pixels) quality = 1 # Run Celebi color quantization on an image. # Returns a dict: {ARGB_color_int: population} result = ImageQuantizeCelebi( "example.jpg", quality, 128, # maximum number of colors ) print(result) # Rank and select the best theme colors. # Returns a list of ARGB color integers. selected_colors = Score.score(result) print(selected_colors) ``` -------------------------------- ### Generate Non-Dynamic Colors Source: https://github.com/t-dynamos/materialyoucolor-python/blob/main/README.md Generate static color schemes (light and dark) from an integer color representation. The 'props' attribute returns a dictionary of color names to RGBA values. ```python from materialyoucolor.scheme import Scheme from materialyoucolor.scheme.scheme_android import SchemeAndroid # Color is a an int, which is made as: # 0xff + hex_code (without #) # Eg: 0xff + #4181EE = 0xff4181EE # To convert hex to this form, do `int("0xff" + "", 16)` color = 0xff4181EE print(Scheme.light(color).props) print(Scheme.dark(color).props) # Props is a dict, key is color name and value is rgba format list # {'primary': [0, 90, 195, 255], 'onPrimary': .... # Same way for android print(SchemeAndroid.light(color).props) print(SchemeAndroid.dark(color).props) ``` -------------------------------- ### Image Color Quantization with Celebi Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Extracts dominant colors from an image using the Celebi algorithm. Supports both a high-performance C++ backend and a Python/Pillow backend for compatibility. ```python from materialyoucolor.quantize import ImageQuantizeCelebi, QuantizeCelebi from materialyoucolor.score.score import Score from materialyoucolor.utils.color_utils import rgba_from_argb, hex_from_argb # Method 1: C++ backend (recommended for performance) # Returns dict of {ARGB_color: population_count} image_path = "wallpaper.jpg" quality = 5 # Pixel sampling factor (1 = every pixel, higher = faster) max_colors = 128 # Maximum colors to extract colors = ImageQuantizeCelebi(image_path, quality, max_colors) print(f"Extracted {len(colors)} colors from image") # Display top colors by population sorted_colors = sorted(colors.items(), key=lambda x: x[1], reverse=True) print("\nTop 10 colors by frequency:") for argb, population in sorted_colors[:10]: hex_color = hex_from_argb(argb) print(f" {hex_color}: {population} pixels") # Output example: # Top 10 colors by frequency: # #2D4A5EFF: 45632 pixels # #5A8CA0FF: 32156 pixels # #1E3040FF: 28493 pixels # ... # Method 2: Python/Pillow backend (for compatibility) from PIL import Image image = Image.open(image_path) pixel_len = image.width * image.height try: image_data = image.get_flattened_data() except AttributeError: image_data = image.getdata() # Subsample pixels for performance pixels = [image_data[i] for i in range(0, pixel_len, quality)] colors_pillow = QuantizeCelebi(pixels, max_colors) # Score and select best theme colors selected_colors = Score.score(colors) print(f"\nSelected {len(selected_colors)} theme colors:") for argb in selected_colors: rgba = rgba_from_argb(argb) print(f" RGB: {rgba[:3]}, HEX: {hex_from_argb(argb)}") # Output example: # Selected 4 theme colors: # RGB: [65, 129, 238], HEX: #4181EEFF # RGB: [180, 95, 45], HEX: #B45F2DFF # RGB: [45, 120, 80], HEX: #2D7850FF # RGB: [200, 180, 50], HEX: #C8B432FF ``` -------------------------------- ### Harmonize Colors with Blend Class Source: https://context7.com/t-dynamos/materialyoucolor-python/llms.txt Use the Blend class to harmonize design colors with a theme's source color. This shifts hues towards the theme while maintaining recognizability. Supports different blending methods like HCT hue and CAM16-UCS. ```python from materialyoucolor.blend.blend import Blend from materialyoucolor.utils.color_utils import hex_from_argb, rgba_from_argb # Source/theme color theme_color = 0xff4181EE # Blue theme # Design color to harmonize (e.g., brand color, warning color) design_color = 0xffFF5722 # Deep orange # Harmonize - shifts hue towards theme while keeping recognizable harmonized = Blend.harmonize(design_color, theme_color) print(f"Original: {hex_from_argb(design_color)}") # #FF5722FF print(f"Harmonized: {hex_from_argb(harmonized)}") # Shifted towards blue print(f"Theme: {hex_from_argb(theme_color)}") # #4181EEFF # Output: # Original: #FF5722FF # Harmonized: #FF4D35FF (subtle shift towards theme hue) # Theme: #4181EEFF # HCT hue blend - interpolate hue while preserving chroma/tone blended_hue = Blend.hct_hue( from_argb=design_color, to_argb=theme_color, amount=0.5 # 0.0 = original, 1.0 = target hue ) print(f"\nHCT Hue Blend (50%): {hex_from_argb(blended_hue)}") # CAM16-UCS blend - full perceptual interpolation blended_ucs = Blend.cam16_ucs( from_argb=design_color, to_argb=theme_color, amount=0.3 # 30% towards target ) print(f"CAM16-UCS Blend (30%): {hex_from_argb(blended_ucs)}") # Create harmonized error/warning colors for a theme error_color = 0xffB00020 # Standard error red warning_color = 0xffFFC107 # Standard warning amber harmonized_error = Blend.harmonize(error_color, theme_color) harmonized_warning = Blend.harmonize(warning_color, theme_color) print(f"\nHarmonized Error: {hex_from_argb(harmonized_error)}") print(f"Harmonized Warning: {hex_from_argb(harmonized_warning)}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.