Giter Site home page Giter Site logo

kingjay66 / sunkit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sunlitt/sunkit

0.0 1.0 0.0 435 KB

SunKit is a Swift library which uses math and trigonometry to compute several information about the Sun.

License: Apache License 2.0

Swift 100.00%

sunkit's Introduction

SunKit

sunkit

GitHub GitHub stars GitHub issues Requires Core Location

SunKit is a Swift package which uses math and trigonometry to compute several information about the Sun. This package has been developed by a team of learners relatively new to the Swift programming language, which means that there could be a lot of space for improvements. Every contribution is welcome.

SunKit was first developed as part of a bigger project: Sunlitt. Even though Sunlitt is not meant to be released as Open Source we decided to wrap the fundamental logic of the app and make an open source library out of it.

sunkit

To compute Sunrise, Sunset, Golden Hour and so on we only need a CLLocation and the time zone of that location. CoreLocation framework is required for SunKit to work.

Credit

For attribution, we prefer that you use an unmodified vector of our logomark available in this repository (sunkit.svg), along with our organization name, both at legible sizes, and that they link back to our website Sunlitt.app.

Usage

SunKit only needs a location and the relative time zone to compute every information you need about the Sun.
Everything is computed locally, no internet connection is needed.

Creating a Sun

// Creating a CLLocation object with the coordinates you are interested in
let naplesLocation: CLLocation = .init(latitude: 40.84014, longitude: 14.25226)

// Timezone for the location of interest. It's highly recommended to initialize it via identifier
let timeZoneNaples: Timezone = .init(identifier: "Europe/Rome") ?? .current

// Creating the Sun instance which will store all the information you need about sun events and his position
var mySun: Sun = .init(location: naplesLocation, timeZone: timeZoneNaples)

Retrieve information

// Creating a Date instance
let myDate: Date = Date() // Your current date

// Setting inside mySun object the date of interest
mySun.setDate(myDate)

      // All the following informations are related to the given location for the date that has just been set

// Azimuth of the Sun 
mySun.azimuth.degrees  

// Altitude of the Sun
mySun.altitude.degrees

// Sunrise Date
mySun.sunrise

// Sunset Date
mySun.sunset

// Evening Golden Hour Start Date
mySun.eveningGoldenHourStart

// Evening Golden Hour End Date
mySun.eveningGoldenHourEnd

// To know all the information you can retrieve go to the **Features** section.

Working with Timezones and Dates

To properly show the Sun Date Events use the following DateFormatter.

 //Creting a DateFormatter
 let dateFormatter =  DateFormatter()
 
 //Properly setting his attributes
 dateFormatter.locale    =  .current
 dateFormatter.timeZone  =  timeZoneNaples  // It shall be the same as the one used to initilize mySun
 dateFormatter.timeStyle = .full
 dateFormatter.dateStyle = .full
  
 //Printing Sun Date Events with the correct Timezone
  
 print("Sunrise: \(dateFormatter.string(from: mySun.sunrise))")
    

Features

  • Sun Azimuth
  • Sun Altitude
  • Civil Dusk Time
  • Civil Dawn Time
  • Sunrise Time
  • Solar Noon Time
  • Solar Midnight Time
  • Morning Golden Hour Time
  • Evening Golden Hour Time
  • Sunset Time
  • Astronomical Dusk
  • Astronomical Dawn
  • Nautical Dusk
  • Nautical Dawn
  • Morning Blue Hour Time
  • Evening Blue Hour Time
  • Sun Azimuth at Sunrise
  • Sun Azimuth at Sunset
  • Sun Azimuth at Solar Noon
  • Total Daylight Duration
  • Total Night Duration
  • March Equinox
  • June Solstice
  • September Equinox
  • December Solstice

References

  • NOAA Global Monitoring Division. General Solar Position Calculations: Link.
  • PV Education: Link.
  • Celestial Calculations: A Gentle Introduction to Computational Astronomy: Link.

MoonKit ๐ŸŒ™

Take a look to the other Package, this time about the Moon.

Special thanks

sunkit's People

Contributors

davideilmito avatar seldon1000 avatar uevs avatar

Watchers

 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.