Skip to content

Commit 24ff1e7

Browse files
committed
Fixed Moondrawing Routine
Deleted old files
1 parent d97aae3 commit 24ff1e7

File tree

2 files changed

+21
-889
lines changed

2 files changed

+21
-889
lines changed

ESP32-e-Paper-Weather-Display.ino

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1818
See more at http://www.dsbird.org.uk
1919
20-
Modifications done by Alessandro Marani
20+
Modifications done by Alessandro Marani
2121
- Better alignment of Text and Graphics
2222
- Better alignment of Forecast Multiline-Text
2323
- Wind and Gust speeds
@@ -27,6 +27,7 @@
2727
- Changed Battery-Display when no battery used
2828
- Moved some Status-Infos to better suitable places
2929
- Stronger lines in Weather Symbols and Wind graphics
30+
- Fixed Moon drawing routine to avoid drawing strayed pixels
3031
*/
3132

3233
#define BOX_HEADER 20
@@ -388,6 +389,7 @@ double DrawMoon(int x, int y, int dd, int mm, int yy, String hemisphere) {
388389
double Phase = NormalizedMoonPhase(dd, mm, yy);
389390
hemisphere.toLowerCase();
390391
if (hemisphere == "south") Phase = 1 - Phase;
392+
391393
// Draw dark part of moon
392394
display.fillCircle(x + diameter - 1, y + diameter, diameter / 2 + 1, GxEPD_BLACK);
393395
const int number_of_lines = 90;
@@ -405,16 +407,26 @@ double DrawMoon(int x, int y, int dd, int mm, int yy, String hemisphere) {
405407
Xpos2 = Xpos - 2 * Phase * Rpos + Rpos;
406408
}
407409
// Draw light part of moon
410+
// Marani: Fixed the calculation to draw the moon phases smoothly without straying pixels
408411
double pW1x = (Xpos1 + number_of_lines) / number_of_lines * diameter + x;
409-
double pW1y = (number_of_lines - Ypos) / number_of_lines * diameter + y;
412+
double pW1y = ceil((number_of_lines - Ypos) / number_of_lines * diameter + y);
410413
double pW2x = (Xpos2 + number_of_lines) / number_of_lines * diameter + x;
411-
double pW2y = (number_of_lines - Ypos) / number_of_lines * diameter + y;
412-
double pW3x = (Xpos1 + number_of_lines) / number_of_lines * diameter + x;
413-
double pW3y = (Ypos + number_of_lines) / number_of_lines * diameter + y;
414-
double pW4x = (Xpos2 + number_of_lines) / number_of_lines * diameter + x;
415-
double pW4y = (Ypos + number_of_lines) / number_of_lines * diameter + y;
416-
display.drawLine(pW1x, pW1y, pW2x, pW2y, GxEPD_WHITE);
417-
display.drawLine(pW3x, pW3y, pW4x, pW4y, GxEPD_WHITE);
414+
double pW2y = floor((Ypos + number_of_lines) / number_of_lines * diameter + y);
415+
bool draw_fill = false;
416+
if (Phase < 0.48) {
417+
pW1x = ceil(pW1x);
418+
pW2x = floor(pW2x-1);
419+
draw_fill = true;
420+
}
421+
else if (Phase > 0.52 && Phase <= 1.0) {
422+
pW1x = floor(pW1x-1);
423+
pW2x = ceil(pW2x);
424+
draw_fill = true;
425+
}
426+
if (draw_fill) {
427+
display.drawLine(pW1x, pW1y, pW2x, pW1y, GxEPD_WHITE);
428+
display.drawLine(pW1x, pW2y, pW2x, pW2y, GxEPD_WHITE);
429+
}
418430
}
419431
display.drawCircle(x + diameter - 1, y + diameter, diameter / 2, GxEPD_BLACK);
420432
return Phase;

0 commit comments

Comments
 (0)