All Samples(438) | Call(416) | Derive(0) | Import(22)
hypot(x, y) Return the Euclidean distance, sqrt(x*x + y*y).
src/s/f/SFML2-HEAD/python/samples/worm.py SFML2(Download)
head_x += self.parts_spacing*math.cos(self.angle) head_y += self.parts_spacing*math.sin(self.angle) if self.is_running() and self.targeted_length <= self.required_length: # let's check if the worm ate the apple if math.hypot(apple.GetPosition()[0] - head_x, apple.GetPosition()[1] - head_y) < apple.size/2 + self.part_size/2: # Yes it did arena.update_score() self.targeted_length += self.grow_length # The worm gets longer apple.random_move(arena)
for i in range(len(self)): if i < len(self) - self.part_size/self.parts_spacing - 1: test_x, test_y = self[i].GetPosition() if math.hypot(head_x-test_x, head_y-test_y) < self.part_size and self.is_running(): # Check for collision self.crash() if len(self) == 0:
src/s/h/shedskin-HEAD/examples/fysphun.py shedskin(Download)
# (c) Alex P-B (chozabu@gmail.com) # license: http://creativecommons.org/licenses/by-nc-sa/2.5/ from math import sin, cos, pi, hypot from random import random def setup(w, h):
def twopoint(p1,p2,destdist = 15,mult = 0.5): xd = p1.x-p2.x yd = p1.y-p2.y td = hypot(xd, yd)#+0.0000000001 rads = p1.rad+p2.rad diffd = (destdist-td)*mult xd/=td
l.p2 = p2 xd = p1.x-p2.x yd = p1.y-p2.y dist = hypot(xd,yd) l.dist = dist l.strength = strength l.drawme = drawlinks
src/s/f/sfml-HEAD/trunk/python/samples/worm.py sfml(Download)
head_x += self.parts_spacing*math.cos(self.angle) head_y += self.parts_spacing*math.sin(self.angle) if self.is_running() and self.targeted_length <= self.required_length: # let's check if the worm ate the apple if math.hypot(apple.GetPosition()[0] - head_x, apple.GetPosition()[1] - head_y) < apple.size/2 + self.part_size/2: # Yes it did arena.update_score() self.targeted_length += self.grow_length # The worm gets longer apple.random_move(arena)
for i in range(len(self)): if i < len(self) - self.part_size/self.parts_spacing - 1: test_x, test_y = self[i].GetPosition() if math.hypot(head_x-test_x, head_y-test_y) < self.part_size and self.is_running(): # Check for collision self.crash() if len(self) == 0:
src/s/f/sfml-HEAD/python/samples/worm.py sfml(Download)
head_x += self.parts_spacing*math.cos(self.angle) head_y += self.parts_spacing*math.sin(self.angle) if self.is_running() and self.targeted_length <= self.required_length: # let's check if the worm ate the apple if math.hypot(apple.GetPosition()[0] - head_x, apple.GetPosition()[1] - head_y) < apple.size/2 + self.part_size/2: # Yes it did arena.update_score() self.targeted_length += self.grow_length # The worm gets longer apple.random_move(arena)
for i in range(len(self)): if i < len(self) - self.part_size/self.parts_spacing - 1: test_x, test_y = self[i].GetPosition() if math.hypot(head_x-test_x, head_y-test_y) < self.part_size and self.is_running(): # Check for collision self.crash() if len(self) == 0:
src/p/y/python-cookbook-HEAD/cb2_examples/cb2_18_14_sol_1.py python-cookbook(Download)
def _addition_result(self, result, other_abs):
new_perc = 100.0 * (math.hypot(self.abs, other_abs) / result)
return Measurement(result, new_perc)
def __add__(self, other):
result = self.val + other.val
return self._addition_result(result, other.abs)
def __sub__(self, other):
result = self.val - other.val
return self._addition_result(result, other.abs)
def _multiplication_result(self, result, other_perc):
new_perc = math.hypot(self.perc, other_perc)
src/r/a/Rabbyt-0.8.3/examples/bezier.py Rabbyt(Download)
from math import hypot import pygame import rabbyt rabbyt.init_display((640,480)) rabbyt.set_viewport((640,480), projection=(0,0,640,480))
running=False
elif event.type == pygame.MOUSEBUTTONDOWN:
for c in control_points:
if hypot(c.x-event.pos[0], c.y-event.pos[1]) < 20:
grabbed_point = c
break
elif event.type == pygame.MOUSEMOTION:
src/z/c/zc.async-1.5.3/src/zc/async/examples/pi3.py zc.async(Download)
def generate_sample(size=100000):
count = 0
for i in range(size):
if math.hypot(random.random(), random.random()) < 1:
count += 1
return count, size
src/z/c/zc.async-1.5.3/src/zc/async/examples/pi2.py zc.async(Download)
def generate_sample(size=100000):
count = 0
for i in range(size):
if math.hypot(random.random(), random.random()) < 1:
count += 1
return count, size
src/z/c/zc.async-1.5.3/src/zc/async/examples/pi1.py zc.async(Download)
def generate_sample(size=100000):
count = 0
for i in range(size):
if math.hypot(random.random(), random.random()) < 1:
count += 1
return count, size
src/p/y/pypy3-HEAD/pypy/lib/cmath.py pypy3(Download)
if base is not None:
return log(x) / log(base)
x = complex(x, 0)
l = math.hypot(x.real,x.imag)
imag = math.atan2(x.imag, x.real)
real = math.log(l)
return complex(real, imag)
def log10(x):
"""log10(x)
Return the base-10 logarithm of x."""
x = complex(x, 0)
l = math.hypot(x.real, x.imag)
if x.real == 0. and x.imag == 0.:
real, imag = 0, 0
else:
s = math.sqrt(0.5*(math.fabs(x.real) + math.hypot(x.real,x.imag)))
d = 0.5*x.imag/s
if x.real > 0.:
real = s
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next