import streamlit as st import matplotlib.pyplot as plt import matplotlib.colors as mcolors import numpy as np def mix_colors(color1, color2, ratio): # Convert color strings to RGB values color1_rgb = np.array(mcolors.to_rgb(color1)) color2_rgb = np.array(mcolors.to_rgb(color2)) # Mix colors based on the given ratio mixed_color = ratio * color1_rgb + (1 - ratio) * color2_rgb return mixed_color def display_mixed_color(color1, color2, ratio): # Create a color mixing chart fig, ax = plt.subplots() gradient = np.linspace(0, 1, 100) colors = [mix_colors(color1, color2, r) for r in gradient] ax.imshow([colors], aspect='auto', cmap='viridis') ax.axis('off') st.pyplot(fig) def main(): st.title("Color Mixing Debugger") st.write("Generate intermediate color tones by adjusting colors and mixing ratio.") # Select colors color1 = st.color_picker("Select Color 1", "#FF0000") color2 = st.color_picker("Select Color 2", "#0000FF") # Select mixing ratio ratio = st.slider("Select Mixing Ratio", 0.0, 1.0, 0.5, 0.1) # Display mixed color mixed_color = mix_colors(color1, color2, ratio) st.write("Mixed Color:", mixed_color) st.write("Mixed Color Example:") display_mixed_color(color1, color2, ratio) if __name__ == "__main__": main()
基于Streamlit的颜色混合调试
最新推荐文章于 2024-08-04 01:15:42 发布
这篇博客介绍了一个基于Streamlit的应用,用于调试和混合两种颜色。用户可以选择颜色1和颜色2,然后通过调整混合比例来生成中间色调。应用中包含了颜色选择器和滑块来控制混合比例,并实时显示混合结果。
摘要由CSDN通过智能技术生成