-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
101 changed files
with
5,529 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.