FLUTTER ECOSYSTEM

sergiandreplace/flutter_rough

rough.js 라이브러리의 플러터 구현

flutter_rough 프로젝트 이미지
Stars
90
Forks
11
최근 푸시(UTC)
2021. 12. 31.
프로젝트 상태
활성
Sergi Martínez GitHub avatar
GITHUB User

Sergi Martínez ↗

언어DartKotlinSwiftShellObjective-C

기술 주제

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 3 개
  • flutter{"sdk":"flutter"}
  • flutter_test개발 의존성{"sdk":"flutter"}
  • extra_pedantic개발 의존성1.2.0

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

Pub GitHub Release Date GitHub

Rough

Rough is a library that allows you draw in a sketchy, hand-drawn-like style. It's a direct port of Rough.js.

Installation

In the dependencies: section of your pubspec.yaml, add the following line:

dependencies:
  rough: <latest_version>

Basic usage

Right now only drawing via canvas is supported. This is a basic documentation in case you want to play around with Rough. I can't ensure non-breaking changes of the library interface.

To draw a figure you have to:

  1. Create a DrawConfig object to determine how your drawing will look.
  2. Create a Filler to be used when drawing objects (you have to provide a configuration for the filling and a DrawConfig for the filling path).
  3. Create a Generator object using the created DrawConfig and Filler. This will define a drawing/filling style.
  4. Invoke the drawing method from the Generator to create a Drawable.
  5. Paint the Drawable in the canvas using the drawRough method extension for Canvas.

Here an example on how to draw a circle:

//Create a `DrawConfig` object.
DrawConfig myDrawConfig = DrawConfig.build(
  roughness: 3,
  curveStepCount: 14,
  maxRandomnessOffset: 3,
);

//Create a `Filler` with a configuration (we reuse the drawConfig in this case).
FillerConfig myFillerConfig = FillerConfig(
    hachureGap: 8,
    hachureAngle: -20,
    drawConfig: myDrawConfig,
);
Filler myFiller = ZigZagFiller(myFillerConfig);

//Create a `Generator` with the created `DrawConfig` and `Filler`
Generator generator = Generator(
  myDrawConfig,
  myFiller,
);

//4. Build a circle `Drawable`.
Drawable figure = generator.circle(200, 200, 320);

//5. Paint the `Drawable` in the canvas.
Canvas.drawRough(figure, pathPaint, fillPaint);

And this is the result:

Result

Both DrawConfig and FillerConfig will use default values for anything not specified.

Samples

Some screenshots of the example app:

Example 1 Example 2 Example 3 Example 4