void PageWeather1()
{
    display.setRotation(4);
  display.fillScreen(GxEPD_WHITE);
  display.setTextColor(GxEPD_BLACK);
  display.setFont();
  
 DisplayWeatherIcon(64, 100);                  // Display weather icon    scale = Large;
  DrawBattery( 0, 21);
DrawRSSI(105, 21, wifi_signal);
display.drawLine(0,50, 120, 50, GxEPD_BLACK);//x1 y1 x2 y2
display.drawLine(0, 150, 120, 150, GxEPD_BLACK);//x1 y1 x2 y2
display.drawLine(0, 170, 120, 170, GxEPD_BLACK);//x1 y1 x2 y2
display.drawLine(0, 230, 120, 230, GxEPD_BLACK);//x1 y1 x2 y2
display.drawLine(64, 170, 64, 230, GxEPD_BLACK);//x1 y1 x2 y2
  display.update();
}
void DisplayWeatherIcon(int x, int y) {
 // DisplayConditionsSection(x, y, WxConditions[0].Icon, LargeIcon);
 // DisplayConditionsSection(x, y+100, WxConditions[0].Icon, SmallIcon);
  DisplayConditionsSection(x, y, "11d", LargeIcon);
  DisplayConditionsSection(35, y+100,"11d", SmallIcon);
  DisplayConditionsSection(95, y+100,"11n", SmallIcon);
}

void DisplayConditionsSection(int x, int y, String IconName, bool IconSize) {
  Serial.println("Icon name: " + IconName);
  if      (IconName == "01d" || IconName == "01n")  Sunny(x, y, IconSize, IconName);
  else if (IconName == "02d" || IconName == "02n")  MostlySunny(x, y, IconSize, IconName);
  else if (IconName == "03d" || IconName == "03n")  Cloudy(x, y, IconSize, IconName);
  else if (IconName == "04d" || IconName == "04n")  MostlyCloudy(x, y, IconSize, IconName);
  else if (IconName == "09d" || IconName == "09n")  ChanceRain(x, y, IconSize, IconName);
  else if (IconName == "10d" || IconName == "10n")  Rain(x, y, IconSize, IconName);
  else if (IconName == "11d" || IconName == "11n")  Tstorms(x, y, IconSize, IconName);//молния
  else if (IconName == "13d" || IconName == "13n")  Snow(x, y, IconSize, IconName);
  else if (IconName == "50d" || IconName == "50n")  Haze(x, y, IconSize, IconName);//легкий туман
  else if (IconName == "51d" || IconName == "51n")  Fog(x, y, IconSize, IconName);// туман
  else                                              Nodata(x, y, IconSize, IconName);
}


void Sunny(int x, int y, bool IconSize, String IconName) {//солнечно
  int scale = Small, Offset = 15;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 35;
  }
  else y = y - 3; // Shift up small sun icon


  if (IconName.endsWith("n")) 
  {moon(x, y + Offset, scale, IconSize);
     return;
  }
     scale = scale * 1.6;
  addsun(x, y-3+scale/2, scale, IconSize);
 
}

void MostlySunny(int x, int y, bool IconSize, String IconName) {//основная солнечно
  int scale = Small, linesize = 5, Offset = 20 ,Offset1 = 13;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 50;
    Offset1=25;
  }
  if (IconName.endsWith("n"))
  {addmoon(x, y + Offset, scale, IconSize);
  addcloud(x, y+ Offset1, scale*2/3, linesize/2);
   return;
  }
  addsun(x - scale * 1.8, y - scale * 1.5, scale, IconSize);
  addcloud(x, y+Offset1, scale*2/3, linesize/2);
}

void MostlyCloudy(int x, int y, bool IconSize, String IconName) {//основная облачность
  int scale = Small, linesize = 3, Offset = 15;
 
  
  
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 45;
       if (IconName.endsWith("n"))
  {addmoon(x+5, y + Offset+scale/2, scale, IconSize);
  }
  else{
  addsun(x - scale * 1.6, y - scale * 1.0, scale, IconSize);
 }
    addcloud(x, y+18, scale, linesize);
  }
  else
  {
       if (IconName.endsWith("n"))
  {addmoon(x, y + Offset, scale, IconSize);
  }
  else{
  addsun(x - scale * 1.6, y - scale * 1.5, scale, IconSize);
 }
   addcloud(x, y+7, scale, linesize); 
  }

}

