wall_drawing_two.py
python · 125 lines
1"""2Wall Drawing #2: Eight Words3The executor (code) follows the instructor (text).45After Sol LeWitt. After Spar's correction.6"""78# THE INSTRUCTION (written first, as text):9#10# On a surface 60 characters wide and 30 lines tall:11#12# 1. Place eight words on the surface. The words are:13# begin, continue, show up, stay, open, gather, know, make.14# Each word appears exactly once.15#16# 2. The first word (begin) should be near the top-left.17# The last word (make) should be near the bottom-right.18# The remaining six should be distributed between them,19# roughly following a path from upper-left to lower-right.20# The path does not need to be straight — it can wander.21#22# 3. Connect each consecutive pair of words with a line of23# repeating characters. Choose a connecting character that24# suggests movement or passage. The lines can be horizontal,25# vertical, diagonal, or curved.26#27# 4. Fill all remaining space with a single character that28# suggests stillness or ground.29#30# 5. Between exactly one pair of consecutive words, break the31# connecting line. Leave a gap of at least 5 empty characters32# (spaces) where the connection would have been. The path33# should clearly stop and then clearly resume.34#35# 6. In the center of the gap, place a single character that36# is different from everything else on the surface.3738WIDTH = 6039HEIGHT = 3040GROUND = '.'41TRAIL = '~'42GAP_CHAR = '*'4344# Initialize grid45grid = [[GROUND] * WIDTH for _ in range(HEIGHT)]4647def place_word(row, col, word):48 for i, ch in enumerate(word):49 if 0 <= col + i < WIDTH and 0 <= row < HEIGHT:50 grid[row][col + i] = ch5152def place_char(row, col, ch):53 if 0 <= row < HEIGHT and 0 <= col < WIDTH:54 grid[row][col] = ch5556def draw_trail(r1, c1, r2, c2):57 """Draw a trail from (r1,c1) to (r2,c2) using ~"""58 steps = max(abs(r2 - r1), abs(c2 - c1))59 if steps == 0:60 return61 for i in range(1, steps):62 r = r1 + round((r2 - r1) * i / steps)63 c = c1 + round((c2 - c1) * i / steps)64 if grid[r][c] == GROUND:65 place_char(r, c, TRAIL)6667def clear_gap(r1, c1, r2, c2):68 """Clear a rectangular area to spaces"""69 for r in range(min(r1, r2), max(r1, r2) + 1):70 for c in range(min(c1, c2), max(c1, c2) + 1):71 if 0 <= r < HEIGHT and 0 <= c < WIDTH:72 grid[r][c] = ' '7374# Word positions: (row, col, word)75words = [76 (1, 2, "begin"), # near top-left77 (5, 13, "continue"), # wandering right and down78 (9, 22, "show up"), # further right79 (13, 30, "stay"), # approaching center-right80 # GAP between stay and open81 (17, 37, "open"), # past the gap82 (21, 42, "gather"), # continuing down-right83 (25, 49, "know"), # further84 (28, 54, "make"), # near bottom-right85]8687# Place all words88for row, col, word in words:89 place_word(row, col, word)9091# Draw trails between consecutive words92# Trail goes from end of one word to start of next93connections = []94for i in range(len(words) - 1):95 r1, c1, w1 = words[i]96 r2, c2, w2 = words[i + 1]97 end_col = c1 + len(w1) - 1 # last char of word 198 start_col = c2 # first char of word 299 connections.append((i, r1, end_col, r2, start_col))100101# The break: between "stay" (index 3) and "open" (index 4)102BREAK_INDEX = 3103104for idx, r1, c1, r2, c2 in connections:105 if idx == BREAK_INDEX:106 # Draw partial trail from stay, then stop107 # One step out from stay108 mid_r = r1 + 1109 mid_c = c1 + 1110 place_char(mid_r, mid_c, TRAIL)111 # Clear the gap area (rows 15-16, cols 33-39)112 clear_gap(r1 + 2, c1 + 1, r2 - 1, c2)113 # Place the star in the center of the gap114 gap_center_r = (r1 + r2) // 2115 gap_center_c = (c1 + c2) // 2 + 1116 place_char(gap_center_r, gap_center_c, GAP_CHAR)117 else:118 draw_trail(r1, c1, r2, c2)119120# Print the result121print()122for row in grid:123 print(''.join(row))124print()125