8000 GitHub - Wildchild9/Shapes: A library for quickly and easily drawing and modifying complex shapes.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Wildchild9/Shapes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Shapes

A library for quickly and easily drawing and modifying complex shapes.

Try it out

To try out this project, open the DrawingShapes.xcodeproj file, then run the Testing playground. To see the outputs of the various shape statements, be sure to expand the preview on the right side of the playground.

Examples

Squares and Cubes

Here are a few examples of some fun quick shapes you can make with this library.

Firstly lets start off by making a square:

let square = Shape().to(0, 0).to(0, 100).to(100, 100).to(100, 0).closed().withFill(.white)

Screenshot 2022-12-08 at 6 13 07 PM

This can easly be made into a cube with a single method call:
let cube = square.prism()

Screenshot 2022-12-08 at 6 14 35 PM

Furthermore, if we want to apply more advanced styling, we can apply a gradient and show the points of the shape.

let styledCube = cube.withFill(.argon).showingPoints()

Screenshot 2022-12-08 at 6 15 34 PM


Pyramids

Now let's look at some more complex shapes, such as a pyramid. To make a pyramid, it is almost as easy as making a square but with one additional call to joinedAt.

let pyramid = Shape()
    .to(0, 100).to(100, 100).to(125, 75).to(25, 75).closed()
    .joinedAt(x: 60, y: -30)
    .withFill(.wireTap).showingPoints()

Screenshot 2022-12-08 at 6 29 02 PM

To make a bipyramid, we can do this in a few different ways. The first way we can do this is by using the existing pyramid and mirroring it about its bottom axis and performing a translation.

let bipyramid = squareBipyramid + squareBipyramid.reflected(over: .bottom).flipped(.vertically).translatedBy(x: 0, y: -25)

Screenshot 2022-12-08 at 6 32 21 PM

Alternatively, we can make the new bipyramid from scratch. This can be done by adding a slight modification to the code that generates the pyramid, just by passing an additional point to the joinedAt method.

let bipyramid = Shape()
    .to(0, 100).to(100, 100).to(125, 75).to(25, 75).closed()
    .joinedAt(points: (60, -30), (65, 205))
    .withFill(.wireTap).showingPoints()

As we can see, this produces the same result:

Screenshot 2022-12-08 at 6 35 25 PM


Other fun shapes

Polygon:

var polygonalPrism = Shape.regularPolygon(n: 7, sideLength: 100).prism()
polygonalPrism.applyingOptions(.fill(.electricViolet), .showPoints)

Screenshot 2022-12-08 at 6 39 19 PM

Badge:

let badge = Shape.star(numberOfPoints: 9, radiusPercent: 0.7).withFill(.red).applyingOption(.fillInShape(true))

Screenshot 2022-12-08 at 6 42 04 PM

21-pointed star:

let star = Shape.crossStar(numberOfPoints: 21).applyingOptions(.fill(.timber), .lineWidth(1.0)).scaled(by: 3)

Screenshot 2022-12-08 at 6 44 26 PM

Using Shapes in Your Project

You can interact with these shapes and use them in your own project in two primary ways.

  1. Extracting a UIView from a shape

    • This can be done by calling shape.draw()
  2. Extracting a UIBezierPath from a shape

    • This can be done by calling shape.path

About

A library for quickly and easily drawing and modifying complex shapes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0