This library project contains a few noise generators created in Swift.

Overview

SwiftNoiseGenerator

This library project contains a few noise generators created in Swift.

contains:

  • Perlin Noise
  • Simplex Noise

How to use

Edit your Package.swift

     name: "MyExecutable",
     dependencies: [
         // Dependencies declare other packages that this package depends on.
-        // .package(url: /* package url */, from: "1.0.0"),
+        .package(url: "https://github.com/hirota1ro/swift-noise-generator", from: "1.0.0"),
     ],
     targets: [
         // Targets are the basic building blocks of a package. A target can define a module or a test suite.
         // Targets can depend on other targets in this package, and on products in packages this package depends on.
         .executableTarget(
             name: "MyExecutable",
-            dependencies: []),
+            dependencies: [.product(name: "SwiftNoiseGenerator", package: "swift-noise-generator")]),
         .testTarget(
             name: "MyExecutableTests",
             dependencies: ["MyExecutable"]),

Sample Code

import SwiftNoiseGenerator

let generator = PerlinNoise()
//let generator = SimplexNoise()

var a: [String] = []
for j in stride(from: 0, to: 360, by: 8) {
    for i in stride(from: 0, to: 480, by: 8) {
        let x = Double(i - 240) / 100
        let y = Double(j - 180) / 100

        let noise = generator.normalized(x, y, 0) // 0〜1
        let b = Int(noise * 255) // 0x00〜0xFF
        let rgb = (b << 16) | (b << 8) | (b) // 0x000000〜0xFFFFFF
        let hex = String(format: "%06x", rgb)

        let s = """
          <rect x="\(i)" y="\(j)" width="8" height="8" fill="#\(hex)" stroke="none" />
          """
        a.append(s)
    }
}

let svg = """
  <svg width="480" height="360" viewBox="0 0 480 360" xmlns="http://www.w3.org/2000/svg" version="1.1">
  \(a.joined(separator: "\n"))
  </svg>
  """
let dir = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first!
let file = dir.appendingPathComponent("noise.svg")
try! svg.write(to: file, atomically: true, encoding: .utf8)
You might also like...
🏈 Cache CocoaPods for faster rebuild and indexing Xcode project.
🏈 Cache CocoaPods for faster rebuild and indexing Xcode project.

🏈 Cache CocoaPods for faster rebuild and indexing Xcode project.

Open Source project for watching YouTube channel playlists.
Open Source project for watching YouTube channel playlists.

YouTube Channel Watcher An open source project build using SwiftUI and Combine that lets you monitor a variety of different YouTube channels and their

Sample project to reproduce Xcode 13 indexing problems

Xcode 13 indexing regression for Swift static libraries Summary: Currently if you have a project that links a pre-compiled Swift static library (with

Globant iOS Academy Base Project
Globant iOS Academy Base Project

The repository will be used for trainees to save course progress.

Another Virtualization.framework demo project, with focus to iBoot (WIP)
Another Virtualization.framework demo project, with focus to iBoot (WIP)

Virtual iBoot Fun This is just another Virtualization.framework sample project (WIP), but with focus on iBoot (iOS/macOS/tvOS/etc. bootloader) For a m

All the reusable code that we need in each project

SwiftyUtils SwiftyUtils groups all the reusable code that we need to ship in each project. This framework contains: Extensions Protocols Structs Subcl

DGPreview - Make UIKit project enable preview feature of SwiftUI
DGPreview - Make UIKit project enable preview feature of SwiftUI

DGPreview Make UIKit project enable preview feature of SwiftUI Requirements iOS

swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

macOS system library in Swift

SystemKit A macOS system library in Swift based off of libtop, from Apple's top implementation. For an example usage of this library, see dshb, a macO

Owner
Ichiro HIROTA
iOS, Android
Ichiro HIROTA
iOS helper library that contains commonly used code in Uptech iOS projects

iOS helper library that contains commonly used code in Uptech iOS projects.

Uptech 1 Apr 1, 2022
Created a Tic Tac Toe game with pure swift that runs within zsh shell.

Swift TicTacToe Created a Tic Tac Toe game with pure swift that runs within zsh shell. The computer is actually really hard to beat and it ends up bei

Ethan 0 Nov 25, 2021
iOS application for CA Tech Challenge ONLINE ACE created by @KS1019 and @techiro

インターン後改善したところ RepositoryのMock化を行って、ViewModelのテストを可能にした RepositoryやViewModelをコンストラクタインジェクションを使ってDI Repository自体のテストを実装できるように、URLSessionのAdapterを定義してスケジ

Kotaro Suto 1 Nov 25, 2021
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Enable autocomplete use resources in swift project.

ResourceKit Enable autocomplete use resources in swift project. まだハードコードで消耗してるの? ResourceKitで安全コーディング! How does ResourceKit work? ResouceKit makes you

bannzai 90 Nov 25, 2022
A handy collection of Swift method and Tools to build project faster and more efficient.

SwifterKnife is a collection of Swift extension method and some tools that often use in develop project, with them you might build project faster and

李阳 4 Dec 29, 2022
Generates Heroku-style random project names in Swift

RandomProjectName.swift Generates Heroku-style random project names in Swift. Usage Just call String.randomProjectName(), and specify the optional suf

NLUDB 0 Dec 6, 2021
Project shows how to unit test asynchronous API calls in Swift using Mocking without using any 3rd party software

UnitTestingNetworkCalls-Swift Project shows how to unit test asynchronous API ca

Gary M 0 May 6, 2022
Functional data types and functions for any project

Swiftx Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way

TypeLift 219 Aug 30, 2022
All the reusable code that we need in each project

SwiftyUtils SwiftyUtils groups all the reusable code that we need to ship in each project. This framework contains: Extensions Protocols Structs Subcl

Tom Baranes 529 Dec 25, 2022