logoStarPatterns
Back to Patterns

Heart Pattern

Pattern Result

*** ***
*****_*****
***********
*********
*******
*****
***
*

Code Implementation

Explanation

The Heart Pattern creates a shape that resembles a heart using asterisks. The pattern consists of three parts: the top part forms two half circles, the middle part connects the two half circles, and the bottom part forms an inverted pyramid. The algorithm ensures that n is even to create a symmetrical heart. The top part places stars at specific positions to create the curved top of the heart. The middle part fills the entire row with stars except for the middle position. The bottom part creates an inverted pyramid by adding spaces at the beginning and end of each row, with the number of spaces increasing and the number of stars decreasing as the row number increases.