def main(): n = int(sys.argv[1]) dist = stdarray.readFloat1D() cx = stdarray.readFloat2D() cy = stdarray.readFloat2D() x = 0.0 y = 0.0 #stddraw.setPenRadius(0.1) #stddraw.setPenColor(stddraw.ORANGE) #stddraw.point(0, 0) #stddraw.setPenRadius(0.1) #stddraw.setPenColor(stddraw.GREEN) #stddraw.point(1, 1) #stddraw.setPenRadius(0.1) #stddraw.setPenColor(stddraw.BLUE) #stddraw.point(0.5, 0.5) #stddraw.setPenColor(stddraw.BLACK) #stddraw.point(0.5, 0.288) stddraw.setPenRadius(0.003) #stddraw.setPenColor(stddraw.RED) for i in range(n): r = stdrandom.discrete(dist) x0 = cx[r][0] * x + cx[r][1] * y + cx[r][2] y0 = cy[r][0] * x + cy[r][1] * y + cy[r][2] x = x0 y = y0 stddraw.point(x * 0.7 + 0.25, y * 0.7 + 0.25) stddraw.show()
def main(): n = int(sys.argv[1]) for i in range(n): x = stdrandom.gaussian(0.5, 0.2) y = stdrandom.gaussian(0.5, 0.2) stddraw.point(x, y) stddraw.show()
def _draw_points(array, pointcolor): """ @param array: Array with points @param pointcolor: Color of points Draws given points in a color (TO BE USED FOR draw_data_random() FUNCTION) """ stddraw.setPenColor(pointcolor) for point in array: stddraw.point(point[0], point[1])
def plotPoints(a): """ Plot the values of array 'a' as points. """ N = len(a) stddraw.setXscale(0, N - 1) stddraw.setPenRadius(1.0 / (3.0 * N)) for i in range(N): stddraw.point(i, a[i])
def plotPoints(a): """ Plot the values of array 'a' as points. """ N = len(a) stddraw.setXscale(0, N-1) stddraw.setPenRadius(1.0 / (3.0 * N)) for i in range(N): stddraw.point(i, a[i])
def plotPoints(a): """ Plot the elements of array a as points. """ n = len(a) stddraw.setXscale(-1, n) stddraw.setPenRadius(1.0 / (3.0 * n)) for i in range(n): stddraw.point(i, a[i])
def set_the_face(): stddraw.line(6 - 0.1, 6, 5.5, 6.5) stddraw.line(5.5, 6, 6 - 0.1, 6.5) stddraw.line(6 + 0.1, 6, 6.5, 6.5) stddraw.line(6.5, 6, 6 + 0.1, 6.5) for i in range(30): stddraw.point(6 + (i * 0.01), 5.6 - (i * 0.005)) stddraw.point(6 - (i * 0.01), 5.6 - (i * 0.005))
def main(): n = int(sys.argv[1]) cx = [0.000, 1.000, 0.500] cy = [0.000, 0.000, 0.866] x = 0.0 y = 0.0 stddraw.setPenRadius(0.0) for i in range(n): r = stdrandom.uniformInt(0, 3) x = (x + cx[r]) / 2.0 y = (y + cy[r]) / 2.0 stddraw.point(x, y) stddraw.show()
def main(): n = int(sys.argv[1]) dist = stdarray.readFloat1D() cx = stdarray.readFloat2D() cy = stdarray.readFloat2D() x = 0.0 y = 0.0 stddraw.setPenRadius(0.0) for i in range(n): r = stdrandom.discrete(dist) x0 = cx[r][0] * x + cx[r][1] * y + cx[r][2] y0 = cy[r][0] * x + cy[r][1] * y + cy[r][2] x = x0 y = y0 stddraw.point(x, y) stddraw.show()
def main(): n = int(sys.argv[1]) dist = stdarray.readFloat1D() cx = stdarray.readFloat2D() cy = stdarray.readFloat2D() x = 0.0 y = 0.0 #stddraw.setPenRadius(0.1) #stddraw.setPenColor(stddraw.ORANGE) #stddraw.point(0, 0) #stddraw.setPenRadius(0.1) #stddraw.setPenColor(stddraw.GREEN) #stddraw.point(1, 1) #stddraw.setPenRadius(0.1) #stddraw.setPenColor(stddraw.BLUE) #stddraw.point(0.5, 0.5) #stddraw.setPenColor(stddraw.BLACK) #stddraw.point(0.5, 0.288) stddraw.setPenRadius(0.003) #stddraw.setPenColor(stddraw.RED) for i in range(n): r = stdrandom.discrete(dist) x0 = cx[r][0] * x + cx[r][1] * y + cx[r][2] y0 = cy[r][0] * x + cy[r][1] * y + cy[r][2] x = x0 y = y0 #cos -sin x #sin cos y angle = (2 * 3.14) / 360 * i dvd = 4 if (i % dvd == 0): stddraw.setPenColor(stddraw.BLUE) angle = 0 if (i % dvd == 1): stddraw.setPenColor(stddraw.RED) angle = 22.5 if (i % dvd == 2): stddraw.setPenColor(stddraw.GREEN) angle = 45 if (i % 4 == 3): stddraw.setPenColor(stddraw.ORANGE) angle = -22.5 x_r = x - 0.5 y_r = y - 0.288 x_1 = x_r * math.cos(angle) - y_r * math.sin(angle) y_1 = x_r * math.sin(angle) + y_r * math.cos(angle) stddraw.point(x_1 * 0.5 + 0.5, y_1 * 0.5 + 0.5) #stddraw.point(x-0.5, y-0.288) #print(str(x_1) + "_" + str(y_1)) stddraw.show()
def main(): stddraw.createWindow(1024, 256) stddraw.setPenRadius(0) stddraw.setXscale(0, _SAMPLES_PER_REDRAW) stddraw.setYscale(-.75, +.75) stddraw.show() # Create keyboardDict, a dictionary relating each keyboard key # to a guitar string. keyboardDict = {} i = 0 for key in _KEYBOARD: factor = 2 ** ((i-24) / 12.0) guitarString = guitarstring.GuitarString(_CONCERT_A * factor) keyboardDict[key] = guitarString i += 1 # pluckedGuitarStrings is the set of all guitar strings that have # been plucked. pluckedGuitarStrings = set() t = 0 # The main input loop. while True: if stddraw.hasNextKeyTyped(): # Fetch the key that the user just typed. key = stddraw.nextKeyTyped() # Figure out which guitar string to pluck, and pluck it. try: guitarString = keyboardDict[key] guitarString.pluck() pluckedGuitarStrings.add(guitarString) except KeyError: pass # Add up the samples from each plucked guitar string. Also # advance the simulation of each plucked guitar string by # one step. sample = 0.0 faintGuitarStrings = set() for guitarString in pluckedGuitarStrings: sample += guitarString.sample() guitarString.tic() if guitarString.isFaint(): faintGuitarStrings.add(guitarString) # Remove faint guitar strings from the set of plucked guitar # strings. for guitarString in faintGuitarStrings: pluckedGuitarStrings.remove(guitarString) # Play the total. stdaudio.playSample(sample) # Plot stddraw.point(t % _SAMPLES_PER_REDRAW, sample); if t == (_SAMPLES_PER_REDRAW - 1): stddraw.show() stddraw.clear() t = 0 t += 1
adjust_number = 9 adjust_number2 = 3 for i in range(12): stddraw.setFontSize(30) test3x = (math.cos(math.radians(test3)) * 0.5 * 0.82) + 0.5 test3y = (math.sin(math.radians(test3)) * 0.5 * 0.82) + 0.5 store_number = i if store_number == 0: store_number = 3 elif store_number == 1: store_number = 2 elif store_number == 2: store_number = 1 elif store_number >= 3: store_number = store_number + adjust_number adjust_number = adjust_number - 2 xx = str(store_number) stddraw.text(test3x, test3y, xx) test3 = test3 + 30 stddraw.line(.5, .5, x, y) stddraw.setPenColor(stddraw.BLUE) stddraw.line(.5, .5, x1, y1) stddraw.setPenRadius(0.01) stddraw.setPenColor(stddraw.RED) stddraw.line(.5, .5, x2, y2) stddraw.setPenColor(stddraw.BLACK) stddraw.setPenRadius(0.02) stddraw.point(.5, .5) stddraw.show()
def draw(self): stddraw.setPenRadius(0.0125) stddraw.point(self._r[0], self._r[1])
#----------------------------------------------------------------------- # triangle.py #----------------------------------------------------------------------- import stddraw import math # Draw a triangle. t = math.sqrt(3.0) / 2.0 stddraw.createWindow() stddraw.line(0.0, 0.0, 1.0, 0.0) stddraw.line(1.0, 0.0, 0.5, t) stddraw.line(0.5, t, 0.0, 0.0) stddraw.point(0.5, t/3.0) stddraw.show() stddraw.wait()
posx = ((hand_end_point(0, False) - 0.5) * math.cos(radian_angle_minutes) + (hand_end_point(1, False) - 0.5) * math.sin(radian_angle_minutes)) + 0.5 posy = ( -(hand_end_point(0, False) - 0.5) * math.sin(radian_angle_minutes) + (hand_end_point(1, False) - 0.5) * math.cos(radian_angle_minutes)) + 0.5 #blue minute hand, shorter length and more width stddraw.setPenRadius(0.0095) stddraw.setPenColor(stddraw.BLUE) stddraw.line(0.5, 0.5, posx, posy) #black hour hand, shortest length and most width radian_angle_hours = ( ((hour * 30) + (minute * 0.6)) * math.pi ) / 180 #convert degrees to rads, add degrees of minutes so hour hand can accurately tell time posx = ( (hand_end_point(0, True) - 0.5) * math.cos(radian_angle_hours) + (hand_end_point(1, True) - 0.5) * math.sin(radian_angle_hours)) + 0.5 posy = ( -(hand_end_point(0, True) - 0.5) * math.sin(radian_angle_hours) + (hand_end_point(1, True) - 0.5) * math.cos(radian_angle_hours)) + 0.5 stddraw.setPenRadius(0.0125) stddraw.setPenColor(stddraw.BLACK) stddraw.line(0.5, 0.5, posx, posy) #point in middle stddraw.setPenRadius(0.016) stddraw.point(0.5, 0.5) stddraw.show(100)
def draw(self): stddraw.setPenRadius(0.025) stddraw.point(self._r.cartesian(0), self._r.cartesian(1))
# Credits: idea suggested by Diego Nehab # Reference: http://www.math.dartmouth.edu/~dlittle/java/SpiroGraph # Reference: http://www.wordsmith.org/~anu/java/spirograph.html R = float(sys.argv[1]) r = float(sys.argv[2]) a = float(sys.argv[3]) stddraw.createWindow() stddraw.setXscale(-300, +300) stddraw.setYscale(-300, +300) stddraw.setPenRadius(0) t = 0.0 while True: x = (R + r) * math.cos(t) - (r + a) * math.cos(((R + r) / r) * t) y = (R + r) * math.sin(t) - (r + a) * math.sin(((R + r) / r) * t) degrees = -math.degrees((R + r) / r) * t stddraw.point(x, y) #stddraw.picture(x, y, "earth.gif", degrees) #stddraw.rotate(+Math.toDegrees((R+r)/r)*t) stddraw.sleep(10) stddraw.show() t += 0.01 # Example executions: # # python spirograph.py 180 40 15 # python spirograph.py 100 55 20
def draw(self): stddraw.setPenRadius(0.0125/1.0e10*self._mass**0.33) s=(int)(255-(self._mass/1e31)**0.3*255) stddraw.setPenColor(color.Color(s,s,s)) stddraw.point(self._r[0], self._r[1])
durationControl = int(input()) stddraw.setPenRadius(0.001) stddraw.setCanvasSize(1000, 600) stddraw.line(0.05, 0, 0.05, 1) stddraw.line(0, 0.05, 1, 0.05) stddraw.setPenRadius(0.005) stddraw.text(0.1, 0.95, "Running Time") stddraw.text(0.95, 0.07, "k") the_max = max(a) for i in range(300): duration = (a[i] / the_max) + 0.05 if (duration < (durationControl / the_max) + 0.05): stddraw.setPenColor(stddraw.GREEN) stddraw.point((i / 300) + 0.05, duration) else: stddraw.setPenColor(stddraw.RED) stddraw.point((i / 300) + 0.05, duration) stddraw.setPenColor(stddraw.BLACK) stddraw.text(0.25, 0.75, "The best running time happens when k = " + str(a.index(min(a)))) stddraw.setPenColor(stddraw.BLUE) stddraw.setPenRadius(0.001) stddraw.line(0.05, (durationControl / the_max) + 0.05, 1, (durationControl / the_max) + 0.05) result_pic = "result" + str(a.index(min(a))) + ".jpeg" stddraw.save(result_pic)
import stddraw import math print(str(2**8) + ' saalaam') t = math.sqrt(3) / 2.0 stddraw.line(0, 0, 1, 0) stddraw.line(1, 0, 0.5, t) stddraw.line(0.5, t, 0, 0) stddraw.point(0.5, t / 3.0) stddraw.show()
import stddraw import math t = math.sqrt(3.0) / 2.0 stddraw.setCanvasSize(1800, 800) stddraw.setXscale(-500, 500) stddraw.setYscale(-500, 500) i = 0.0 for i in range(0, 10000, 1): if i % 3 == 0: i = -i stddraw.clear(stddraw.YELLOW) stddraw.line(-300 - i, -330 - i, 100 - i, 200.0 - i) stddraw.line(1.0 - i, 0.0 - i, 0.5 - i, t - i) stddraw.line(107.5 - i, t * 15 - i, -68 - i, 311 - i) stddraw.point(-106.5 - i, 100 * t / 3.0 - i) stddraw.show(10) stddraw.clear(stddraw.YELLOW) print(i)
import stddraw import math t = math.sqrt(3.0) / 2 stddraw.line(0.0, 0.0, 1.0, 0.0) stddraw.line(1.0, 0.0, 0.5, t) stddraw.line(0.5, t, 0.0, 0.0) stddraw.point(0.5, t / 3) stddraw.show()
#----------------------------------------------------------------------- # plotfilter.py #----------------------------------------------------------------------- import stdio import stddraw # Plot the points read from standard input. x0 = stdio.readFloat() y0 = stdio.readFloat() x1 = stdio.readFloat() y1 = stdio.readFloat() stddraw.createWindow() stddraw.setXscale(x0, x1) stddraw.setYscale(y0, y1) stddraw.setPenRadius(0.001) # Read and plot the points. while not stdio.isEmpty(): x = stdio.readFloat() y = stdio.readFloat() stddraw.point(x, y) stddraw.show() stddraw.wait()
def draw_data(self, mass): stddraw.clear() for i in mass: #print(i) stddraw.point(i[0], i[1]) stddraw.show(2000)
def draw_clusters(self, clusters): stddraw.clear() for k in range(0, self.K): for i in clusters[k]: stddraw.point(i[0], i[1]) stddraw.show(2000)
def draw_convex_point(self, convex): for i in convex: stddraw.point(i[0], i[1]) stddraw.show(2000)
def draw(self): location = 'space_files\\' + self._name stddraw.picture(Picture(location), self._r[0], self._r[1]) stddraw.point(self._r[0], self._r[1])
def draw(self): stddraw.point(self._x, self._y)
def draw(self): """ Draws self to standard draw. """ stddraw.point(self._x, self._y)
) # если test1 - изменить количество кластеров (2), если test2 - (2), если test3 - (2) # data_arr = [] # будущий массив с данными # data_arr = generation(data_arr) # генерация этого массива data_arr = separation(test) data_learning = learning_data( data_arr[1]) # массив с данными для дообучения, разбитый на группы data_main = data_arr[0] # массив с данными для первого прохода data = Data(data_main) print(data_main) data_sample = data.sample() # выборка данных для иерархической кластеризации stddraw.setCanvasSize(CANVAS, CANVAS) stddraw.setYscale(0, CANVAS) stddraw.setXscale(0, CANVAS) for i in range(len(data_main)): stddraw.point(data_main[i][0][0], data_main[i][0][1]) stddraw.show(10000) for i in range(len(data_sample)): stddraw.setPenColor(stddraw.GREEN) stddraw.point(data_sample[i][0][0], data_sample[i][0][1]) stddraw.show(1000) ierarhic = Ierarhic(data_sample) clasters = ierarhic.Ierarhic1( ) # иерархическая кластеризация, итог - массив с кластерами centers_of_clasters = Ierarhic2(clasters) # центры полученных кластеров print(clasters) print(centers_of_clasters) parametr = check( clasters, centers_of_clasters
def main(): stddraw.createWindow(1024, 256) stddraw.setPenRadius(0) stddraw.setXscale(0, _SAMPLES_PER_REDRAW) stddraw.setYscale(-0.75, +0.75) stddraw.show() # Create keyboardDict, a dictionary relating each keyboard key # to a guitar string. keyboardDict = {} i = 0 for key in _KEYBOARD: factor = 2 ** ((i - 24) / 12.0) guitarString = guitarstring.GuitarString(_CONCERT_A * factor) keyboardDict[key] = guitarString i += 1 # pluckedGuitarStrings is the set of all guitar strings that have # been plucked. pluckedGuitarStrings = set() t = 0 # The main input loop. while True: if stddraw.hasNextKeyTyped(): # Fetch the key that the user just typed. key = stddraw.nextKeyTyped() # Figure out which guitar string to pluck, and pluck it. try: guitarString = keyboardDict[key] guitarString.pluck() pluckedGuitarStrings.add(guitarString) except KeyError: pass # Add up the samples from each plucked guitar string. Also # advance the simulation of each plucked guitar string by # one step. sample = 0.0 faintGuitarStrings = set() for guitarString in pluckedGuitarStrings: sample += guitarString.sample() guitarString.tic() if guitarString.isFaint(): faintGuitarStrings.add(guitarString) # Remove faint guitar strings from the set of plucked guitar # strings. for guitarString in faintGuitarStrings: pluckedGuitarStrings.remove(guitarString) # Play the total. stdaudio.playSample(sample) # Plot stddraw.point(t % _SAMPLES_PER_REDRAW, sample) if t == (_SAMPLES_PER_REDRAW - 1): stddraw.show() stddraw.clear() t = 0 t += 1
def main(): n = int(sys.argv[1]) dist = stdarray.readFloat1D() cx = stdarray.readFloat2D() cy = stdarray.readFloat2D() x = 0.0 y = 0.0 stddraw.setPenRadius(0.0) for i in range(n): r = stdrandom.discrete(dist) x0 = cx[r][0]*x + cx[r][1]*y + cx[r][2] y0 = cy[r][0]*x + cy[r][1]*y + cy[r][2] x = x0 y = y0 stddraw.point(x, y) stddraw.show()