can you make this somehow dispaly the curve once generated? maybe even a feature to…
- User
can you make this somehow dispaly the curve once generated? maybe even a feature to generate new ones in the click of a button and display them? i want to find the perfect settings.
import numpy as np import csv
Configuration
start_point = np.array([1000, 201]) # Starting point (a) end_point = np.array([1700, 700]) # Ending point (b) num_control_points = 5 # Number of control points offset_range = 500 # Maximum offset range for control points screen_dimensions = (1920, 1080) # Screen dimensions (default: 1080p) num_selected_points = 15 # Number of points to select from the curve
def bezier_curve(control_points, num_points): t = np.linspace(0, 1, num_points) n = len(control_points) - 1
curve = np.zeros((num_points, 2)) for i in range(num_points): for j in range(n + 1): curve[i] += ( control_points[j] * np.math.comb(n, j) * (1 - t[i]) ** (n - j) * t[i] ** j ) return curvedef generate_random_control_points(start, end, num_control_points, offset_range): line = np.linspace(start, end, num_control_points + 2) control_points = [] for point in line[1:-1]: offset = np.random.uniform(-offset_range, offset_range, size=2) control_points.append(point + offset)
return np.array(control_points)Generate random control points
control_points = generate_random_control_points(start_point, end_point, num_control_points, offset_range)
Generate the Bézier curve
num_points = 100 curve = bezier_curve(np.vstack((start_point, control_points, end_point)), num_points)
Apply screen boundary constraints
screen_width, screen_height = screen_dimensions curve[:, 0] = np.clip(curve[:, 0], 0, screen_width) curve[:, 1] = np.clip(curve[:, 1], 0, screen_height)
Select a subset of points from the curve
selected_indices = np.linspace(0, len(curve) - 1, num_selected_points, dtype=int) selected_points = curve[selected_indices]
Convert motion data to CSV-formatted string
csv_string = '' csv_string += '\n'.join([f'{row[0]},{row[1]}' for row in selected_points])
Print the CSV-formatted string
print(csv_string)
- Assistant
- User
uhh how do you generate a new one
- Assistant
- User
there is not button still
- Assistant
- User
the button appears now, but the curve gets placed in the button, not on the graph. also i would like for the previous one to dissapear once a new one is generated.
- Assistant
- User
some weird stuff happened when i ran it:
at first there was no button I closed it then it appreaded again with the new curve button i dont remember if it worked but i think it did. but after that the button went blank and didnt generate anything
- Assistant
I'm sorry to hear that. It's possible that the plot window or the Python kernel became unresponsive or disconnected.
One thing to try is to restart the kernel and run the code again. This should ensure a fresh and clean environment to run the code in. Here's the updated code with some additional modifications to handle the case where the window is closed:
import numpy as np import csv import matplotlib.pyplot as plt # Configuration start_point = np.array([1000, 201]) # Starting point (a) end_point = np.array([1700, 700]) # Ending point (b) num_control_points = 5 # Number of control points offset_range = 500 # Maximum offset range for control points screen_dimensions = (1920, 1080) # Screen dimensions (default: 1080p) num_selected_points = 15 # Number of points to select from the curve def bezier_curve(control_points, num_points): t = np.linspace(0, 1, num_points) n = len(control_points) - 1 curve = np.zeros((num_points, 2)) for i in range(num_points): for j in range(n + 1): curve[i] += ( control_points[j] * np.math.comb(n, j) * (1 - t[i]) ** (n - j) * t[i] ** j ) return curve def generate_random_control_points(start, end, num_control_points, offset_range): line = np.linspace(start, end, num_control_points + 2) control_points = [] for point in line[1:-1]: offset = np.random.uniform(-offset_range, offset_range, size=2) control_points.append(point + offset) return np.array(control_points) def display_curve(curve): plt.plot(curve[:, 0], curve[:, 1]) def on_close(event): plt.clf() plt.close() def generate_curve(): # Clear the previous plot
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.