void Cloudy(int x, int y, bool IconSize, String IconName) {//облачно
  int scale = Small, linesize = 5, Offset = 7;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 12;
  }
  y=y+Offset;
 if (IconSize == SmallIcon) {
  //if (IconName.endsWith("n")) addmoon(x, y + Offset, scale, IconSize);
  
  addcloud(x + scale*2, y - scale*2-scale/2, scale / 2, linesize/2); // Cloud top right
  addcloud(x - scale-scale/4, y - scale*2, scale / 2, linesize/2); // Cloud top left
  addcloud(x, y, scale, 3);             // Main cloud
  
 // addrain(x, y, scale, IconSize);
  }
  else{
  
  addcloud(x, y, scale, 3);             // Main cloud
     addcloud(x + scale*2, y - scale, scale / 2, linesize/2); // Cloud top right
  addcloud(x - 2*scale-scale/3, y-scale/3 , scale / 2, linesize/2); // Cloud top left
 // addrain(x, y, scale, IconSize);
  }
}

void Rain(int x, int y, bool IconSize, String IconName) {//дождь
  int scale = Small, linesize = 5, Offset = 10;
  y=y+3;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 35;
  }
  if (IconSize == SmallIcon) {
  //if (IconName.endsWith("n")) addmoon(x, y + Offset, scale, IconSize);
  
 
  addcloud(x + scale*2, y - scale*2-scale/2, scale / 2, linesize/2); // Cloud top right
  addcloud(x - scale-scale/4, y - scale*2, scale / 2, linesize/2); // Cloud top left
  addcloud(x, y, scale, 3);             // Main cloud
  
  addrain(x, y, scale, IconSize);
  }
  else{
  
   addcloud(x, y, scale, 3);             // Main cloud
     addcloud(x + scale*2, y - scale, scale / 2, linesize/2); // Cloud top right
  addcloud(x - 2*scale-scale/3, y-scale/3 , scale / 2, linesize/2); // Cloud top left
  addrain(x, y-3, scale, IconSize);
  }
}

void ExpectRain(int x, int y, bool IconSize, String IconName) {//ожидание дождя
  int scale = Small, linesize = 5, Offset = 10;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 35;
  }
  if (IconName.endsWith("n")) addmoon(x, y + Offset, scale, IconSize);
  addsun(x - scale * 1.8, y - scale * 1.8, scale, IconSize);
  addcloud(x, y, scale, linesize);
  addrain(x, y, scale, IconSize);
}

void ChanceRain(int x, int y, bool IconSize, String IconName) {//легкий дождь
  int scale = Small, linesize = 3, Offset = 15,cl=5,cl1=5;
  y=y-3;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 45;
    cl=5;
    cl1=0;
    
  }
  if (IconName.endsWith("n"))
  {addmoon(x, y + Offset, scale, IconSize);
  }else
  {addsun(x - scale * 1.8, y - scale * 1.6, scale, IconSize);
  }
  addcloud(x, y+cl, scale, linesize);
  addrain(x, y+cl1, scale, IconSize);
}

void Tstorms(int x, int y, bool IconSize, String IconName) {//шторм
  int scale = Small, linesize = 3, Offset = 10;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 35;
  }
  if (IconName.endsWith("n")) addmoon(x, y + Offset, scale, IconSize);
  addcloud(x, y, scale, 3);
  addtstorm(x, y, scale);
}

void Snow(int x, int y, bool IconSize, String IconName) {//снег
  int scale = Small, linesize = 3, Offset = 13;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 35;
  }
  if (IconName.endsWith("n")) addmoon(x, y + Offset, scale, IconSize);
  addcloud(x, y, scale, linesize);
  addsnow(x, y, scale, IconSize);
}

void Fog(int x, int y, bool IconSize, String IconName) {//Туман
  int scale = Small, linesize = 3, Offset = 10;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 35;
  }
  if (IconName.endsWith("n")) addmoon(x, y + Offset, scale, IconSize);
  addcloud(x, y - 5, scale, linesize);
   if (IconSize == LargeIcon) {
  addfog(x, y -5, scale, linesize, IconSize);
   }
   else
   {
     addfog(x, y+5 , scale, linesize, IconSize);
   }
}

