Struct raqote::PathBuilder
source · pub struct PathBuilder { /* private fields */ }
Expand description
A helper struct used for constructing a Path
.
Implementations§
source§impl PathBuilder
impl PathBuilder
sourcepub fn new() -> PathBuilder
pub fn new() -> PathBuilder
Examples found in repository?
examples/stroke.rs (line 6)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
&StrokeStyle {
width: 100000., // <--
..StrokeStyle::default()
},
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
More examples
examples/stroke-arc.rs (line 7)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.arc(0., 0., 20., 0., std::f32::consts::PI);
let path = pb.finish();
dt.set_transform(&Transform::translation(50., 50.));
dt.stroke(
&path,
&Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
&StrokeStyle {
width: 40., // <--
..StrokeStyle::default()
},
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
examples/sweep-gradient.rs (line 6)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn main() {
use raqote::*;
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.rect(0., 0., 400., 400.);
let path = pb.finish();
let gradient = Source::new_sweep_gradient(
Gradient {
stops: vec![
GradientStop {
position: 0.,
color: Color::new(0xff, 0, 0, 0),
},
GradientStop {
position: 0.5,
color: Color::new(0xff, 0xff, 0xff, 0x0),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0, 0, 0x0),
},
],
},
Point::new(150., 200.),
45.,
180.+45.,
Spread::Repeat,
);
dt.fill(&path, &gradient, &DrawOptions::new());
dt.write_png("example.png");
}
examples/pad.rs (line 35)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let mut dt = DrawTarget::new(200, 200);
let gradient = Source::new_linear_gradient(
Gradient {
stops: vec![
GradientStop {
position: 0.0,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 0.9999,
color: Color::new(0xff, 0x0, 0x0, 0x0),
},
GradientStop {
position: 1.0,
color: Color::new(0xff, 0x0, 0x0, 0x0),
},
],
},
Point::new(40., 0.),
Point::new(100., 0.),
Spread::Pad,
);
let mut pb = PathBuilder::new();
pb.rect(0., 0., 80., 80.);
let path = pb.finish();
dt.fill(&path, &gradient, &DrawOptions::default());
dt.write_png("out.png").unwrap();
}
examples/capabilities.rs (line 14)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(340., 190.);
pb.arc(160., 190., 180., 0., 2. * 3.14159);
pb.close();
let path = pb.finish();
dt.push_clip(&path);
let mut pb = PathBuilder::new();
pb.move_to(0., 0.);
pb.line_to(200., 0.);
pb.line_to(200., 300.);
pb.line_to(0., 300.);
pb.close();
let path = pb.finish();
dt.fill(
&path,
&Source::Solid(SolidSource {
r: 0x80,
g: 0x80,
b: 0,
a: 0x80,
}),
&DrawOptions::new(),
);
let mut pb = PathBuilder::new();
pb.move_to(50., 50.);
pb.line_to(100., 70.);
pb.line_to(110., 150.);
pb.line_to(40., 180.);
pb.close();
/*
dt.move_to(100., 10.);
dt.quad_to(150., 40., 200., 10.);
dt.quad_to(120., 100., 80., 200.);
dt.quad_to(150., 180., 200., 200.);
dt.close();
*/
pb.move_to(100., 10.);
pb.cubic_to(150., 40., 175., 0., 200., 10.);
pb.quad_to(120., 100., 80., 200.);
pb.quad_to(150., 180., 200., 200.);
pb.close();
let path = pb.finish();
let decoder = png::Decoder::new(File::open("photo.png").unwrap());
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut buf).unwrap();
println!("{:?}", info.color_type);
let mut image: Vec<u32> = Vec::new();
for i in buf.chunks(3) {
image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
}
let _bitmap = Image {
width: info.width as i32,
height: info.height as i32,
data: &image[..],
};
//dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
//dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
let gradient = Source::RadialGradient(
Gradient {
stops: vec![
GradientStop {
position: 0.2,
color: Color::new(0xff, 0x00, 0xff, 0x00),
},
GradientStop {
position: 0.8,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0xff, 0x00, 0xff),
},
],
},
Spread::Pad,
Transform::translation(-150., -150.),
);
dt.fill(&path, &gradient, &DrawOptions::new());
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&gradient,
&StrokeStyle {
cap: LineCap::Butt,
join: LineJoin::Bevel,
width: 10.,
miter_limit: 2.,
dash_array: vec![10., 5.],
dash_offset: 3.,
},
&DrawOptions::new(),
);
let font = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
.unwrap()
.load()
.unwrap();
dt.draw_text(
&font,
24.,
"Hello",
Point::new(0., 100.),
&Source::Solid(SolidSource {
r: 0,
g: 0,
b: 0xff,
a: 0xff,
}),
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
sourcepub fn move_to(&mut self, x: f32, y: f32)
pub fn move_to(&mut self, x: f32, y: f32)
Moves the current point to x
, y
Examples found in repository?
examples/stroke.rs (line 7)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
&StrokeStyle {
width: 100000., // <--
..StrokeStyle::default()
},
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
More examples
examples/capabilities.rs (line 15)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(340., 190.);
pb.arc(160., 190., 180., 0., 2. * 3.14159);
pb.close();
let path = pb.finish();
dt.push_clip(&path);
let mut pb = PathBuilder::new();
pb.move_to(0., 0.);
pb.line_to(200., 0.);
pb.line_to(200., 300.);
pb.line_to(0., 300.);
pb.close();
let path = pb.finish();
dt.fill(
&path,
&Source::Solid(SolidSource {
r: 0x80,
g: 0x80,
b: 0,
a: 0x80,
}),
&DrawOptions::new(),
);
let mut pb = PathBuilder::new();
pb.move_to(50., 50.);
pb.line_to(100., 70.);
pb.line_to(110., 150.);
pb.line_to(40., 180.);
pb.close();
/*
dt.move_to(100., 10.);
dt.quad_to(150., 40., 200., 10.);
dt.quad_to(120., 100., 80., 200.);
dt.quad_to(150., 180., 200., 200.);
dt.close();
*/
pb.move_to(100., 10.);
pb.cubic_to(150., 40., 175., 0., 200., 10.);
pb.quad_to(120., 100., 80., 200.);
pb.quad_to(150., 180., 200., 200.);
pb.close();
let path = pb.finish();
let decoder = png::Decoder::new(File::open("photo.png").unwrap());
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut buf).unwrap();
println!("{:?}", info.color_type);
let mut image: Vec<u32> = Vec::new();
for i in buf.chunks(3) {
image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
}
let _bitmap = Image {
width: info.width as i32,
height: info.height as i32,
data: &image[..],
};
//dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
//dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
let gradient = Source::RadialGradient(
Gradient {
stops: vec![
GradientStop {
position: 0.2,
color: Color::new(0xff, 0x00, 0xff, 0x00),
},
GradientStop {
position: 0.8,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0xff, 0x00, 0xff),
},
],
},
Spread::Pad,
Transform::translation(-150., -150.),
);
dt.fill(&path, &gradient, &DrawOptions::new());
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&gradient,
&StrokeStyle {
cap: LineCap::Butt,
join: LineJoin::Bevel,
width: 10.,
miter_limit: 2.,
dash_array: vec![10., 5.],
dash_offset: 3.,
},
&DrawOptions::new(),
);
let font = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
.unwrap()
.load()
.unwrap();
dt.draw_text(
&font,
24.,
"Hello",
Point::new(0., 100.),
&Source::Solid(SolidSource {
r: 0,
g: 0,
b: 0xff,
a: 0xff,
}),
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
sourcepub fn line_to(&mut self, x: f32, y: f32)
pub fn line_to(&mut self, x: f32, y: f32)
Adds a line segment from the current point to x
, y
Examples found in repository?
examples/stroke.rs (line 8)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
&StrokeStyle {
width: 100000., // <--
..StrokeStyle::default()
},
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
More examples
examples/capabilities.rs (line 23)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(340., 190.);
pb.arc(160., 190., 180., 0., 2. * 3.14159);
pb.close();
let path = pb.finish();
dt.push_clip(&path);
let mut pb = PathBuilder::new();
pb.move_to(0., 0.);
pb.line_to(200., 0.);
pb.line_to(200., 300.);
pb.line_to(0., 300.);
pb.close();
let path = pb.finish();
dt.fill(
&path,
&Source::Solid(SolidSource {
r: 0x80,
g: 0x80,
b: 0,
a: 0x80,
}),
&DrawOptions::new(),
);
let mut pb = PathBuilder::new();
pb.move_to(50., 50.);
pb.line_to(100., 70.);
pb.line_to(110., 150.);
pb.line_to(40., 180.);
pb.close();
/*
dt.move_to(100., 10.);
dt.quad_to(150., 40., 200., 10.);
dt.quad_to(120., 100., 80., 200.);
dt.quad_to(150., 180., 200., 200.);
dt.close();
*/
pb.move_to(100., 10.);
pb.cubic_to(150., 40., 175., 0., 200., 10.);
pb.quad_to(120., 100., 80., 200.);
pb.quad_to(150., 180., 200., 200.);
pb.close();
let path = pb.finish();
let decoder = png::Decoder::new(File::open("photo.png").unwrap());
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut buf).unwrap();
println!("{:?}", info.color_type);
let mut image: Vec<u32> = Vec::new();
for i in buf.chunks(3) {
image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
}
let _bitmap = Image {
width: info.width as i32,
height: info.height as i32,
data: &image[..],
};
//dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
//dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
let gradient = Source::RadialGradient(
Gradient {
stops: vec![
GradientStop {
position: 0.2,
color: Color::new(0xff, 0x00, 0xff, 0x00),
},
GradientStop {
position: 0.8,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0xff, 0x00, 0xff),
},
],
},
Spread::Pad,
Transform::translation(-150., -150.),
);
dt.fill(&path, &gradient, &DrawOptions::new());
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&gradient,
&StrokeStyle {
cap: LineCap::Butt,
join: LineJoin::Bevel,
width: 10.,
miter_limit: 2.,
dash_array: vec![10., 5.],
dash_offset: 3.,
},
&DrawOptions::new(),
);
let font = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
.unwrap()
.load()
.unwrap();
dt.draw_text(
&font,
24.,
"Hello",
Point::new(0., 100.),
&Source::Solid(SolidSource {
r: 0,
g: 0,
b: 0xff,
a: 0xff,
}),
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
sourcepub fn quad_to(&mut self, cx: f32, cy: f32, x: f32, y: f32)
pub fn quad_to(&mut self, cx: f32, cy: f32, x: f32, y: f32)
Adds a quadratic bezier from the current point to x
, y
,
using a control point of cx
, cy
Examples found in repository?
examples/capabilities.rs (line 56)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(340., 190.);
pb.arc(160., 190., 180., 0., 2. * 3.14159);
pb.close();
let path = pb.finish();
dt.push_clip(&path);
let mut pb = PathBuilder::new();
pb.move_to(0., 0.);
pb.line_to(200., 0.);
pb.line_to(200., 300.);
pb.line_to(0., 300.);
pb.close();
let path = pb.finish();
dt.fill(
&path,
&Source::Solid(SolidSource {
r: 0x80,
g: 0x80,
b: 0,
a: 0x80,
}),
&DrawOptions::new(),
);
let mut pb = PathBuilder::new();
pb.move_to(50., 50.);
pb.line_to(100., 70.);
pb.line_to(110., 150.);
pb.line_to(40., 180.);
pb.close();
/*
dt.move_to(100., 10.);
dt.quad_to(150., 40., 200., 10.);
dt.quad_to(120., 100., 80., 200.);
dt.quad_to(150., 180., 200., 200.);
dt.close();
*/
pb.move_to(100., 10.);
pb.cubic_to(150., 40., 175., 0., 200., 10.);
pb.quad_to(120., 100., 80., 200.);
pb.quad_to(150., 180., 200., 200.);
pb.close();
let path = pb.finish();
let decoder = png::Decoder::new(File::open("photo.png").unwrap());
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut buf).unwrap();
println!("{:?}", info.color_type);
let mut image: Vec<u32> = Vec::new();
for i in buf.chunks(3) {
image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
}
let _bitmap = Image {
width: info.width as i32,
height: info.height as i32,
data: &image[..],
};
//dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
//dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
let gradient = Source::RadialGradient(
Gradient {
stops: vec![
GradientStop {
position: 0.2,
color: Color::new(0xff, 0x00, 0xff, 0x00),
},
GradientStop {
position: 0.8,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0xff, 0x00, 0xff),
},
],
},
Spread::Pad,
Transform::translation(-150., -150.),
);
dt.fill(&path, &gradient, &DrawOptions::new());
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&gradient,
&StrokeStyle {
cap: LineCap::Butt,
join: LineJoin::Bevel,
width: 10.,
miter_limit: 2.,
dash_array: vec![10., 5.],
dash_offset: 3.,
},
&DrawOptions::new(),
);
let font = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
.unwrap()
.load()
.unwrap();
dt.draw_text(
&font,
24.,
"Hello",
Point::new(0., 100.),
&Source::Solid(SolidSource {
r: 0,
g: 0,
b: 0xff,
a: 0xff,
}),
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
sourcepub fn rect(&mut self, x: f32, y: f32, width: f32, height: f32)
pub fn rect(&mut self, x: f32, y: f32, width: f32, height: f32)
Adds a rect to the path
Examples found in repository?
examples/sweep-gradient.rs (line 7)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn main() {
use raqote::*;
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.rect(0., 0., 400., 400.);
let path = pb.finish();
let gradient = Source::new_sweep_gradient(
Gradient {
stops: vec![
GradientStop {
position: 0.,
color: Color::new(0xff, 0, 0, 0),
},
GradientStop {
position: 0.5,
color: Color::new(0xff, 0xff, 0xff, 0x0),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0, 0, 0x0),
},
],
},
Point::new(150., 200.),
45.,
180.+45.,
Spread::Repeat,
);
dt.fill(&path, &gradient, &DrawOptions::new());
dt.write_png("example.png");
}
More examples
examples/pad.rs (line 36)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let mut dt = DrawTarget::new(200, 200);
let gradient = Source::new_linear_gradient(
Gradient {
stops: vec![
GradientStop {
position: 0.0,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 0.9999,
color: Color::new(0xff, 0x0, 0x0, 0x0),
},
GradientStop {
position: 1.0,
color: Color::new(0xff, 0x0, 0x0, 0x0),
},
],
},
Point::new(40., 0.),
Point::new(100., 0.),
Spread::Pad,
);
let mut pb = PathBuilder::new();
pb.rect(0., 0., 80., 80.);
let path = pb.finish();
dt.fill(&path, &gradient, &DrawOptions::default());
dt.write_png("out.png").unwrap();
}
sourcepub fn cubic_to(
&mut self,
cx1: f32,
cy1: f32,
cx2: f32,
cy2: f32,
x: f32,
y: f32
)
pub fn cubic_to( &mut self, cx1: f32, cy1: f32, cx2: f32, cy2: f32, x: f32, y: f32 )
Adds a cubic bezier from the current point to x
, y
,
using control points cx1
, cy1
and cx2
, cy2
Examples found in repository?
examples/capabilities.rs (line 55)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(340., 190.);
pb.arc(160., 190., 180., 0., 2. * 3.14159);
pb.close();
let path = pb.finish();
dt.push_clip(&path);
let mut pb = PathBuilder::new();
pb.move_to(0., 0.);
pb.line_to(200., 0.);
pb.line_to(200., 300.);
pb.line_to(0., 300.);
pb.close();
let path = pb.finish();
dt.fill(
&path,
&Source::Solid(SolidSource {
r: 0x80,
g: 0x80,
b: 0,
a: 0x80,
}),
&DrawOptions::new(),
);
let mut pb = PathBuilder::new();
pb.move_to(50., 50.);
pb.line_to(100., 70.);
pb.line_to(110., 150.);
pb.line_to(40., 180.);
pb.close();
/*
dt.move_to(100., 10.);
dt.quad_to(150., 40., 200., 10.);
dt.quad_to(120., 100., 80., 200.);
dt.quad_to(150., 180., 200., 200.);
dt.close();
*/
pb.move_to(100., 10.);
pb.cubic_to(150., 40., 175., 0., 200., 10.);
pb.quad_to(120., 100., 80., 200.);
pb.quad_to(150., 180., 200., 200.);
pb.close();
let path = pb.finish();
let decoder = png::Decoder::new(File::open("photo.png").unwrap());
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut buf).unwrap();
println!("{:?}", info.color_type);
let mut image: Vec<u32> = Vec::new();
for i in buf.chunks(3) {
image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
}
let _bitmap = Image {
width: info.width as i32,
height: info.height as i32,
data: &image[..],
};
//dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
//dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
let gradient = Source::RadialGradient(
Gradient {
stops: vec![
GradientStop {
position: 0.2,
color: Color::new(0xff, 0x00, 0xff, 0x00),
},
GradientStop {
position: 0.8,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0xff, 0x00, 0xff),
},
],
},
Spread::Pad,
Transform::translation(-150., -150.),
);
dt.fill(&path, &gradient, &DrawOptions::new());
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&gradient,
&StrokeStyle {
cap: LineCap::Butt,
join: LineJoin::Bevel,
width: 10.,
miter_limit: 2.,
dash_array: vec![10., 5.],
dash_offset: 3.,
},
&DrawOptions::new(),
);
let font = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
.unwrap()
.load()
.unwrap();
dt.draw_text(
&font,
24.,
"Hello",
Point::new(0., 100.),
&Source::Solid(SolidSource {
r: 0,
g: 0,
b: 0xff,
a: 0xff,
}),
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
sourcepub fn close(&mut self)
pub fn close(&mut self)
Closes the current subpath
Examples found in repository?
examples/capabilities.rs (line 17)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(340., 190.);
pb.arc(160., 190., 180., 0., 2. * 3.14159);
pb.close();
let path = pb.finish();
dt.push_clip(&path);
let mut pb = PathBuilder::new();
pb.move_to(0., 0.);
pb.line_to(200., 0.);
pb.line_to(200., 300.);
pb.line_to(0., 300.);
pb.close();
let path = pb.finish();
dt.fill(
&path,
&Source::Solid(SolidSource {
r: 0x80,
g: 0x80,
b: 0,
a: 0x80,
}),
&DrawOptions::new(),
);
let mut pb = PathBuilder::new();
pb.move_to(50., 50.);
pb.line_to(100., 70.);
pb.line_to(110., 150.);
pb.line_to(40., 180.);
pb.close();
/*
dt.move_to(100., 10.);
dt.quad_to(150., 40., 200., 10.);
dt.quad_to(120., 100., 80., 200.);
dt.quad_to(150., 180., 200., 200.);
dt.close();
*/
pb.move_to(100., 10.);
pb.cubic_to(150., 40., 175., 0., 200., 10.);
pb.quad_to(120., 100., 80., 200.);
pb.quad_to(150., 180., 200., 200.);
pb.close();
let path = pb.finish();
let decoder = png::Decoder::new(File::open("photo.png").unwrap());
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut buf).unwrap();
println!("{:?}", info.color_type);
let mut image: Vec<u32> = Vec::new();
for i in buf.chunks(3) {
image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
}
let _bitmap = Image {
width: info.width as i32,
height: info.height as i32,
data: &image[..],
};
//dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
//dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
let gradient = Source::RadialGradient(
Gradient {
stops: vec![
GradientStop {
position: 0.2,
color: Color::new(0xff, 0x00, 0xff, 0x00),
},
GradientStop {
position: 0.8,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0xff, 0x00, 0xff),
},
],
},
Spread::Pad,
Transform::translation(-150., -150.),
);
dt.fill(&path, &gradient, &DrawOptions::new());
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&gradient,
&StrokeStyle {
cap: LineCap::Butt,
join: LineJoin::Bevel,
width: 10.,
miter_limit: 2.,
dash_array: vec![10., 5.],
dash_offset: 3.,
},
&DrawOptions::new(),
);
let font = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
.unwrap()
.load()
.unwrap();
dt.draw_text(
&font,
24.,
"Hello",
Point::new(0., 100.),
&Source::Solid(SolidSource {
r: 0,
g: 0,
b: 0xff,
a: 0xff,
}),
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
sourcepub fn arc(
&mut self,
x: f32,
y: f32,
r: f32,
start_angle: f32,
sweep_angle: f32
)
pub fn arc( &mut self, x: f32, y: f32, r: f32, start_angle: f32, sweep_angle: f32 )
Adds an arc approximated by quadratic beziers with center x
, y
and radius r
starting at start_angle
and sweeping by sweep_angle
.
For a positive sweep_angle
the sweep is done clockwise, for a negative
sweep_angle
the sweep is done counterclockwise.
Examples found in repository?
examples/stroke-arc.rs (line 8)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.arc(0., 0., 20., 0., std::f32::consts::PI);
let path = pb.finish();
dt.set_transform(&Transform::translation(50., 50.));
dt.stroke(
&path,
&Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
&StrokeStyle {
width: 40., // <--
..StrokeStyle::default()
},
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
More examples
examples/capabilities.rs (line 16)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(340., 190.);
pb.arc(160., 190., 180., 0., 2. * 3.14159);
pb.close();
let path = pb.finish();
dt.push_clip(&path);
let mut pb = PathBuilder::new();
pb.move_to(0., 0.);
pb.line_to(200., 0.);
pb.line_to(200., 300.);
pb.line_to(0., 300.);
pb.close();
let path = pb.finish();
dt.fill(
&path,
&Source::Solid(SolidSource {
r: 0x80,
g: 0x80,
b: 0,
a: 0x80,
}),
&DrawOptions::new(),
);
let mut pb = PathBuilder::new();
pb.move_to(50., 50.);
pb.line_to(100., 70.);
pb.line_to(110., 150.);
pb.line_to(40., 180.);
pb.close();
/*
dt.move_to(100., 10.);
dt.quad_to(150., 40., 200., 10.);
dt.quad_to(120., 100., 80., 200.);
dt.quad_to(150., 180., 200., 200.);
dt.close();
*/
pb.move_to(100., 10.);
pb.cubic_to(150., 40., 175., 0., 200., 10.);
pb.quad_to(120., 100., 80., 200.);
pb.quad_to(150., 180., 200., 200.);
pb.close();
let path = pb.finish();
let decoder = png::Decoder::new(File::open("photo.png").unwrap());
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut buf).unwrap();
println!("{:?}", info.color_type);
let mut image: Vec<u32> = Vec::new();
for i in buf.chunks(3) {
image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
}
let _bitmap = Image {
width: info.width as i32,
height: info.height as i32,
data: &image[..],
};
//dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
//dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
let gradient = Source::RadialGradient(
Gradient {
stops: vec![
GradientStop {
position: 0.2,
color: Color::new(0xff, 0x00, 0xff, 0x00),
},
GradientStop {
position: 0.8,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0xff, 0x00, 0xff),
},
],
},
Spread::Pad,
Transform::translation(-150., -150.),
);
dt.fill(&path, &gradient, &DrawOptions::new());
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&gradient,
&StrokeStyle {
cap: LineCap::Butt,
join: LineJoin::Bevel,
width: 10.,
miter_limit: 2.,
dash_array: vec![10., 5.],
dash_offset: 3.,
},
&DrawOptions::new(),
);
let font = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
.unwrap()
.load()
.unwrap();
dt.draw_text(
&font,
24.,
"Hello",
Point::new(0., 100.),
&Source::Solid(SolidSource {
r: 0,
g: 0,
b: 0xff,
a: 0xff,
}),
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
sourcepub fn finish(self) -> Path
pub fn finish(self) -> Path
Completes the current path
Examples found in repository?
examples/stroke.rs (line 11)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
&StrokeStyle {
width: 100000., // <--
..StrokeStyle::default()
},
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
More examples
examples/stroke-arc.rs (line 10)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.arc(0., 0., 20., 0., std::f32::consts::PI);
let path = pb.finish();
dt.set_transform(&Transform::translation(50., 50.));
dt.stroke(
&path,
&Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
&StrokeStyle {
width: 40., // <--
..StrokeStyle::default()
},
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
examples/sweep-gradient.rs (line 8)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn main() {
use raqote::*;
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.rect(0., 0., 400., 400.);
let path = pb.finish();
let gradient = Source::new_sweep_gradient(
Gradient {
stops: vec![
GradientStop {
position: 0.,
color: Color::new(0xff, 0, 0, 0),
},
GradientStop {
position: 0.5,
color: Color::new(0xff, 0xff, 0xff, 0x0),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0, 0, 0x0),
},
],
},
Point::new(150., 200.),
45.,
180.+45.,
Spread::Repeat,
);
dt.fill(&path, &gradient, &DrawOptions::new());
dt.write_png("example.png");
}
examples/pad.rs (line 37)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let mut dt = DrawTarget::new(200, 200);
let gradient = Source::new_linear_gradient(
Gradient {
stops: vec![
GradientStop {
position: 0.0,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 0.9999,
color: Color::new(0xff, 0x0, 0x0, 0x0),
},
GradientStop {
position: 1.0,
color: Color::new(0xff, 0x0, 0x0, 0x0),
},
],
},
Point::new(40., 0.),
Point::new(100., 0.),
Spread::Pad,
);
let mut pb = PathBuilder::new();
pb.rect(0., 0., 80., 80.);
let path = pb.finish();
dt.fill(&path, &gradient, &DrawOptions::default());
dt.write_png("out.png").unwrap();
}
examples/capabilities.rs (line 18)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(340., 190.);
pb.arc(160., 190., 180., 0., 2. * 3.14159);
pb.close();
let path = pb.finish();
dt.push_clip(&path);
let mut pb = PathBuilder::new();
pb.move_to(0., 0.);
pb.line_to(200., 0.);
pb.line_to(200., 300.);
pb.line_to(0., 300.);
pb.close();
let path = pb.finish();
dt.fill(
&path,
&Source::Solid(SolidSource {
r: 0x80,
g: 0x80,
b: 0,
a: 0x80,
}),
&DrawOptions::new(),
);
let mut pb = PathBuilder::new();
pb.move_to(50., 50.);
pb.line_to(100., 70.);
pb.line_to(110., 150.);
pb.line_to(40., 180.);
pb.close();
/*
dt.move_to(100., 10.);
dt.quad_to(150., 40., 200., 10.);
dt.quad_to(120., 100., 80., 200.);
dt.quad_to(150., 180., 200., 200.);
dt.close();
*/
pb.move_to(100., 10.);
pb.cubic_to(150., 40., 175., 0., 200., 10.);
pb.quad_to(120., 100., 80., 200.);
pb.quad_to(150., 180., 200., 200.);
pb.close();
let path = pb.finish();
let decoder = png::Decoder::new(File::open("photo.png").unwrap());
let mut reader = decoder.read_info().unwrap();
let mut buf = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut buf).unwrap();
println!("{:?}", info.color_type);
let mut image: Vec<u32> = Vec::new();
for i in buf.chunks(3) {
image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
}
let _bitmap = Image {
width: info.width as i32,
height: info.height as i32,
data: &image[..],
};
//dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
//dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
let gradient = Source::RadialGradient(
Gradient {
stops: vec![
GradientStop {
position: 0.2,
color: Color::new(0xff, 0x00, 0xff, 0x00),
},
GradientStop {
position: 0.8,
color: Color::new(0xff, 0xff, 0xff, 0xff),
},
GradientStop {
position: 1.,
color: Color::new(0xff, 0xff, 0x00, 0xff),
},
],
},
Spread::Pad,
Transform::translation(-150., -150.),
);
dt.fill(&path, &gradient, &DrawOptions::new());
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&gradient,
&StrokeStyle {
cap: LineCap::Butt,
join: LineJoin::Bevel,
width: 10.,
miter_limit: 2.,
dash_array: vec![10., 5.],
dash_offset: 3.,
},
&DrawOptions::new(),
);
let font = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
.unwrap()
.load()
.unwrap();
dt.draw_text(
&font,
24.,
"Hello",
Point::new(0., 100.),
&Source::Solid(SolidSource {
r: 0,
g: 0,
b: 0xff,
a: 0xff,
}),
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PathBuilder
impl RefUnwindSafe for PathBuilder
impl Send for PathBuilder
impl Sync for PathBuilder
impl Unpin for PathBuilder
impl UnwindSafe for PathBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more