Code Monkey home page Code Monkey logo

raqote's Introduction

raqote

Build Status Crates.io Documentation

A pure Rust 2D Graphics Library.

Raqote is a small, simple, fast software 2D graphics library.

Current functionality

  • path filling
  • stroking
  • dashing
  • image, solid, and gradient fills
  • rectangular and path clipping
  • blend modes
  • layers
  • repeat modes for images
  • global alpha

Notable users

  • resvg supports using raqote as a backend.
  • Servo uses raqote as its canvas backend.
  • orbtk uses raqote.

Example:

A simple example drawing to a window

Another example drawing to a png follows:

use raqote::*;

let mut dt = DrawTarget::new(400, 400);

let mut pb = PathBuilder::new();
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., 300., 300.);
pb.close();
let path = pb.finish();

let gradient = Source::new_radial_gradient(
    Gradient {
        stops: vec![
            GradientStop {
                position: 0.2,
                color: Color::new(0xff, 0, 0xff, 0),
            },
            GradientStop {
                position: 0.8,
                color: Color::new(0xff, 0xff, 0xff, 0xff),
            },
            GradientStop {
                position: 1.,
                color: Color::new(0xff, 0xff, 0, 0xff),
            },
        ],
    },
    Point::new(150., 150.),
    128.,
    Spread::Pad,
);
dt.fill(&path, &gradient, &DrawOptions::new());

let mut pb = PathBuilder::new();
pb.move_to(100., 100.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();

dt.stroke(
    &path,
    &Source::Solid(SolidSource {
        r: 0x0,
        g: 0x0,
        b: 0x80,
        a: 0x80,
    }),
    &StrokeStyle {
        cap: LineCap::Round,
        join: LineJoin::Round,
        width: 10.,
        miter_limit: 2.,
        dash_array: vec![10., 18.],
        dash_offset: 16.,
    },
    &DrawOptions::new()
);

dt.write_png("example.png");

Produces:

example.png

raqote's People

Contributors

jrmuizel avatar razrfalcon avatar eijebong avatar cbrewster avatar jdm avatar de-vri-es avatar nical avatar dralley avatar danieldg avatar dylanmcdiarmid avatar emilio avatar parasyte avatar ameliabradley avatar ricmzn avatar shnatsel avatar simonsapin avatar cellfusion avatar kaiakz avatar pylbrecht avatar

Stargazers

Lura avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.