Skip to content

Commit

Permalink
v0.2.1 (#16)
Browse files Browse the repository at this point in the history
* v0.2.1
  • Loading branch information
dudochkin-victor authored Jan 6, 2022
1 parent c4f1d48 commit 0d28292
Show file tree
Hide file tree
Showing 101 changed files with 5,529 additions and 206 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ux-primitives"
version = "0.1.4"
version = "0.2.1"
authors = ["Victor Dudochkin <[email protected]>"]
readme = "README.md"
homepage = "https://angular-rust.github.io/ux-primitives"
Expand Down
72 changes: 58 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,70 @@
[loc-badge]: https://img.shields.io/tokei/lines/github/angular-rust/ux-primitives?style=flat-square
[loc-url]: https://github.com/angular-rust/ux-primitives

UX Primitives is a core graphic and color abstraction for Angular Rust.
UX Primitives is a powerful library for working with color and graphics. It is one of the main building blocks of the Angular Rust framework. This library is well organized and easy to use.

**Angular Rust** is a high productivity, `platform-agnostic` frontend framework for the [Rust language](https://www.rust-lang.org/). It now supports desktop and web development. Angular Rust currently uses Clutter for desktop development and WebAssembly for web development. We are planning to add support for mobile development.
## Quick Start

Add UX primitives to your project using Cargo-edit or by editing the Cargo.toml file:

cargo add ux-primitives

### Basic usage

```rust
use primitives::prelude::*;

use primitives::foundation::{colorschemes::Tetrad, colorspace::HslColor};

fn main() {
// Get Palette Color
let base = color::TEAL_9;

println!("Base color {}", base.to_hex_string());

println!("Lighten {}", base.lighten(10.0).to_hex_string());

println!("Darken {}", base.darken(10.0).to_hex_string());

println!("Hue Adjusted {}", base.adjust_hue(90.).to_hex_string());

println!("Complement {}", base.complement().to_hex_string());

![Angular Rust structure](https://dudochkin-victor.github.io/assets/angular-rust/structure.svg)
println!("Inverted {}", base.invert().to_hex_string());

println!("Saturated {}", base.saturate(50.).to_hex_string());

println!("Desaturated {}", base.desaturate(50.).to_hex_string());

println!("Grayscale {}", base.grayscale().to_hex_string());

let hsl: HslColor = base.into();

println!("{} {}", base, hsl);

// Generate color scheme
let scheme = Tetrad::new(base);
// You can adjust color scheme parameters before get colors
println!();

for idx in 0..scheme.num_of_colors() {
match scheme.get_color(idx) {
Some(col) => println!("Color: {}", col.to_hex_string()),
None => println!("No color")
}
}
}
```

## Features

- [x] Graphic abstraction for cairo and web canvas, implemented in [UX Animate](https://github.com/angular-rust/ux-animate)
- [x] Most used color spaces: RGB, RGBA, HSL, HSV, LAB, CMY, CMYK
- [x] Graphic abstraction for native and web canvas implemented in [UX Animate](https://github.com/angular-rust/ux-animate)
- [x] The most commonly used color spaces: RGB, RGBA, HSL, HSV, LAB, CMY, CMYK.
- [x] Color conversion: RGB to HSL, etc.
- [x] Support for color quantization to make the color closer to the palette
- [x] Palette `Open Color`

- [x] Support for color quantization to bring the color closer to the palette.
- [x] Palette [Open Color](https://github.com/yeun/open-color) (4.5 thousand stars)
- [x] Generation of color scheme according to [color theory](http://en.wikipedia.org/wiki/Color_theory).
- [x] Basic traits for interactive applications (WIP).

## Color scheme for UI design

Expand All @@ -55,12 +105,6 @@ UX Primitives contain powerfull palette for easy of use and more professional lo

![available colors](https://dudochkin-victor.github.io/assets/ux-primitives/open-color.svg)

## Quick Start

Install UX Primitives:

cargo add ux-primitives

## Learn More

* [Manual, Docs, etc](https://angular-rust.github.io/)
Expand Down
61 changes: 0 additions & 61 deletions src/colorspace/mod.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
100 changes: 100 additions & 0 deletions src/foundation/colorschemes/analogous.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#![allow(unused_imports)]
use crate::foundation::colorspace::{Color, HsvColor};

use super::ryb_rotate;

/// The analog colors are those colors which lie on either side of any given color.
///
/// Often these are color schemes found in nature.
/// An application that makes use of analogous colors usually feels harmonious.
/// The secondary color, as described above, can often be an analogous color.
#[derive(Debug, Clone)]
pub struct Analogous {
angle: f32,
contrast: f32,

colors: Vec<Color>,
primary_color: Color,
}

impl Analogous {
/// Generate Analogous scheme with your color, 10 degree angle and 25 percent of contrast
pub fn new(primary: Color) -> Self {
Self::with_parameters(primary, Some(10.0), Some(25.0))
}

pub fn with_parameters(primary: Color, angle: Option<f32>, contrast: Option<f32>) -> Self {
let mut instance = Self {
colors: Vec::new(),
primary_color: primary,
angle: angle.unwrap_or(10.0),
contrast: contrast.unwrap_or(25.0),
};
instance.generate();

instance
}

fn generate(&mut self) {
self.colors = vec![self.primary_color];
let primary_hsb: HsvColor = self.primary_color.into();

const ARRAY: [[f32; 2]; 4] = [[1.0, 2.2], [2.0, 1.0], [-1.0, -0.5], [-2.0, 1.0]];

for idx in 0..ARRAY.len() {
let one = ARRAY[idx][0];
let two = ARRAY[idx][1];

// set hue
let mut new_hsb: HsvColor = ryb_rotate(primary_hsb.into(), self.angle * one);

// value is brightness
let t: f32 = 0.44 - two * 0.1;
if primary_hsb.value - self.contrast * two < t {
new_hsb.value = t * 100.0;
} else {
new_hsb.value = primary_hsb.value - self.contrast * two;
}

// set saturation
new_hsb.saturation -= 5.0;

self.colors.push(new_hsb.into());
}
}

pub fn angle(&self) -> f32 {
self.angle
}

pub fn set_angle(&mut self, value: f32) {
self.angle = value;
self.generate();
}

pub fn contrast(&self) -> f32 {
self.contrast
}

pub fn set_contrast(&mut self, value: f32) {
self.contrast = value;
self.generate();
}

pub fn num_of_colors(&self) -> usize {
self.colors.len()
}

pub fn get_color(&self, index: usize) -> Option<Color> {
self.colors.get(index).copied()
}

pub fn primary_color(&self) -> Color {
self.primary_color
}

pub fn set_primary_color(&mut self, value: Color) {
self.primary_color = value;
self.generate();
}
}
87 changes: 87 additions & 0 deletions src/foundation/colorschemes/complementary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#![allow(unused_imports)]
use crate::foundation::colorspace::{Color, HsvColor};

use super::ryb_rotate;

/// The complementary colors are the colors which are directly opposite from one another on the color wheel.
///
/// Complementary colors are contrasting and stand out against each other.
/// Often it is a good idea to use a complementary color as the highlight color, as described above.
#[derive(Debug, Clone)]
pub struct Complementary {
colors: Vec<Color>,
primary_color: Color,
}

impl Complementary {
pub fn new(primary: Color) -> Self {
let mut instance = Self {
colors: Vec::new(),
primary_color: primary,
};
instance.generate();

instance
}

fn generate(&mut self) {
self.colors = vec![self.primary_color];

let primary_hsb: HsvColor = self.primary_color.into();

let mut contrasting: HsvColor = primary_hsb;

// value is brightness
if primary_hsb.value > 40.0 {
contrasting.value = 10.0 + primary_hsb.value * 0.25;
} else {
contrasting.value = 100.0 - primary_hsb.value * 0.25;
}
self.colors.push(contrasting.into());

// supporting
let mut supporting: HsvColor = primary_hsb;

supporting.value = 30.0 + primary_hsb.value;
supporting.saturation = 10.0 + primary_hsb.saturation * 0.3;
self.colors.push(supporting.into());

// complement
let complement: HsvColor = ryb_rotate(self.primary_color, 180.0);
self.colors.push(complement.into());

// contrasting complement
let mut contrasting_complement: HsvColor = complement.clone();

if complement.value > 30.0 {
contrasting_complement.value = 10.0 + complement.value * 0.25;
} else {
contrasting_complement.value = 100.0 - complement.value * 0.25;
}
self.colors.push(contrasting_complement.into());

// supporting complement
let mut supporting_complement: HsvColor = complement;

supporting_complement.value = 30.0 + complement.value;
supporting_complement.saturation = 10.0 + complement.saturation * 0.3;
self.colors.push(supporting_complement.into());
}

pub fn num_of_colors(&self) -> usize {
self.colors.len()
}

pub fn get_color(&self, index: usize) -> Option<Color> {
self.colors.get(index).copied()
}

pub fn primary_color(&self) -> Color {
self.primary_color
}

pub fn set_primary_color(&mut self, val: Color) {
self.primary_color = val;
self.generate();
}
}
Loading

0 comments on commit 0d28292

Please sign in to comment.