mirror of
https://github.com/acamarata/moon-cycle.git
synced 2026-06-30 18:54:29 +00:00
initial commit
This commit is contained in:
commit
31d27cd6c0
10 changed files with 187 additions and 0 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
node_modules/
|
||||
dist/
|
||||
.env
|
||||
.DS_Store
|
||||
.vscode
|
||||
7
CHANGELOG.md
Normal file
7
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [1.0.0] - 2023-11-14
|
||||
|
||||
- Initial release
|
||||
7
LICENSE
Normal file
7
LICENSE
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
ISC License
|
||||
|
||||
Copyright (c) 2023, [Your Full Name]
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
52
README.md
Normal file
52
README.md
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
# moon-cycle
|
||||
|
||||
Simple functions to map a Date() to the current lunar phase and map that to hourly photos of the moon during that phase from NASA.
|
||||
|
||||
Yearly takes the full photos for all of 2023 (8760 images) while Monthly take only the cycle starting from November 13 (708 images).
|
||||
|
||||
The images have been organized, named, converted to webp, and optimized according to the following structure:
|
||||
- "mm" (moon monthly) vs "my" (moon yearly)
|
||||
- "256" (256x256 size) vs "512" (512x512 size)
|
||||
- "75" (lower quality) vs "85" (higher quality)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install praycalc
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Copy any of the mm or my folders (or both) to your projects "public" directory. Then use as follows:
|
||||
|
||||
```js
|
||||
const { cycleMonth, cycleYear } = require('moon-cycle');
|
||||
|
||||
const date = new Date();
|
||||
|
||||
// Get results
|
||||
const mm = cycleMonth(date)
|
||||
const my = cycleYear(date)
|
||||
|
||||
// Print results
|
||||
console.log(`\nDate = ${date.toISOString()}\nMatch Moon Image URLs to Date..\n`)
|
||||
console.log(`MM = /mm/${mm}`);
|
||||
console.log(`MY = /my/${my}`);
|
||||
|
||||
|
||||
```
|
||||
|
||||
Exported functions include cycleMonth and cycleYear
|
||||
|
||||
### Parameters:
|
||||
|
||||
- result: name of the monthly or yearly webp file
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome!
|
||||
|
||||
## License
|
||||
|
||||
ISC License
|
||||
30
cycleMonth.js
Normal file
30
cycleMonth.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
function cycleMonth(date = new Date()) {
|
||||
/**
|
||||
* There are 708 images from 001.webp to 708.webp in
|
||||
* the moon monthly (mm) folder. These are hourly
|
||||
* photos from NASA's 2023 collection which directly
|
||||
* relate to one per hour. The below function takes
|
||||
* seconds since the last known new moon the figures
|
||||
* number of Synodic months since then to find the
|
||||
* current "hourly phase" for the current cycle of
|
||||
* the moon. This relates R as always 1-708.
|
||||
*/
|
||||
|
||||
const startDate = new Date("2023-11-13T09:27:00Z");
|
||||
const synDays = 29.53058821398858;
|
||||
const synSecs = synDays * 24 * 60 * 60;
|
||||
|
||||
// X = number of seconds since 2023-11-13T09:27:00Z
|
||||
const X = Math.floor((date.getTime() - startDate.getTime()) / 1000);
|
||||
|
||||
// Y = get the number of months since
|
||||
const Y = Math.floor(X / synSecs);
|
||||
|
||||
// R = decimal time (minus years) * number of images
|
||||
const R = Math.floor(((X / synSecs) - Y) * 708);
|
||||
|
||||
let result = R.toString().padStart(3, '0')+'.webp';
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = { cycleMonth };
|
||||
30
cycleYear.js
Normal file
30
cycleYear.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
function cycleYear(date = new Date()) {
|
||||
/**
|
||||
* There are 8760 images from 0001.webp to 8760.webp
|
||||
* in the moon yearly (my) folder. These are hourly
|
||||
* photos from NASA's 2023 collection which directly
|
||||
* relate to one per hour. The below function takes
|
||||
* hours (seconds / 3600) and maps directly to these
|
||||
* 8760 images in the folders. The last calculation
|
||||
* below rounds the cycle so R is always 1-8760.
|
||||
*/
|
||||
|
||||
const startDate = new Date("2023-01-01T00:00:00Z");
|
||||
|
||||
// X = number of seconds since 2023-01-01T00:00:00Z
|
||||
const X = Math.floor((date.getTime() - startDate.getTime()) / 1000);
|
||||
|
||||
// Y = convert to number of hours since
|
||||
const Y = Math.floor(X / 3600);
|
||||
|
||||
// Z = get the number of years since
|
||||
const Z = Math.floor(Y / 8760);
|
||||
|
||||
// R = decimal time (minus years) * number of images
|
||||
const R = Math.floor(((Y / 8760) - Z) * 8760);
|
||||
|
||||
let result = R.toString().padStart(4, '0')+'.webp';
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = { cycleYear };
|
||||
12
index.d.ts
vendored
Normal file
12
index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// index.d.ts
|
||||
declare module 'moon-cycle' {
|
||||
export function cycleMonth(date: Date): MonthResult;
|
||||
export function cycleYear(date: Date): YearResult;
|
||||
|
||||
interface MonthResult {
|
||||
result: string;
|
||||
}
|
||||
interface YearResult {
|
||||
result: string;
|
||||
}
|
||||
}
|
||||
7
index.js
Normal file
7
index.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
const { cycleMonth } = require('./cycleMonth');
|
||||
const { cycleYear } = require('./cycleYear');
|
||||
|
||||
module.exports = {
|
||||
cycleMonth,
|
||||
cycleYear
|
||||
};
|
||||
25
package.json
Normal file
25
package.json
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "moon-cycle",
|
||||
"version": "1.0.0",
|
||||
"description": "NREL SPA native implementation in JS",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ussunnah/moon-cycle.git"
|
||||
},
|
||||
"keywords": [
|
||||
"moon",
|
||||
"cycle",
|
||||
"images",
|
||||
"nasa"
|
||||
],
|
||||
"author": "USF",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ussunnah/moon-cycle/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ussunnah/moon-cycle#readme"
|
||||
}
|
||||
12
test.js
Normal file
12
test.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
const { cycleMonth, cycleYear } = require('./index');
|
||||
|
||||
const date = new Date();
|
||||
|
||||
// Get results
|
||||
const mm = cycleMonth(date)
|
||||
const my = cycleYear(date)
|
||||
|
||||
// Print results
|
||||
console.log(`\nDate = ${date.toISOString()}\nMatch Moon Image URLs to Date..\n`)
|
||||
console.log(`MM = /mm/${mm}`);
|
||||
console.log(`MY = /my/${my}`);
|
||||
Loading…
Reference in a new issue