// First day of month calculation is from here // https://cs.uwaterloo.ca/~alopez-o/math-faq/mathtext/node39.html century = 20; year = 21; month = 5; // [11:January, 12:February, 1:March, 2:April, 3:May, 4:June, 5:July, 6:August, 7:September, 8:October, 9:November, 10:December] day = 1; // [1:31] highlightDay = 0; // [0:31] fontSize = 10; cellSize = 20; highlightDiameter = 15; highlightWidth = 2; cYear = calcYear(year, month); fontName = "Alef"; // ["Alef", "Amiri", "Bahnschrift", "Bauhaus 93", "Bell MT", "Book Antiqua", "Bookman Old Style", "Britannic Bold"] borders = true; borderWidth = 1; // [0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0] filled = false; top_left_text = ""; top_right_text = ""; bottom_left_text = ""; bottom_right_text = ""; function calcYear(year, month) = (month <= 10 ? year : year-1); function firstDayOfMonth(c, y, m) = (1 + floor((2.6 * m) - 0.2) - (2 * c) + cYear + floor(cYear / 4) + floor(c/4)) % 7; module drawDay(daynum=1) { if (filled == false) { union() { if (borders) { difference() { square(cellSize, center=true); square(cellSize-borderWidth, center=true); } } text(str(daynum), size=fontSize, halign="center", valign="center", font=fontName); } } else { difference() { square(cellSize, center=true); text(str(daynum), size=fontSize, halign="center", valign="center", font=fontName); } } } module calendar() { monthDays = [0,31,30,31,30,31,31,30,31,30,31,31,28]; dayOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; monthNames = ["", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February"]; daysInWeek = 7; startTmp = firstDayOfMonth(century, year, month); startDay = startTmp >= 0 ? startTmp : 7 + startTmp; daysInMonth = monthDays[month]; rows = (startDay + daysInMonth) <= 35 ? 5 : 6; headers = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]; //headers = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"]; //echo("Calc Year: ", calcYear(year, month)); //echo("First Day Of Month: ", startDay); //echo("First Day Of Month: ", dayOfWeek[startDay]); //echo("Days In Month: ", daysInMonth); //echo("Rows: ", rows); if (top_left_text != "") { translate([-10, 50, 0]) text(top_left_text, size=fontSize/2, halign="left"); } if (top_right_text != "") { translate([130, 50, 0]) text(top_right_text, size=fontSize/2, halign="right"); } if (bottom_left_text != "") { echo(bottom_left_text); translate([-10, -130, 0]) text(bottom_left_text, size=fontSize/2, halign="left"); } if (bottom_right_text != "") { echo(bottom_right_text); translate([130, -130, 0]) text(bottom_right_text, size=fontSize/2, halign="right"); } translate([(cellSize*6)/2, cellSize*1.55, 0]) text(str(monthNames[month], " ", century, (year < 10 ? 0 : ""), year), size=fontSize, halign="center", font=fontName); for (a =[0:6]) { translate([cellSize*a, cellSize, 0]) difference() { square([cellSize, cellSize], center=true); square([cellSize-1, cellSize-1], center=true); } } for (a =[0:6]) { translate([cellSize*a, cellSize-(cellSize/2)+2, 0]) text(headers[a], size=fontSize/2, halign="center", valign="bottom", font=fontName); } if (startDay > 0) { for (a =[0:(startDay-1)]) { dayXPos = round(a % 7); dayYPos = 0; translate([(dayXPos)*cellSize, dayYPos*cellSize, 0]) drawDay(""); } } for (a =[1:(daysInMonth)]) { dayXPos = floor((a+startDay-1) % 7); dayYPos = floor((a+startDay-1) / 7); if (filled == false) { translate([dayXPos*cellSize, -dayYPos*cellSize, 0]) drawDay(a); if (highlightDay == a) { translate([dayXPos*cellSize, -dayYPos*cellSize, 0]) difference() { circle(d=highlightDiameter); circle(d=highlightDiameter-highlightWidth); } } } else { difference() { translate([dayXPos*cellSize, -dayYPos*cellSize, 0]) drawDay(a); if (highlightDay == a) { translate([dayXPos*cellSize, -dayYPos*cellSize, 0]) difference() { circle(d=highlightDiameter); circle(d=highlightDiameter-highlightWidth); } } } } } if (startDay+daysInMonth < 42) { for (a =[(startDay+daysInMonth+1):42]) { dayXPos = floor((a-1) % 7); dayYPos = floor((a-1) / 7); translate([(dayXPos)*cellSize, -dayYPos*cellSize, 0]) drawDay(""); } } } calendar();