コード例 #1
0
ファイル: test.py プロジェクト: dejbug/pyg
	def onDraw(self, surface):
		self.h1.draw(surface)
		self.h2.draw(surface)
		self.h3.draw(surface)
		self.h4.draw(surface)
		
		self.h2.centerPointSize = 3
		self.h2.centerPointColor = pygame.Color("red")
		
		pygame.draw.aaline(surface, pygame.Color("grey"), self.h2.c, self.cur)
		
		a, b = self.h1.getshield(self.cur)
		pygame.draw.aaline(surface, pygame.Color("red"), a, b)
		
		
		lc = hex.LineCalc(self.h2.c, self.cur)
		t = "(%+4d, %+4d) [%3d] %+4d" % (lc.dx, lc.dy, lc.len, int(lc.deg))
		self.tout(surface, (10, 30), t, pygame.Color("red"))
		
		sixth = (lc.deg / 60) % 6
		pygame.draw.aaline(surface, pygame.Color("red"), *hex.hexlines(self.h2.c, self.radius)[sixth])
		
		sixthdeg = lc.deg % 60
		len = self.radius*trig.sin(60)/trig.sin(120-sixthdeg)
		cut = typ.Point(int(round(len*trig.cos(lc.deg))), int(round(len*trig.sin(lc.deg))))
		t = "%+4d {%2d} (%+4d, %+4d)" % ((sixthdeg, len, ) + cut)
		self.tout(surface, (10, 50), t, pygame.Color("blue"))
		
		hexhit = lc.len < len
		
		pygame.draw.circle(surface, pygame.Color("red"), (self.h2.c.x+cut.x, self.h2.c.y+cut.y), 3)
		
		t = "(%d:%d)" % self.cur + (" | x" if hexhit else " | =")
		self.tout(surface, (10, 10), t)
コード例 #2
0
def _get_suns_declination_sin_and_cos_step_6(L):
    """
    6. calculate the Sun's declination

        sinDec = 0.39782 * sin(L)
        cosDec = cos(asin(sinDec))
    """
    sinDec = 0.39782 * sin(L)
    cosDec = cos(asin(sinDec))
    return sinDec, cosDec  # scalars
コード例 #3
0
ファイル: afc1990.py プロジェクト: rconradharris/pysunset
def _get_suns_local_hour_angle_step_7a(zenith, latitude, sinDec, cosDec):
    """
    7a. calculate the Sun's local hour angle

        cosH = (cos(zenith) - (sinDec * sin(latitude))) / (cosDec * cos(latitude))

        if (cosH >  1) 
          the sun never rises on this location (on the specified date)
        if (cosH < -1)
          the sun never sets on this location (on the specified date)
    """
    cosH = (cos(zenith) - (sinDec * sin(latitude))) / (cosDec * cos(latitude))

    if cosH > 1:
        raise NoSunrise("cosH={0}".format(cosH))
    elif cosH < -1:
        raise NoSunset("cosH={0}".format(cosH))

    return cosH  # scalar
コード例 #4
0
ファイル: trig_test.py プロジェクト: qcambrel/trig-functions
	def test_cos(self):
		self.assertEqual(trig.cos(trig.radians(45)), 1/math.sqrt(2))
コード例 #5
0
print('HELLO')
n = int(input('Enter something:'))
print "Your number is ", n
if n == 10:
    print('You win')
else:
    print('You lose')
print "%i! = %i" % (n, series.factor(n))
f1, f2 = series.fibo(n)
print "F(%i) = %i" % (n - 1, f1)
print "F(%i) = %i" % (n, f2)
f = open('test')
while f:
    try:
        nf = int(f.readline())
        print "%i! = %i" % (nf, series.factor(nf))
    except:
        print('Empty string mean end of file')
        break
x = float(input('Enter something for sin&cos:'))
if x <= 10 * math.pi:
    print "sin is ", trig.sin(x)
    print "cos is ", trig.cos(x)
    print "sin^2 + cos^2 = ", (trig.sin(x)**2 + trig.cos(x)**2)
else:
    print "Oh, too much"
    print math.pi
    print math.cos(x)
    print math.sin(x)
コード例 #6
0
ファイル: hex.py プロジェクト: dejbug/pyg
	def getcut(self, p):
		lc = LineCalc(self.c, p)
		sixth = (lc.deg / 60) % 6
		sixthdeg = lc.deg % 60
		len = self.r*trig.sin(60)/trig.sin(120-sixthdeg)
		return typ.Point(len*trig.cos(lc.deg), len*trig.sin(lc.deg))
コード例 #7
0
ファイル: hex.py プロジェクト: dejbug/pyg
import pygame, math
import typ, trig

from sys import maxint as MAXINT


class Error(Exception): pass
class LineCalcError(Error): pass
class InfSlopeError(LineCalcError): pass
class ParallelError(LineCalcError): pass


hexdegs = range(0,360,60)
hexrads = [(trig.cos(d), trig.sin(d)) for d in hexdegs]


def hexagon(c, r):
	return [typ.Point(round(c[0]+r*h[0]), round(c[1]+r*h[1])) for h in hexrads]


def hexlines(c, r):
	vv = hexagon(c, r)
	return [(vv[i], vv[(i+1)%len(vv)]) for i in xrange(len(vv))]
	
	
class GridPointsGenerator(object):
	def __init__(self, radius, cols, rows, offset=None, extra=None):
		self.radius, self.cols, self.rows = radius, cols, rows
	
		self.offset = typ.Point(*(offset if offset else (radius+1,radius+1)))
		self.extra = extra or (0,0)