Пример #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_true_longitude_step_4(M):
    """
    4. calculate the Sun's true longitude

        L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634
        NOTE: L potentially needs to be adjusted into the range [0,360) by adding/subtracting 360
    """
    L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634
    return L % 360  # degrees
Пример #3
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
Пример #4
0
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
Пример #5
0
	def test_sin(self):
		self.assertEqual(trig.sin(trig.radians(45)), 1/math.sqrt(2))
Пример #6
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)
Пример #7
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))
Пример #8
0
Файл: hex.py Проект: dejbug/pyg
	def hit(self, p, borderGap=2):
		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 lc.len < max(0, len-borderGap)
Пример #9
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)
Пример #10
0
#!/usr/bin/env python3

import turtle
import trig

hypotenuse = trig.find_missing_side(sin=trig.sin(degrees=35), opposite=2.8)
total = trig.pythagorean(opposite=2.8, hypotenuse=hypotenuse['hypotenuse'])

print(total)
board = turtle.Turtle()

board.forward(total['adjacent'] * 50)  # draw base

board.left(90)
board.forward(total['opposite'] * 50)

board.left(125)
board.forward(total['hypotenuse'] * 50)

turtle.done()