Code Monkey home page Code Monkey logo

swift-geometrize's Introduction

Geometrize logo fulltext

swift-geometrize

Swift package for recreating images as geometric primitives. It began as a Swift port of the geometrize-lib C++ library, but it has since evolved in a distinct direction. You can give it a try in web version.

Usage

Look geometrize-cli target how package could be used to geometrize images.

Shape Comparison

The matrix below shows typical results for a combination of circles, triangles, rotated rectangles, rotated ellipses and all supported shapes at 50, 200 and 500 total shapes:

50 Shapes 200 Shapes 500 Shapes
Circles Chicken 50 Circles Chicken 200 Circles Chicken 500 Circles
Triangles Chicken 50 Triangles Chicken 200 Triangles Chicken 500 Triangles
Rotated Rectangles Chicken 50 RotatedRectangles Chicken 200 RotatedRectangles Chicken 500 RotatedRectangles
Rotated Ellipses Chicken 50 RotatedEllipses Chicken 200 RotatedEllipses Chicken 500 RotatedEllipses
All Shapes Chicken 50 All Shapes Chicken 200 All Shapes Chicken 500 All Shapes

Geometrizebot

You could try swift-geometrize in action in Telegram bot Geometrizebot which is also written in Swift and open-sourced.

TODO:

  • ✅ add stroke width for line, polyline and bezier curve;
  • ✅ multithreading;
  • add polygon as shape type;
  • filling shapes with gradient;
  • solve dealing with randomness in tests;
  • geometrize with predefined or user supplied brush strokes;
  • geometrize with characters (on output will be something which could be called ascii art or art produced by James Cook Type Writer Artist);
  • photo mosaic,
  • string art.

License

Licensed under MIT license.

Buy Me A Coffee

swift-geometrize's People

Contributors

romanpodymov avatar tayloraswift avatar valeriyvan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swift-geometrize's Issues

Geometrizing with lines produces tons of warnings

geometrize-cli -t line -c 1000 -i Tests/geometrizeTests/Resources/grapefruit.png -o grapefruit.svg produces a lot of warnings like following:

Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.

Compile error running tests on Ubuntu

swift test
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/******/Tests/geometrizeTests/BitmapDiffing.swift:7:17: error: initializers in structs are not marked with 'convenience'
    convenience init(bitmap: Bitmap) {
    ~~~~~~~~~~~~^
    
/******/Tests/geometrizeTests/BitmapDiffing.swift:7:17: error: initializers in structs are not marked with 'convenience'
    convenience init(bitmap: Bitmap) {
    ~~~~~~~~~~~~^
    
/******/Tests/geometrizeTests/BitmapDiffing.swift:32:27: error: value of type 'XCTAttachment' has no member 'name'
            oldAttachment.name = "reference"
            ~~~~~~~~~~~~~ ^~~~
/******/Tests/geometrizeTests/BitmapDiffing.swift:7:17: error: initializers in structs are not marked with 'convenience'
    convenience init(bitmap: Bitmap) {
    ~~~~~~~~~~~~^
    
/******/Tests/geometrizeTests/BitmapDiffing.swift:32:27: error: value of type 'XCTAttachment' has no member 'name'
            oldAttachment.name = "reference"
            ~~~~~~~~~~~~~ ^~~~
/******/Tests/geometrizeTests/ImageRunnerTests.swift:12:9: warning: code after 'throw' will never be executed
        let url = Bundle.module.url(forResource: "kris", withExtension: "png")!
        ^
/******/Tests/geometrizeTests/ImageRunnerTests.swift:12:9: warning: code after 'throw' will never be executed
        let url = Bundle.module.url(forResource: "kris", withExtension: "png")!
        ^
error: fatalError

error: fatalError

Running tests fails with compile error

swift test
Building for debugging...
/Users/******/swift-geometrize/.build/checkouts/swift-snapshot-testing/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift:46:8: error: 'curveTo' is only available in macOS 11.0 or newer
      .curveTo: "CurveTo",
       ^
/Users/******/swift-geometrize/.build/checkouts/swift-snapshot-testing/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift:46:8: note: add 'if #available' version check
      .curveTo: "CurveTo",
       ^
/Users/******/swift-geometrize/.build/checkouts/swift-snapshot-testing/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift:42:22: note: add @available attribute to enclosing static method
  public static func elementsDescription(numberFormatter: NumberFormatter) -> Snapshotting {
                     ^

Geometrizing with ellipses produces tons of warnings

geometrize-cli -t ellipse -c 1000 -i Tests/geometrizeTests/Resources/grapefruit.png -o grapefruit.svg produces a lot of warnings like this:

Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: rasterize(xMin:yMin:xMax:yMax:) produced no scanlines
Warning: there are no scanlines.
Warning: Scanline has x1(511) > x2(510. This makes scanline invisible.
Warning: Scanline has x1(511) > x2(510. This makes scanline invisible.
Warning: Scanline has x1(511) > x2(510. This makes scanline invisible.
Warning: Scanline has x1(511) > x2(510. This makes scanline invisible.
Warning: Scanline has x1(511) > x2(510. This makes scanline invisible.
Warning: Scanline has x1(511) > x2(510. This makes scanline invisible.

Geometrizing the same image with rotated ellipses gives no warnings.

Consider introducing Mutable protocol

protocol Mutable {
    func setup(x: ClosedRange<Int>, y: ClosedRange<Int>, using: inout SplitMix64)
    func mutate(x: ClosedRange<Int>, y: ClosedRange<Int>, using: inout SplitMix64)
}

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.