void Haze(int x, int y, bool IconSize, String IconName) {//легкий туман
  int scale = Small, linesize = 3, Offset = 10;
  if (IconSize == LargeIcon) {
    scale = Large;
    Offset = 35;
  }
  if (IconName.endsWith("n"))
  {moon(x, y + Offset, scale, IconSize);
  }else{
  addsun(x, y - 5, scale * 1.4, IconSize);
  }
  addfog(x, y +5, scale * 1.4, linesize, IconSize);
}

void CloudCover(int x, int y, int CCover) {//полная облачность
  addcloud(x - 9, y + 2, Small * 0.3, 2); // Cloud top left
  addcloud(x + 3, y - 2, Small * 0.3, 2); // Cloud top right
  addcloud(x, y + 10, Small * 0.6, 2); // Main cloud
  drawString(x + 20, y, String(CCover) + "%", LEFT);
}

void moon(int x, int y, int scale, bool IconSize) {//луна
  if (IconSize == LargeIcon) {
    y=y-10;
    display.fillCircle(x , y - 30, uint16_t(scale * 2.2), GxEPD_RED);
   display.fillCircle(x+30, y - 30, uint16_t(scale * 2.6), GxEPD_WHITE);
     drawString(x -60, y+10 ,   " *   *    *    *  ", CENTER);
   drawString(x +5, y ,    "  *   *", CENTER);
   drawString(x , y-10 , "     *  ", CENTER);
   drawString(x-5, y-20 , " *   *", CENTER);
   drawString(x-10 , y-30 , "   *    *   ", CENTER);
    drawString(x -5, y-40 , "*   *", CENTER);
    drawString(x , y-50 , "  *   ", CENTER);
   drawString(x +5, y-60 , " *   *", CENTER);
   drawString(x -60, y-70 ,   " *    *    *  *  ", CENTER);
   
   drawString(x -60, y ,    "  * ", CENTER);
   drawString(x -60, y-20 , "* '", CENTER);
   drawString(x -60, y-40 , "' *", CENTER);
   drawString(x -60, y-60 , ".  * ", CENTER);
  }
  else
    {  y=y-5;
    display.fillCircle(x , y - 10, uint16_t(scale * 1.8), GxEPD_RED);
    display.fillCircle(x +12, y - 10, uint16_t(scale * 2.1), GxEPD_WHITE);
  
      drawString(x +10, y ,   "* . ", CENTER);//справа
   drawString(x +5, y-10 ,   " * . ", CENTER);
   drawString(x +5, y-20 ,   "* * ", CENTER);
    drawString(x +10, y-30 ,  "* ' ", CENTER);
    
    drawString(x -25, y+10 ,  "* ' *   *   ", CENTER);
      drawString(x -25, y ,   "*   ", CENTER);//слева
   drawString(x -25, y-10 ,   " .  ", CENTER);
   drawString(x -25, y-20 ,   "* . ", CENTER);
    drawString(x -25, y-30 ,  "* '  ", CENTER);
    
  }
}

void addmoon(int x, int y, int scale, bool IconSize) {//луна c облаками
  if (IconSize == LargeIcon) {
    display.fillCircle(x - 85+50, y - 70, uint16_t(scale * 1.2), GxEPD_RED);
    display.fillCircle(x - 62+40, y - 70, uint16_t(scale * 1.5), GxEPD_WHITE);
  }
  else
  {
    display.fillCircle(x - 10, y - 28, uint16_t(scale * 1.0), GxEPD_RED);
   display.fillCircle(x - 4, y - 28, uint16_t(scale * 1.4), GxEPD_WHITE);
  }
}

