draw_shape/draw_shape.rs
1// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! A simple test program for exercising the rasterizer.
16
17extern crate font_rs;
18
19use std::io::{stdout, Write};
20
21use font_rs::geom::Point;
22use font_rs::raster::Raster;
23
24fn draw_shape(r: &mut Raster, s: f32) {
25 r.draw_line(
26 &Point {
27 x: s * 10.0,
28 y: s * 10.5,
29 },
30 &Point {
31 x: s * 20.0,
32 y: s * 150.0,
33 },
34 );
35 r.draw_line(
36 &Point {
37 x: s * 20.0,
38 y: s * 150.0,
39 },
40 &Point {
41 x: s * 50.0,
42 y: s * 139.0,
43 },
44 );
45 r.draw_quad(
46 &Point {
47 x: s * 50.0,
48 y: s * 139.0,
49 },
50 &Point {
51 x: s * 100.0,
52 y: s * 60.0,
53 },
54 &Point {
55 x: s * 10.0,
56 y: s * 10.5,
57 },
58 );
59}
60
61fn main() {
62 let w = 400;
63 let h = 400;
64 let mut r = Raster::new(w, h);
65 draw_shape(&mut r, 4.0);
66 let mut o = stdout();
67 let _ = o.write(format!("P5\n{} {}\n255\n", w, h).as_bytes());
68 let _ = o.write(&r.get_bitmap());
69}