processing/
color.rs

1use glium::Surface;
2
3use Screen;
4
5impl<'a> Screen<'a> {
6	/// Change the background color of the window. It takes four f32's. If color mode
7	/// is equal to "RGB", then it takes one for red, one for green, one for blue, and
8	/// one for alpha. If color mode is equal to "HSB", then the arguments are
9	/// reinterpreted as one for hue, one for saturation, one for brightness, and one
10	/// for alpha.
11    #[inline]
12    pub fn background(&mut self, r: f32, g: f32, b: f32, a: f32) {
13        let framebuffer = &mut self.fbo;
14        framebuffer.clear_color_srgb(r, g, b, a);
15    }
16
17	/// Change the color mode to "RGB" or "HSB". This causes the arguments to fill(),
18	/// stroke(), background(), and color() to be reinterpreted in the respective 
19	/// color system.
20    #[inline]
21    pub fn color_mode(&mut self, mode: &str) {
22        self.c_mode = mode.to_owned();
23    }
24
25	/// Change the color used to fill in the space bounded by shapes. For example,
26	/// setting fill to 1, 1, 1, 1 in "RGB" mode will cause the interior of a
27	/// rectangle to be white. The arguments to fill are actually slices of f32's. This
28	/// is meant to be a convenience when you know that you want to draw many of the
29	/// same kind of shape, but each with a different stroke color. Calling this
30	/// function will also undo the effect of fill_off().
31    #[inline]
32    pub fn fill(&mut self, r: &[f32], g: &[f32], b: &[f32], a: &[f32]) {
33        if self.fill_stuff == false {
34            self.fill_stuff = true;
35        }
36        if self.c_mode == "RGB" {
37            self.fill_col = vec![];
38            for x in 0..r.len() {
39                // self.fill_col.push(RGB(r[x], g[x], b[x]);
40                self.fill_col.push(r[x]);
41                self.fill_col.push(g[x]);
42                self.fill_col.push(b[x]);
43                self.fill_col.push(a[x]);
44            }
45        } else {
46        }
47    }
48
49	/// This disables filling in of shapes, such that only their outline is drawn. It
50	/// essentially acts as if the interior of a shape was transparent. Calling fill()
51	/// or fill_on() will re-enable filling in of shapes.
52    #[inline]
53    pub fn fill_off(&mut self) {
54        self.fill_stuff = false;
55    }
56
57	/// This disables the drawing of edges of shapes, such that only their interior is
58	/// drawn. It essentially acts as if the shape was one single color, with the edge
59	/// sharing that color. It's a little easier to understand with some examples
60	/// (see the Processing reference). Calling stroke() or stroke_on() will re-enable
61	/// the drawing of edges of shapes.
62    #[inline]
63    pub fn stroke_off(&mut self) {
64        self.stroke_stuff = false;
65    }
66
67	/// This undoes the effect of fill_off(), so that the interiors of shapes are drawn
68	/// again.
69    #[inline]
70    pub fn fill_on(&mut self) {
71        self.fill_stuff = true;
72    }
73	
74	/// This undoes the effect of stroke_off(), so that the edges of shapes are drawn
75	/// again.
76    #[inline]
77    pub fn stroke_on(&mut self) {
78        self.stroke_stuff = true;
79    }
80	
81	/// Change the color used to drawn the edges of shapes. For example,
82	/// setting stroke to 1, 1, 1, 1 in "RGB" mode will cause the edge of a
83	/// rectangle to be white. The arguments to stroke are actually slices of f32's.
84	/// This is meant to be a convenience when you know that you want to draw many of
85	/// the same kind of shape, but each with a different edge color. Calling this
86	/// function will also undo the effect of stroke_off().
87    #[inline]
88    pub fn stroke(&mut self, r: &[f32], g: &[f32], b: &[f32], a: &[f32]) {
89        if self.stroke_stuff == false {
90            self.stroke_stuff = true;
91        }
92        if self.c_mode == "RGB" {
93            self.stroke_col = vec![];
94            for x in 0..r.len() {
95                // self.stroke_col.push(RGB(r[x], g[x], b[x]);
96                self.stroke_col.push(r[x]);
97                self.stroke_col.push(g[x]);
98                self.stroke_col.push(b[x]);
99                self.stroke_col.push(a[x]);
100            }
101        } else {
102        }
103    }
104
105    // Creating & Reading
106
107    // #[inline]
108    // pub fn alpha(c: Color) {
109    //     c.a
110    // }
111    //
112    // #[inline]
113    // pub fn blue(c: Color) {
114    //     c.b
115    // }
116    //
117    // #[inline]
118    // pub fn brightness(c: Color) {
119    //     hsv = convert(HSV, c);
120    //     hsv.v
121    // }
122    //
123    // #[inline]
124    // pub fn color(r: f32, g: f32, b: f32) {
125    //     RGB(r, g, b)
126    // }
127    //
128    // #[inline]
129    // pub fn green(c: Color) {
130    //     c.g;
131    // }
132    //
133    // #[inline]
134    // pub fn hue(c: Color) {
135    //     hsv = convert(HSV, c);
136    //     hsv.h
137    // }
138    //
139    // #[inline]
140    // pub fn lerpColor(c1: Color, c2: Color, amt: f64) {
141    //     weighted_color_mean(amt, c1, c2);
142    // }
143    //
144    // #[inline]
145    // pub fn red(c: Color) {
146    //     c.r
147    // }
148    //
149    // #[inline]
150    // pub fn saturation(c: Color) {
151    //     hsv = convert(HSV, c);
152    //     hsv.s
153    // }
154}