void Nodata(int x, int y, bool IconSize, String IconName) {//нет данных
  if (IconSize == LargeIcon) display.setFont(&FreeMonoBold18pt7b); else display.setFont(&FreeMonoBold9pt7b);
  drawString(x - 3, y - 10, "?", CENTER);
}
//#include <Fonts/FreeMonoBold9pt7b.h>
//#include <Fonts/FreeMonoBold12pt7b.h>
//#include <Fonts/FreeMonoBold18pt7b.h>
//#include <Fonts/FreeMonoBold24pt7b.h>
// Symbols are drawn on a relative 10x10grid and 1 scale unit = 1 drawing unit
void addcloud(int x, int y, int scale, int linesize) {//рисуем облачность
  display.fillCircle(x - scale * 3, y, scale, GxEPD_BLACK);                                                              // Left most circle
  display.fillCircle(x + scale * 3, y, scale, GxEPD_BLACK);                                                              // Right most circle
  display.fillCircle(x - scale, y - scale, scale * 1.4, GxEPD_BLACK);                                                    // left middle upper circle
  display.fillCircle(x + scale * 1.5, y - scale * 1.3, scale * 1.75, GxEPD_BLACK);                                       // Right middle upper circle
  display.fillRect(x - scale * 3 - 1, y - scale, scale * 6, scale * 2 + 1, GxEPD_BLACK);                                 // Upper and lower lines
  display.fillCircle(x - scale * 3, y, scale - linesize, GxEPD_WHITE);                                                   // Clear left most circle
  display.fillCircle(x + scale * 3, y, scale - linesize, GxEPD_WHITE);                                                   // Clear right most circle
  display.fillCircle(x - scale, y - scale, scale * 1.4 - linesize, GxEPD_WHITE);                                         // left middle upper circle
  display.fillCircle(x + scale * 1.5, y - scale * 1.3, scale * 1.75 - linesize, GxEPD_WHITE);                            // Right middle upper circle
  display.fillRect(x - scale * 3 + 2, y - scale + linesize - 1, scale * 5.9, scale * 2 - linesize * 2 + 2, GxEPD_WHITE); // Upper and lower lines
}

void addrain(int x, int y, int scale, bool IconSize) {//рисуем дождь
  if (IconSize == SmallIcon) {
   display.setFont(&FreeMonoBold9pt7b);
     display.setTextColor(GxEPD_BLACK);
    drawString(x - 25, y + 12, "////", LEFT);
  }
  else
  {
    display.setFont(&FreeMonoBold18pt7b);
    drawString(x - 50-5, y + 25+20, "/////", LEFT);
  }
}

void addsnow(int x, int y, int scale, bool IconSize) {//рисуем снег
  if (IconSize == SmallIcon) {
    display.setFont(&FreeMonoBold9pt7b);
      display.setTextColor(GxEPD_BLACK);
    drawString(x - 25-5, y + 22-5, "* * * ", LEFT);
    drawString(x - 25-5, y + 27-5, " * *  ", LEFT);
  }
  else
  {
    display.setFont(&FreeMonoBold18pt7b);
    drawString(x - 60, y + 42, "* * * ", LEFT);
    drawString(x - 60, y + 52, " * * ", LEFT);
  }
}

void addtstorm(int x, int y, int scale) {//рисуем шторм
  y = y - 5 + scale / 2;
  for (int i = 0; i < 5; i++) {
    display.drawLine(x - scale * 4 + scale * i * 1.5 + 0, y + scale * 1.5, x - scale * 3.5 + scale * i * 1.5 + 0, y + scale, GxEPD_RED);
    if (scale != Small) {
      display.drawLine(x - scale * 4 + scale * i * 1.5 + 1, y + scale * 1.5, x - scale * 3.5 + scale * i * 1.5 + 1, y + scale, GxEPD_RED);
     // display.drawLine(x - scale * 4 + scale * i * 1.5 + 2, y + scale * 1.5, x - scale * 3.5 + scale * i * 1.5 + 2, y + scale, GxEPD_BLACK);
    }
    display.drawLine(x - scale * 4 + scale * i * 1.5, y + scale * 1.5 + 0, x - scale * 3 + scale * i * 1.5 + 0, y + scale * 1.5 + 0, GxEPD_RED);
    if (scale != Small) {
      display.drawLine(x - scale * 4 + scale * i * 1.5, y + scale * 1.5 + 1, x - scale * 3 + scale * i * 1.5 + 0, y + scale * 1.5 + 1, GxEPD_RED);
     // display.drawLine(x - scale * 4 + scale * i * 1.5, y + scale * 1.5 + 2, x - scale * 3 + scale * i * 1.5 + 0, y + scale * 1.5 + 2, GxEPD_BLACK);
    }
    display.drawLine(x - scale * 3.5 + scale * i * 1.4 + 0, y + scale * 2.5, x - scale * 3 + scale * i * 1.5 + 0, y + scale * 1.5, GxEPD_RED);
    if (scale != Small) {
      display.drawLine(x - scale * 3.5 + scale * i * 1.4 + 1, y + scale * 2.5, x - scale * 3 + scale * i * 1.5 + 1, y + scale * 1.5, GxEPD_RED);
    //  display.drawLine(x - scale * 3.5 + scale * i * 1.4 + 2, y + scale * 2.5, x - scale * 3 + scale * i * 1.5 + 2, y + scale * 1.5, GxEPD_BLACK);
    }
  }
}

