{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "// https://en.wikipedia.org/wiki/RGBA_color_model#Representation\n", "\n", "const INT: u32 = 0xAABBCCDD;\n", "\n", "let r = (INT >> 24) as u8;\n", "let g = (INT >> 16) as u8;\n", "let b = (INT >> 8) as u8;\n", "let a = INT as u8;\n", "\n", "println!(\"r: {}, g: {}, b: {}, a: {}\", r, g, b, a);\n", "println!();\n", "println!(\"r: {:02X}\", r);\n", "println!(\" {:b}\", r);\n", "println!(\"g: {:02X}\", g);\n", "println!(\" {:b}\", g);\n", "println!(\"b: {:02X}\", b);\n", "println!(\" {:b}\", b);\n", "println!(\"a: {:02X}\", a);\n", "println!(\" {:b}\", a);\n", "\n", "println!(\"\\nHexadecimal components:\");\n", "\n", "let rr = (r as u32) << 24;\n", "let gg = (g as u32) << 16;\n", "let bb = (b as u32) << 8;\n", "let aa = (a as u32);\n", "\n", "println!(\"r: {:08X}\", rr);\n", "println!(\"g: {:08X}\", gg);\n", "println!(\"b: {:08X}\", bb);\n", "println!(\"a: {:08X}\", aa);\n", "\n", "println!(\"\\nEncode:\");\n", "\n", "let rgba = rr | gg | bb | aa;\n", "\n", "println!(\"{:08X}\", rgba);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "println!(\"{:X}\", 0xFFFFFF);\n", "println!(\"{:X}\", 0x000FFF);\n", "println!(\"{:06X}\", 0x000FFF);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ ":dep sorbet-color = { path = \"..\" }\n", "\n", "use sorbet_color::{*, named::*};" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "let blueviolet_rgb = Rgb::from(BLUEVIOLET);\n", "let blueviolet_rgba = Rgba::from(BLUEVIOLET);\n", "\n", "println!(\"#{:08X}\", BLUEVIOLET);\n", "println!(\"{}\", blueviolet_rgb);\n", "println!(\"{}\", blueviolet_rgba);\n", "println!(\"{:?}\", <[u8; 3]>::from(blueviolet_rgb));\n", "println!(\"{:?}\", <[u8; 4]>::from(blueviolet_rgba));" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "ename": "", "evalue": "", "output_type": "error", "traceback": [ "\u001b[1;31mFailed to start the Kernel. \n", "Unhandled error. \n", "View Jupyter log for further details." ] } ], "source": [ "println!(\"{v} => {v:.3}\", v = 99.001);" ] } ], "metadata": { "interpreter": { "hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a" }, "kernelspec": { "display_name": "Rust", "language": "rust", "name": "rust" }, "language_info": { "codemirror_mode": "rust", "file_extension": ".rs", "mimetype": "text/rust", "name": "rust", "pygment_lexer": "rust", "version": "" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }