39 lines
971 B
Python
39 lines
971 B
Python
import struct
|
|
import math
|
|
import random
|
|
|
|
def generate_bin(filename="simulation.bin", points=200):
|
|
# Magic Number: 0xFEAA01
|
|
MAGIC = 0xFEAA01
|
|
|
|
x_data = []
|
|
y_data = []
|
|
|
|
# Generate Sine Wave with random noise/phase to show updates
|
|
phase_shift = random.random() * math.pi
|
|
|
|
for i in range(points):
|
|
x = (i / points) * (4 * math.pi)
|
|
y = math.sin(x + phase_shift)
|
|
|
|
x_data.append(x)
|
|
y_data.append(y)
|
|
|
|
# Pack Data
|
|
# Header: Magic (I), Count (I)
|
|
header = struct.pack('<II', MAGIC, points)
|
|
|
|
# Body: X floats (f), Y floats (f)
|
|
body_x = struct.pack(f'<{points}f', *x_data)
|
|
body_y = struct.pack(f'<{points}f', *y_data)
|
|
|
|
with open(filename, 'wb') as f:
|
|
f.write(header)
|
|
f.write(body_x)
|
|
f.write(body_y)
|
|
|
|
print(f"Generated {filename} with {points} points (Phase: {phase_shift:.2f})")
|
|
|
|
if __name__ == "__main__":
|
|
generate_bin()
|