void addsun(int x, int y, int scale, bool IconSize) {//рисуем солнце
  int linesize = 5/2;
 //  display.fillRoundRect(35, 65, 18, 180, 10, GxEPD_BLACK);//x y w h R
  display.fillRect(x - scale * 2, y, scale * 4, linesize, GxEPD_RED);
  display.fillRect(x, y - scale * 2, linesize, scale * 4, GxEPD_RED);
 display.drawLine(x - scale * 1.3, y - scale * 1.3, x + scale * 1.3, y + scale * 1.3, GxEPD_RED);
  display.drawLine(x - scale * 1.3, y + scale * 1.3, x + scale * 1.3, y - scale * 1.3, GxEPD_RED);
  if (IconSize == LargeIcon) {
    display.drawLine(1 + x - scale * 1.3, y - scale * 1.3, 1 + x + scale * 1.3, y + scale * 1.3, GxEPD_RED);
    display.drawLine(2 + x - scale * 1.3, y - scale * 1.3, 2 + x + scale * 1.3, y + scale * 1.3, GxEPD_RED);
    display.drawLine(3 + x - scale * 1.3, y - scale * 1.3, 3 + x + scale * 1.3, y + scale * 1.3, GxEPD_RED);
   display.drawLine(1 + x - scale * 1.3, y + scale * 1.3, 1 + x + scale * 1.3, y - scale * 1.3, GxEPD_RED);
    display.drawLine(2 + x - scale * 1.3, y + scale * 1.3, 2 + x + scale * 1.3, y - scale * 1.3, GxEPD_RED);
    display.drawLine(3 + x - scale * 1.3, y + scale * 1.3, 3 + x + scale * 1.3, y - scale * 1.3, GxEPD_RED);
  }
  display.fillCircle(x, y, scale * 1.3, GxEPD_WHITE);
  display.fillCircle(x, y, scale, GxEPD_RED);
//  display.fillCircle(x, y, scale - linesize, GxEPD_WHITE);
}

void addfog(int x, int y, int scale, int linesize, bool IconSize) {//рисуем туман
  if (IconSize == SmallIcon) {
    y -= 10;
    linesize = 1;
  }
  for (int i = 0; i < 6; i++) {
    // display.fillRect(35, 65, 18, 180, 10, GxEPD_BLACK);//x y w h R
    display.fillRect(x - scale * 3, y + scale * 1.5, scale * 6, linesize,  GxEPD_BLACK);
    display.fillRect(x - scale * 3, y + scale * 2.0, scale * 6, linesize,  GxEPD_BLACK);
    display.fillRect(x - scale * 3, y + scale * 2.5, scale * 6, linesize,  GxEPD_BLACK);
  }
}

void drawString(int x, int y, String text, alignment align) {
  char * data  = const_cast<char*>(text.c_str());
  int  x1, y1; //the bounds of x,y and w and h of the variable 'text' in pixels.
  int w, h;
 // int xx = x, yy = y;
    if (align == RIGHT)  x = x - w;
  if (align == CENTER) x = x - w / 2;
   display.setCursor(x,y);
 display.print(text );
 // get_text_bounds(&currentFont, data, &xx, &yy, &x1, &y1, &w, &h, NULL);

 // int cursor_y = y + h;
 // write_string(&currentFont, data, &x, &cursor_y, framebuffer);
}
