|
13 | 13 | k = 1e3 # spring stiffness |
14 | 14 | n_seg = 4 # num of segments per side of the square |
15 | 15 | h = 0.02 # time step size in s |
16 | | -DBC = [0, (n_seg + 1) * n_seg] # fix the left and right top nodes |
| 16 | +DBC = [n_seg, (n_seg + 1) * (n_seg + 1) - 1] # fix the left and right top nodes |
17 | 17 |
|
18 | 18 | # initialize simulation |
19 | 19 | [x, e] = square_mesh.generate(side_len, n_seg) # node positions and edge node indices |
|
29 | 29 | is_DBC = [False] * len(x) |
30 | 30 | for i in DBC: |
31 | 31 | is_DBC[i] = True |
32 | | - |
33 | 32 | # simulation with visualization |
| 33 | +resolution = np.array([900, 900]) |
| 34 | +offset = resolution / 2 |
| 35 | +scale = 200 |
| 36 | +def screen_projection(x): |
| 37 | + return [offset[0] + scale * x[0], resolution[1] - (offset[1] + scale * x[1])] |
| 38 | + |
34 | 39 | time_step = 0 |
35 | | -screen = pygame.display.set_mode([900, 900]) |
| 40 | +screen = pygame.display.set_mode(resolution) |
36 | 41 | running = True |
37 | 42 | while running: |
38 | 43 | # run until the user asks to quit |
|
45 | 50 | # fill the background and draw the square |
46 | 51 | screen.fill((255, 255, 255)) |
47 | 52 | for eI in e: |
48 | | - pygame.draw.aaline(screen, (0, 0, 255), 450 + x[eI[0]] * 200, 450 + x[eI[1]] * 200) |
| 53 | + pygame.draw.aaline(screen, (0, 0, 255), screen_projection(x[eI[0]]), screen_projection(x[eI[1]])) |
49 | 54 | for xI in x: |
50 | | - pygame.draw.circle(screen, (0, 0, 255), 450 + xI * 200, 0.1 * side_len / n_seg * 200) |
| 55 | + pygame.draw.circle(screen, (0, 0, 255), screen_projection(xI), 0.1 * side_len / n_seg * scale) |
51 | 56 |
|
52 | 57 | pygame.display.flip() # flip the display |
53 | 58 |
|
|
0 commit comments