xxxxxxxxxx
108
function getMoonPhase(year, month, day) {
var c = e = jd = b = 0;
if (month < 3) {
year--;
month += 12;
}
c = 365.25 * year;
e = 30.6 * month;
jd = c + e + day - 694039.09; // jd is total days elapsed
jd /= 29.5305882; // divide by the moon cycle
b = parseInt(jd); // int(jd) -> b, take integer part of jd
jd -= b; // subtract integer part to leave fractional part of original jd
b = Math.round(jd * 8); // scale fraction from 0-8 and round
if (b >= 8) {
b = 0; // 0 and 8 are the same so turn 8 into 0
}
return b;
}
function getNextMenstruationDate(lastMenstruationDate, cycleLength) {
const date = new Date(lastMenstruationDate);
date.setDate(date.getDate() + cycleLength);
return date;
}
let moonPhase;
let menstruationDate;
function setup() {
createCanvas(800, 200);
background(220);
// Example date for moon phase calculation
const today = new Date();
moonPhase = getMoonPhase(today.getFullYear(), today.getMonth() + 1, today.getDate());
// Example menstruation cycle calculation
const lastMenstruationDate = new Date('2024-03-01');
menstruationDate = getNextMenstruationDate(lastMenstruationDate, 28);
}
function draw() {
background(220);
// Draw Moon Phase Circle
drawMoonPhaseCircle(200, 100, moonPhase);
// Draw Menstruation Cycle Circle
drawMenstruationCycleCircle(600, 100, menstruationDate);
}
function drawMoonPhaseCircle(x, y, phase) {
fill(255);
noStroke();
ellipse(x, y, 150, 150);
// Calculate angle based on phase
const angle = map(phase, 0, 8, 0, 360);
// Draw dot at calculated angle
const dotX = x + cos(radians(angle)) * 75;
const dotY = y + sin(radians(angle)) * 75;
fill(0);
ellipse(dotX, dotY, 10, 10);
fill(0);
textSize(12);
text(`Moon Phase: ${getPhaseName(phase)}`, x - 75, y + 90);
}
function drawMenstruationCycleCircle(x, y, date) {
fill(255, 0, 0);
noStroke();
ellipse(x, y, 150, 150);
// Calculate angle based on day of cycle
const cycleLength = 28;
const daysSinceLastMenstruation = Math.floor((date.getTime() - new Date('2024-03-01').getTime()) / (1000 * 3600 * 24)) % cycleLength;
const angle = map(daysSinceLastMenstruation, 0, cycleLength, 0, 360);
// Draw dot at calculated angle
const dotX = x + cos(radians(angle)) * 75;
const dotY = y + sin(radians(angle)) * 75;
fill(0);
ellipse(dotX, dotY, 10, 10);
fill(0);
textSize(12);
text(`Next Menstruation: ${date.toLocaleDateString()}`, x - 100, y + 90);
}
function getPhaseName(phase) {
const phases = ['New Moon', 'Waxing Crescent Moon', 'Quarter Moon', 'Waxing Gibbous Moon', 'Full Moon', 'Waning Gibbous Moon', 'Last Quarter Moon', 'Waning Crescent Moon'];
return phases[phase];
}