|
18 | 18 | # for display chip driver and pinout you have (e.g. ILI9341) |
19 | 19 |
|
20 | 20 | # Generate data - here we'll make a normal distribution |
21 | | -X_LOWER_BOUND = 0 |
22 | | -X_UPPER_BOUND = 10 |
23 | 21 | raw_data = [] |
24 | 22 | data = [] |
| 23 | +MAX_DICE_SIDE = 20 |
| 24 | +NUMBER_OF_DICE = 10 |
| 25 | +NUMBER_OF_ROLLS = 500 |
25 | 26 |
|
26 | | -for _ in range(100): |
27 | | - data_point = int(10 * random.random(X_LOWER_BOUND, X_UPPER_BOUND + 1)) |
28 | | - raw_data.append(data_point) |
| 27 | +for _ in range(NUMBER_OF_ROLLS): |
| 28 | + # Simulate equivalent dice rolls |
| 29 | + sum_random = 0 |
| 30 | + for _ in range(NUMBER_OF_DICE): |
| 31 | + sum_random += random.uniform(1, MAX_DICE_SIDE) |
| 32 | + average_random = sum_random // NUMBER_OF_DICE |
| 33 | + raw_data.append(average_random) |
29 | 34 |
|
| 35 | +# Calculate the number of each roll result and pair with itself |
30 | 36 | y_upper_bound = 0 |
31 | | -for value in range(len(X_UPPER_BOUND + 1)): |
32 | | - value_count = raw_data.count(value) |
33 | | - data.append(value_count) |
| 37 | +for value in range(MAX_DICE_SIDE + 1): |
| 38 | + value_count = raw_data.count(value) / 10 |
| 39 | + data.append((value, value_count)) |
34 | 40 | y_upper_bound = max(y_upper_bound, value_count) |
35 | 41 |
|
36 | 42 | # pybadge display: 160x128 |
|
41 | 47 | y=2, # y plane position |
42 | 48 | width=135, # display width |
43 | 49 | height=105, # display height |
44 | | - xrange=(X_LOWER_BOUND, X_UPPER_BOUND), # x range |
| 50 | + xrange=(0, MAX_DICE_SIDE), # x range |
45 | 51 | yrange=(0, y_upper_bound), # y range |
46 | 52 | fill_area=True, |
47 | 53 | ) |
|
54 | 60 |
|
55 | 61 | for x, y in data: |
56 | 62 | my_plane.add_plot_line(x, y) |
57 | | - time.sleep(0.5) |
| 63 | + time.sleep(0.1) |
58 | 64 |
|
59 | 65 | while True: |
60 | 66 | pass |
0 commit comments