• Here is an implementation of your moon phase image (based on Bresenham's circle algorithm - yes, I'm able to learn!):

      let ScreenWidth  = g.getWidth(),  CenterX = ScreenWidth/2;
      let ScreenHeight = g.getHeight(), CenterY = ScreenHeight/2;
    
      g.setBgColor('#000000');
      g.clear(false);
    
      function drawMoonPhase (CenterX,CenterY, Radius, leftFactor,rightFactor) {
        let x = Radius, y = 0, Error = Radius;
    
        g.drawLine(CenterX-leftFactor*x,CenterY, CenterX+rightFactor*x,CenterY);
    
        let dx,dy;
        while (y <= x) {
          dy = 1 + 2*y; y++; Error -= dy;
          if (Error < 0) {
            dx = 1 - 2*x; x--; Error -= dx;
          }
    
          g.drawLine(CenterX-leftFactor*x,CenterY-y, CenterX+rightFactor*x,CenterY-y);
          g.drawLine(CenterX-leftFactor*x,CenterY+y, CenterX+rightFactor*x,CenterY+y);
          g.drawLine(CenterX-leftFactor*y,CenterY-x, CenterX+rightFactor*y,CenterY-x);
          g.drawLine(CenterX-leftFactor*y,CenterY+x, CenterX+rightFactor*y,CenterY+x);
        }
      }
    
      g.setColor('#FFFFFF');
      drawMoonPhase(CenterX,CenterY, 50, 1,-0.5);
    

    leftFactor and rightFactor specify the actual phase that is to be shown:

    • both variables range from -1...+1
    • set both to 1 for a full moon
    • set rightFactor = 1 and start with leftFactor = -1 for a waxing moon. Increase leftFactor until 1 for a full moon
    • set leftFactor = 1 and start with rightFactor = 1 for a waning moon. Decrease rightFactor until -1

    (see GitHub for the current source code and an animated demo)

    Have fun!


    1 Attachment

    • Moonphase.png
About