This is the account of Noah.
Noah was a righteous man, blameless among the people of his time, and he walked with God. Noah had three sons: Shem, Ham and Japheth.
Now the earth was corrupt in God’s sight and was full of violence. God saw how corrupt the earth had become, for all the people on earth had corrupted their ways. So God said to Noah, “I am going to put an end to all people, for the earth is filled with violence because of them. I am surely going to destroy both them and the earth. So make yourself an ark of cypress wood; make rooms in it and coat it with pitch inside and out... I am going to bring floodwaters on the earth to destroy all life under the heavens, every creature that has the breath of life in it. Everything on earth will perish. But I will establish my covenant with you, and you will enter the ark—you and your sons and your wife and your sons’ wives with you. You are to bring into the ark two of all living creatures, male and female, to keep them alive with you. Two of every kind of bird, of every kind of animal and of every kind of creature that moves along the ground will come to you to be kept alive. You are to take every kind of food that is to be eaten and store it away as food for you and for them.”
Noah did everything just as God commanded him.
Genesis 6:9-14, 17-22
When Moses ascended Mount Sinai to receive the Ten Commandments, he drew nearer to the Lord physically than any man before him had (with the possible exception of Adam in Eden.) Because our God is excellent in beauty this nearness only caused Moses' heart yearn to see more of His Lord. So, in Exodus 34 Moses asks God to show him His glory. Since our God is good and loving and since He had already chosen to "speak to Moses face to face, as a man speaks with his friend," He obliged (Exodus 33:11). He told Moses that no man could see His face and live, so He hid Moses in the cleft of a rock and He covered that cleft with His hand as He passed by. Once His glory had passed by He removed His hand and allowed Moses to see His back while He proclaimed His name. This is what He said...
The LORD, the LORD, the compassionate and gracious God, slow to anger, abounding in love and faithfulness, maintaining love to thousands, and forgiving wickedness, rebellion and sin. Yet he does not leave the guilty unpunished; he punishes the children and their children for the sin of the fathers to the third and fourth generation. (Exodus 34:6-7)
I bring this up because I believe that these two verses are a helpful lens through which to view the flood narrative. In them God describes Himself as both one who forgives wickedness in His grace and one who does not leave the guilty unpunished. He is slow to anger and He punishes the children and their children for the sin of the fathers to the third and fourth generation. There is an obvious tension here, a tension which was not fully resolved until Christ died on the cross. By laying the sin of the world on Christ, God was able to both punish the wickedness of our sin to its full extent and show grace to His children. In the flood we see vestiges of this in reverse. Instead of God's wrath being poured out on one perfect man while many wicked men received His grace, we have the opposite. He pours out His wrath on many wicked men while one good man receives His grace.
Though we may shrink from the idea that God would kill every person on earth and only save a small remnant, Scripture does not. There is no hesitation, no shame, and no question. God proclaims simply, "I am going to put an end to all people, for the earth is filled with violence because of them." Notice though that God is not capricious with His anger. He is not killing people for no reason. Everyone who died in the flood deserved what they received from God's hand. God's justice is plain in the Biblical account. He will not allow sin to grow unchecked in His creation. Yet, God is not merely just, He is also gracious. He does not turn His back on His creation altogether. He provides a small remnant with whom He promises to make a covenant, a fresh start. He has not forgotten His promise to Eve or His original intent in creating man. His purposes will prevail. He will not be defeated by man's rebellion and sin.
This is true for God's children at the individual level as well. God's purposes for your life will not be thwarted by your sin and rebellion. Remember this when God's just punishment enters your life. For those who call on His name, there is always a remnant of hope. Though you buckle under the weight of your sin and His punishment, do not despair. Christ has already secured the forgiveness of your sin. Remind yourself that God is "gracious and compassionate, slow to anger and abounding in love." He disciplines those He loves (Revelation3:19-20). His discipline is designed to bring you back in line with His will and plan for your life. "He will not forsake you or leave you," (Deuteronomy 31:6) so submit yourself to His calling on your life and "all things will work together for your good" (Romans 8:28).
For further reading...