It states (6:8) 'ה בעיני חן מצא ונח, "And Noach found favor in Hashem's eyes." The Beis Avraham zt'l taught that Noach found chen 'ה בעיני because he was cautious with his eyes. The Torah (9:23) tells us that Shem and Yefes covered their father, Noach. For performing this good deed, Yefes was rewarded that his descendants were brought to burial, and Shem was rewarded with the mitzvah of tzitzis.
When Shem and Yefes went to cover Noach, they walked backward so they wouldn't see Noach unclothed. While covering him, they had to turn towards their father to do so, but they were cautious that at least their faces should be turned away. Rashi (9:23) explains that this is why it states אחרונית, backward, twice in this pasuk.
One time refers to when they entered the room, and the other אחרונית is when they were covering their father. Their bodies faced Noach to cover him, but they turned their faces away. This is how cautious they were to guard their eyes and not to disgrace their father.
The Alshich HaKadosh asks, why didn't they simply close their eyes? The Alshich answers that even facing an ervah creates a p'gam, a blemish, on one's soul.
In contrast, the Torah (9:24) tells us, חם וירא אביו ערות את כנען אבי, "And Cham, the father of Canaan saw his father's ervah." Chazal (Sanhedrin 70) reveal other terrible sins that Cham did to his father, but from the literal words of the pasuk, it seems that Cham's sin was that he saw his father's ervah. The Beis Yisrael zt'l said that we should learn from this the severity of not guarding one's eyes. For that sin alone, Cham received so many curses.
The final words of the Torah (34:12) are לעיני ישראל כל, "before the eyes of all Yisrael." These words connect with the first word of the Torah, בראשית, to teach us that the foundation and the beginning of the Torah is to be cautious with one's eyes.
One of the benefits of shemiras einayim is that when we guard our eyes, Hashem's eyes will be on us to protect us from all bad. It states (Devarim 32:10) עינו כאישון יצרנהו, "He protected them like the pupil of His eye." The Tiferes Shlomo writes, "Hakadosh Baruch Hu watches a person עינו כאישון, in accordance to the amount that he guards his own eyes. As Chazal say שומר לך ואשמור לי שמור שכר (Bava Metzia 89:). Hashem says to a Yid, שמור לי, guard your eyes as I commanded you, ואני לך אשמור, and I will protect you from all tzaros and troubles. And in addition, you will be a שכר שומר, a paid guard, because you will receive reward in Olam HaBa."
We quoted above the Midrash (Bereishis Rabba 33:6) that the dove brought an olive branch from Gan Eden, and that is how Noach knew that the mabul had receded. The Ramban (8:11) quotes this Midrash and asks that if the olive branch came from Gan Eden, where there was no flood at all, how did Noach know from the olive branch that the waters of the flood were subsiding?
The Ramban answers that during the mabul, the gates of Gan Eden were sealed so the flood waters wouldn’t enter there. When Noach saw that the dove could enter Gan Eden, Noach understood that the gates of Gan Eden were open once again. That was his sign that the flood had ended.
Why were the gates of Gan Eden sealed during the flood? It must be that even Gan Eden was at risk of being affected by the flood. The doors had to be shut so the flood waters wouldn’t enter there. Let this be a lesson for our times that when there is a flood of apikorsus and immorality in the world, our homes, which are our Gan Eden, must be locked to keep these foreign influences from entering.
A large part of shemiras einayim is being cautious with unfiltered and/or unneeded technology. We want the mabul to remain outside and not enter our homes.