import math x_list = range(-15, 17, 1) y_list = [] point_list = [] for x in x_list: y = (x)**2 - (x) - 50 y_list.append(y) point = codesters.Point(x, y) point_list.append(point) label_list = [ 50, 40, 30, 25, 20, 15, 10, 8, 6, 5, 4, 3, 2.5, 2, 1.5, 1, .5, .25, .1, .05, .025, .01, .005] scale_list = [] for label in label_list: scale_factor = 50./label scale_list.append(scale_factor) vert_line_list = [] hor_line_list = [] side_label_list = [] bottom_label_list = [] labels = range(-200, 201, 50) for label in labels: if label == 0: label_text = "0" color = "black" y_arrow = codesters.Triangle(0, 220, 10, color) x_arrow = codesters.Triangle(220, 0, 10, color) x_arrow.set_rotation(-90) x_label = codesters.Text("x", 240, 0) x_label.set_size(.8) y_label = codesters.Text("y", 0, 240) y_label.set_size(.8) else: label_text = label color = "grey" vert_line = codesters.Line(label, -220, label, 225, color) hor_line = codesters.Line(-220, label, 225, label, color) side_label = codesters.Text(label_text, -235, label) side_label.set_size(.6) bottom_label = codesters.Text(label_text, label, -240) bottom_label.set_size(.6) vert_line_list.append(vert_line) hor_line_list.append(hor_line) side_label_list.append(side_label) bottom_label_list.append(bottom_label) box_dictionary = {} text_dictionary = {} def draw_box(box_dict, box_x, box_y, box_color, text_color, box_text, box_name, text_name): box_instance = codesters.Rectangle(box_x, box_y, 75, 20 , box_color, text_color) text_instance = codesters.Text(box_text, box_x, box_y, text_color) text_instance.set_size(.7) box_dictionary[box_name] = box_instance box_dictionary[text_name] = text_instance return box_dict zoom_box_color = "lightgreen" zoom_text_color = "darkgreen" shift_box_color = "lightblue" shift_text_color = "darkblue" flip_box_color = "pink" flip_text_color = "red" box_dictionary = draw_box(box_dictionary, 200, 25, zoom_box_color, zoom_text_color, "x Zoom +", "x_zoom_in_box", "x_zoom_in_text") x_zoom_in_box = box_dictionary["x_zoom_in_box"] x_zoom_in_text = box_dictionary["x_zoom_in_text"] x_zoom_out_box = codesters.Rectangle(200, -25, 75, 20 , zoom_box_color, zoom_text_color) x_zoom_out_text = codesters.Text("x Zoom -", 200, -25, zoom_text_color) x_zoom_out_text.set_size(.7) y_zoom_in_box = codesters.Rectangle(55, 230, 75, 20 , zoom_box_color, zoom_text_color) y_zoom_in_text = codesters.Text("y Zoom +", 58, 230, zoom_text_color) y_zoom_in_text.set_size(.7) y_zoom_out_box = codesters.Rectangle(-55, 230, 75, 20 , zoom_box_color, zoom_text_color) y_zoom_out_text = codesters.Text("y Zoom -", -58, 230, zoom_text_color) y_zoom_out_text.set_size(.7) x_shift_right_box = codesters.Rectangle(55, -220, 75, 20 , shift_box_color, shift_text_color) x_shift_right_text = codesters.Text("x Shift -->", 58, -220, shift_text_color) x_shift_right_text.set_size(.7) x_shift_left_box = codesters.Rectangle(-55, -220, 75, 20 , shift_box_color, shift_text_color) x_shift_left_text = codesters.Text("<-- x Shift", -58, -220, shift_text_color) x_shift_left_text.set_size(.7) y_shift_up_box = codesters.Rectangle(-200, 25, 75, 20 , shift_box_color, shift_text_color) y_shift_up_text = codesters.Text("y Shift /\\", -200, 25, shift_text_color) y_shift_up_text.set_size(.7) y_shift_down_box = codesters.Rectangle(-200, -25, 75, 20 , shift_box_color, shift_text_color) y_shift_down_text = codesters.Text("y Shift \/", -200, -25, shift_text_color) y_shift_down_text.set_size(.7) box_dictionary = draw_box(box_dictionary, -170, -150, flip_box_color, flip_text_color, "y-axis flip", "y_axis_flip_box", "y_axis_flip_text") y_axis_flip_box = box_dictionary["y_axis_flip_box"] y_axis_flip_text = box_dictionary["y_axis_flip_text"] box_dictionary = draw_box(box_dictionary, -170, -175, flip_box_color, flip_text_color, "x-axis flip", "x_axis_flip_box", "x_axis_flip_text") x_axis_flip_box = box_dictionary["x_axis_flip_box"] x_axis_flip_text = box_dictionary["x_axis_flip_text"] box_dictionary = draw_box(box_dictionary, -170, -200, flip_box_color, flip_text_color, "y = x flip", "y_equals_x_box", "y_equals_x_text") y_equals_x_box = box_dictionary["y_equals_x_box"] y_equals_x_text = box_dictionary["y_equals_x_text"] x_scale = 1 y_scale = 1 y_zoom_count = 0 x_zoom_count = 0 x_shift_count = 0 y_shift_count = 0 x_flip_status = 1 y_flip_status = 1 yx_flip_status = 1 def draw(x_zoom, y_zoom, x_shift, y_shift, hor_flip, vert_flip, yx_flip): global y_zoom_count global x_zoom_count global x_shift_count global y_shift_count global x_flip_status global y_flip_status global yx_flip_status global x_scale global y_scale x_zoom_count += x_zoom y_zoom_count += y_zoom if x_zoom_count < 0: x_zoom_count = 0 if y_zoom_count < 0: y_zoom_count = 0 x_shift_count += x_shift y_shift_count += y_shift x_flip_status *= hor_flip y_flip_status *= vert_flip yx_flip_status *= yx_flip x_scale = scale_list[x_zoom_count] y_scale = scale_list[y_zoom_count] actual_x_shift = x_shift_count * x_scale actual_y_shift = y_shift_count * y_scale for label in labels: j = labels.index(label) if label == 0: x_label_text = "0" y_label_text = "0" else: x_label_text = round(label/x_scale,1) y_label_text = round(label/y_scale,1) bottom_label_list[j].set_text(x_label_text) side_label_list[j].set_text(y_label_text) for i in range(len(point_list)): x_spot = (x_list[i] * x_scale + actual_x_shift) * x_flip_status y_spot = (y_list[i] * y_scale + actual_y_shift) * y_flip_status x_temp = x_spot y_temp = y_spot x_spot = x_temp*((yx_flip_status+1)/2) + y_temp*((yx_flip_status-1)/(-2)) y_spot = y_temp*((yx_flip_status+1)/2) + x_temp*((yx_flip_status-1)/(-2)) point_list[i].set_position(x_spot,y_spot) def x_zoom_in(): draw(1, 0, 0, 0, 1, 1, 1) x_zoom_in_box.event_click(x_zoom_in) def x_zoom_out(): draw(-1, 0, 0, 0, 1, 1, 1) x_zoom_out_box.event_click(x_zoom_out) def y_zoom_in(): draw(0, 1, 0, 0, 1, 1, 1) y_zoom_in_box.event_click(y_zoom_in) def y_zoom_out(): draw(0, -1, 0, 0, 1, 1, 1) y_zoom_out_box.event_click(y_zoom_out) def x_shift_right(): draw(0, 0, 1, 0, 1, 1, 1) x_shift_right_box.event_click(x_shift_right) def x_shift_left(): draw(0, 0, -1, 0, 1, 1, 1) x_shift_left_box.event_click(x_shift_left) def y_shift_up(): draw(0, 0, 0, 1, 1, 1, 1) y_shift_up_box.event_click(y_shift_up) def y_shift_down(): draw(0, 0, 0, -1, 1, 1, 1) y_shift_down_box.event_click(y_shift_down) def x_flip(): draw(0, 0, 0, 0, -1, 1, 1) x_axis_flip_box.event_click(x_flip) def y_flip(): draw(0, 0, 0, 0, 1, -1, 1) y_axis_flip_box.event_click(y_flip) def x_equals_x_flip(): draw(0, 0, 0, 0, 1, 1, -1) y_equals_x_box.event_click(x_equals_x_flip) pos_text = codesters.Text() pos_text.set_size(.6) pos_text.set_color("green") def mouse_move(): global x_scale global y_scale x = stage.mouse_x() y = stage.mouse_y() pos_text.set_position(x+20, y) pos_text.set_text("("+str(int(round(x/x_scale,0)))+", "+str(int(round(y/y_scale,0)))+")") stage.event_mouse_move(mouse_move)
  • Run Code
  • Show Console
  • Codesters How To (opens in a new tab)