Giter Club home page Giter Club logo

maliang's Introduction

MaLiang

CI Status Version License Platform

🎉 MaLiang is on Metal now!

MaLiang is a painting framework based on Metal. The name of "MaLiang" comes from a boy who had a magical brush in Chinese ancient fairy story.

Simplified Chinese

Requirements

iOS 9.0+, Swift 4.2+

The core painting module is based on Metal

You can simply make it compatible with lower version of iOS and swift by changing only serval lines of code.

Installation

MaLiang is available through CocoaPods. To install it, simply add the following line to your Podfile:

# 2.0.0 is currently in beta testing
pod 'MaLiang', '~> 2.0.0-beta-2'

To use the old OpenGL ES verion:

pod 'MaLiang', '~> 1.1'

Usage

MaLiang is simple to use.

  1. import MaLiang
  2. enjoy painting!

Canvas

open class Canvas: MLView

A Canvas is the basic component of MaLiang. You will paint all things on it. Canvas extends from MetalView, whitch extends from MTKView. MetalView handles all the logic with MetalKit and hides them from you.

Canvas can be simply created with xib or code.

  • with xib or storyboard, simply drag and drop an UIView object into your view controller and change it's class to Canvas and module to MaLiang
  • with code, just create with init(frame:) as any UIView you do before.

Now, all things necessary is done!

Snapshot

You can take snapshot on canvas now. Just call snapshot function on Canvas and you will get an optional UIImage object.

Brush

With all things done, you can do more with Brush!

Brush is the key feature to MaLiang. It holds textures and colors, whitch makes it possiable to paint amazing things.

Register a Brush with image data or file to Canvas and paint with it:

let path = Bundle.main.path(forResource: "pencil", ofType: "png")!
let pencil = try? canvas.registerBrush(with: URL(fileURLWithPath: path))
pencil?.use()

Brush have serval properties for you to custmize:

// opacity of texture, affects the darkness of stroke
// set opacity to 1 may cause heavy aliasing
open var opacity: CGFloat = 0.3

// width of stroke line in points
open var pointSize: CGFloat = 4

// this property defines the minimum distance (measureed in points) of nearest two textures
// defaults to 1, this means erery texture calculated will be rendered, dictance calculation will be skiped
open var pointStep: CGFloat = 1

// sensitive of pointsize changed from force, from 0 - 1
open var forceSensitive: CGFloat = 0

/// color of stroke
open var color: UIColor = .black

With all these properties, you can create you own brush as your imagination.

Force & 3D Touch

MaLiang supports automatically adjustment of stroke size with painting force. 3D Touch is supported by default, and simulated force will be setup on devices those are not supporting this.

forceSensitive is the property that force affects the storke size. It should be set between 0 to 1. the smaller the value is, the less sensitive will be. if sets to 0, then force will not affects the stroke size.

Document

Document is now configured by default. It holds all the data on the Canvas, and makes the undo and redo actions to be possiable.
And you can implement your own saving logic with the data holds by Document.

TODO

  • Port to Metal
  • Undo & Redo
  • Export to image
  • Optimize for scale
  • Optimize for saving logic
  • Glow style line
  • Text element
  • Image element
  • Texture rotation

License

MaLiang is available under the MIT license. See the LICENSE file for more info.

maliang's People

Contributors

harley-xk avatar

Stargazers

 avatar

Watchers

James Cloos avatar Zhenwei Guan 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.