Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # *Square Wave Pattern* by @CodingComputing
- # Parameters
- num_cycles = 3 # How many repeating cycles are present?
- high_width = 2 # How long is the wave high in each cycle?
- low_before_width = 1 # Before the wave moves up to high, how long is it low?
- low_after_width = 1 # After the wave moves down from high, how long is it low?
- height = 4 # How high does the wave go?
- # Develop Column-wise representation
- # L for Low, H for High, T for Transition
- single_cycle_col_repr = 'L'*low_before_width + 'T' + 'H'*high_width + 'T' + 'L'*low_after_width
- full_col_repr = single_cycle_col_repr * num_cycles
- # Form each row and draw!
- for row_idx in range(height):
- if row_idx == 0: # Top row. '*' comes for H or T type columns
- row_items = [(' ' if c=='L' else '*') for c in full_col_repr]
- elif row_idx == height-1: # Bottom row. '*' comes for L or T type columns
- row_items = [(' ' if c=='H' else '*') for c in full_col_repr]
- else: # Middle row. '*' comes only T type columns
- row_items = [('*' if c=='T' else ' ') for c in full_col_repr]
- print(''.join(row_items)) # Output the row
- # Output:
- # **** **** ****
- # * * * * * *
- # * * * * * *
- # ** **** **** **
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement