def CalcUpdatePeriod(self, speed): """ # returns an update period for this wave based on speed # speed is based on magnitude at time of spawn / max magnitude # speed = 1.0 is fastest. speed = 0.0 is slowest """ speed = clamp(0,speed,1.0) self.update_period = (updateSpeed_max - (pytweening.linear(speed) * (updateSpeed_max-updateSpeed_min)))
def blinks(gray, face): status = '' rect = face if rect is not None: # determine the facial landmarks for the face region, then # convert the facial landmark (x, y)-coordinates to a NumPy # array shape = predictor(gray, rect) shape = face_utils.shape_to_np(shape) #leftEye ,rightEye = leftEye_rightEye # extract the left and right eye coordinates, then use the # coordinates to compute the eye aspect ratio for both eyes leftEye = shape[lStart:lEnd] rightEye = shape[rStart:rEnd] leftEAR = eye_aspect_ratio(leftEye) rightEAR = eye_aspect_ratio(rightEye) # average the eye aspect ratio together for both eyes ear = (leftEAR + rightEAR) / 2.0 if ear < EYE_AR_THRESH: status = 'closed_eye' pyautogui.doubleClick() pytweening.linear(0.75) ######### this code to determine x,y x, y = pyautogui.position() positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4) print(positionStr, 'end') print('\b' * len(positionStr), 'end') # otherwise, the eye aspect ratio is not below the blink # threshold else: status = 'open_eye' # show the frame return status
def make_frame(t): #colorDiv = t + 0.01 #color1= [1.0 / colorDiv, 0.0, 0.0] #color2 = [0.0, 1.0 / colorDiv, 0.0] #gradient= gizeh.ColorGradient("linear",((0,(0,.5,1)),(1,(0,1,1))), xy1=(-cosR,-sinR), xy2=(cosR,sinR)) #gradRad1 = radius1 - 20 #gradRad2 = radius1 + 20 #gradient = gizeh.ColorGradient(type="radial", # stops_colors = [(0,color1),(1,color2)], # xy1=[0.0,0.0], xy2=[gradRad1,0.0], xy3 = [0.0,gradRad2]) surface = gizeh.Surface(W,H) # orbit halo #circle1 = gizeh.circle(radius1, xy = (W/2, H/2), stroke=gradient, stroke_width=5) #circle1.draw(surface) for i in range(numParticles): # Orbiting planet particle = particles[i] if (particle.easing == 1): angle = pytweening.linear((duration - t) / duration) * 360 * particle.direction elif (particle.easing == 2): angle = pytweening.easeInQuad((duration - t) / duration) * 360 * particle.direction elif (particle.easing == 3): angle = pytweening.easeOutQuad((duration - t) / duration) * 360 * particle.direction elif (particle.easing == 4): angle = pytweening.easeInOutQuad((duration - t) / duration) * 360 * particle.direction elif (particle.easing == 5): angle = pytweening.easeInSine((duration - t) / duration) * 360 * particle.direction elif (particle.easing == 6): angle = pytweening.easeOutSine((duration - t) / duration) * 360 * particle.direction elif (particle.easing == 7): angle = pytweening.easeInOutSine((duration - t) / duration) * 360 * particle.direction radians = math.radians(angle) cosR = math.cos(radians) sinR = math.sin(radians) x = W/2 + cosR * particle.orbit_radius y = H/2 + sinR * particle.orbit_radius fill = particle.color #circle = gizeh.circle(particle.radius, xy = (x, y), fill=(1,0,1)) circle = gizeh.circle(particle.radius, xy = (x, y), fill=fill) circle.draw(surface) return surface.get_npimage()
def loop(self): while True: t = time.time() passed = t - self.tickTime self.tickTime = t conf = self.conf conf.processScan() # See if WoW is running or not if self.saveScheduled: self.saveScheduled = 0 self.conf.saveConfig() if self.sock.connected and self.conf.wowPid: color = conf.updatePixelColor() if conf.g == 51: index = 0 hpp = conf.r / 255 if hpp < self.cacheHP: self.startTween( (self.cacheHP - hpp) * self.conf.hpRatio) self.cacheHP = hpp if self.tweenStarted: tweenPerc = 1 - (t - self.tweenStarted) / self.tweenDuration if tweenPerc < 0: tweenPerc = 0 self.tweenStarted = 0 elif tweenPerc > 1: tweenPerc = 1 self.tweenVal = pytweening.linear(tweenPerc) * self.tweenStart if not self.conf.wowPid: time.sleep(1) else: after = time.time() logicTime = 1 / self.FRAMERATE - (after - t) if logicTime > 0: time.sleep(logicTime)
########Mouse Drags #pyautogui.dragTo(100, 200, button='left') # drag mouse to X of 100, Y of 200 while holding down left mouse button #pyautogui.dragTo(300, 400, 2, button='left') # drag mouse to X of 300, Y of 400 over 2 seconds while holding down left mouse button #########Tween / Easing Functions #pyautogui.moveTo(100, 100, 2, pyautogui.easeInQuad) # start slow, end fast #pyautogui.moveTo(100, 100, 2, pyautogui.easeInOutQuad) # start and end fast, slow in middle #######Mouse Clicks #pyautogui.click() # click the mouse #pyautogui.click(x=100, y=200) # move to 100, 200, then click the left mouse button. #pyautogui.click(button='right') # right-click the mouse #pyautogui.click(clicks=2) # double-click the left mouse button #pyautogui.click(clicks=2, interval=0.25) # double-click the left mouse button, but with a quarter second pause in between clicks #pyautogui.click(button='right', clicks=3, interval=0.25) ## triple-click the right mouse button with a quarter second pause in between clicks #pyautogui.doubleClick() # perform a left-button double click #pyautogui.tripleClick() ##########The mouseDown() and mouseUp() Functions #pyautogui.mouseDown(); pyautogui.mouseUp() # does the same thing as a left-button mouse click #pyautogui.mouseDown(button='right') # press the right button down #pyautogui.mouseUp(button='right', x=100, y=200) # move the mouse to 100, 200, then release the right button up. ##########Mouse Scrolling # pyautogui.scroll(10) # scroll up 10 "clicks" #pyautogui.hscroll(-10) # scroll left 10 "clicks" pytweening.linear(0.75) ######### this code to determine x,y x, y = pyautogui.position() positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4) print(positionStr, end='') print('\b' * len(positionStr), end='', flush=True) except KeyboardInterrupt: print('\n')
('Quart', pytweening.easeInQuart, pytweening.easeOutQuart, pytweening.easeInOutQuart), ('Quint', pytweening.easeInQuint, pytweening.easeOutQuint, pytweening.easeInOutQuint), ('Sine', pytweening.easeInSine, pytweening.easeOutSine, pytweening.easeInOutSine), ('Expo', pytweening.easeInExpo, pytweening.easeOutExpo, pytweening.easeInOutExpo), ('Circ', pytweening.easeInCirc, pytweening.easeOutCirc, pytweening.easeInOutCirc), ('Elastic', pytweening.easeInElastic, pytweening.easeOutElastic, pytweening.easeInOutElastic), ('Back', pytweening.easeInBack, pytweening.easeOutBack, pytweening.easeInOutBack), ('Bounce', pytweening.easeInBounce, pytweening.easeOutBounce, pytweening.easeInOutBounce), ) # Linear function has only a single function, not three. wb.create_sheet(title='Linear') sheet = wb.get_sheet_by_name('Linear') for i in range(1, 101): n = i / 100.0 sheet['A' + str(i)] = pytweening.linear(n) if MAKE_CHARTS: refObj = openpyxl.charts.Reference(sheet, (1, 1), (100, 1)) seriesObj = openpyxl.charts.Series(refObj, title='Linear') chartObj = openpyxl.charts.LineChart() chartObj.append(seriesObj) chartObj.drawing.top = 50 chartObj.drawing.left = 300 chartObj.drawing.width = 300 chartObj.drawing.height = 200 sheet.add_chart(chartObj) for graph in graphs: name, easeInFunc, easeOutFunc, easeInOutFunc = graph
def liner(n): """ 速度均匀 """ return pytweening.linear(n)
def run_pattern(df, target, iters=100000, num_frames=100, decimals=2, shake=0.2, max_temp=0.4, min_temp=0, ramp_in=False, ramp_out=False, freeze_for=0, labels=["X Mean", "Y Mean", "X SD", "Y SD", "Corr."], reset_counts=False, custom_points=False): global frame_count global it_count if reset_counts: it_count = 0 frame_count = 0 r_good = df.copy() # this is a list of frames that we will end up writing to file write_frames = [ int(round(pytweening.linear(x) * iters)) for x in np.arange(0, 1, 1 / (num_frames - freeze_for)) ] if ramp_in and not ramp_out: write_frames = [ int(round(pytweening.easeInSine(x) * iters)) for x in np.arange(0, 1, 1 / (num_frames - freeze_for)) ] elif ramp_out and not ramp_in: write_frames = [ int(round(pytweening.easeOutSine(x) * iters)) for x in np.arange(0, 1, 1 / (num_frames - freeze_for)) ] elif ramp_out and ramp_in: write_frames = [ int(round(pytweening.easeInOutSine(x) * iters)) for x in np.arange(0, 1, 1 / (num_frames - freeze_for)) ] extras = [iters] * freeze_for write_frames.extend(extras) # this gets us the nice progress bars in the notbook, but keeps it from crashing looper = trange if is_kernel(): looper = tnrange # this is the main loop, were we run for many iterations to come up with the pattern for i in looper(iters + 1, leave=True, ascii=True, desc=target + " pattern"): t = (max_temp - min_temp) * s_curve(((iters - i) / iters)) + min_temp if target in all_targets: test_good = perturb(r_good.copy(), initial=df, target=target, temp=t) else: raise Exception("bah, that's not a proper type of pattern") # here we are checking that after the purturbation, that the statistics are still within the allowable bounds if is_error_still_ok(df, test_good, decimals): r_good = test_good # save this chart to the file for x in xrange(write_frames.count(i)): save_scatter_and_results(r_good, target + "-image-" + format(int(frame_count), '05'), 150, labels=labels) #save_scatter(r_good, target + "-image-"+format(int(frame_count), '05'), 150) r_good.to_csv(target + "-data-" + format(int(frame_count), '05') + ".csv") frame_count = frame_count + 1 return r_good
def update(self, dt): self.rect.x = 750 * tween.linear(self.iter / ITERATIONS) self.rect.y = 10 + 550 * func(self.iter / ITERATIONS) self.iter += 1 if self.iter > ITERATIONS: self.iter = 0
('Circ', pytweening.easeInCirc, pytweening.easeOutCirc, pytweening.easeInOutCirc), ('Elastic', pytweening.easeInElastic, pytweening.easeOutElastic, pytweening.easeInOutElastic), ('Back', pytweening.easeInBack, pytweening.easeOutBack, pytweening.easeInOutBack), ('Bounce', pytweening.easeInBounce, pytweening.easeOutBounce, pytweening.easeInOutBounce), ) # Linear function has only a single function, not three. wb.create_sheet(title='Linear') sheet = wb.get_sheet_by_name('Linear') for i in range(1, 101): n = i / 100.0 sheet['A' + str(i)] = pytweening.linear(n) if MAKE_CHARTS: refObj = openpyxl.charts.Reference(sheet, (1, 1), (100, 1)) seriesObj = openpyxl.charts.Series(refObj, title='Linear') chartObj = openpyxl.charts.LineChart() chartObj.append(seriesObj) chartObj.drawing.top = 50 chartObj.drawing.left = 300 chartObj.drawing.width = 300 chartObj.drawing.height = 200 sheet.add_chart(chartObj) for graph in graphs: name, easeInFunc, easeOutFunc, easeInOutFunc = graph wb.create_sheet(title=name)