Exemplo n.º 1
0
    def polygon(self, f=1):
        key = self.pos, self.width, f
        if key == self.cpolygonkey:
            return self.cpolygon
        s = math.length(self.pos)
        x, y = self.pos
        x0 = self.width
        y0 = 2 / math.tan(math.radians(30)) * self.width
        beta = math.atan2(x - x0, y - y0)
        gamma = 4 * beta - math.tau / 8
        ds = beta / (math.tau / 12)  # 0 on left 1 on right

        s0 = (1 - 0.4 * ds) * s
        d = (0.2 * ds**2) * s
        p0 = -0.02, s0
        p1 = d, s0
        C, S = math.CS(gamma + 3 / 8 * math.tau, d)
        p2 = x + C, y - S
        p3 = self.pos
        ps = bezier([p0, p1, p2, p3])

        s1 = (1 - 0.4 * (1 - ds)) * s
        d = (0.2 * (1 - ds)**2) * s
        p0 = s1 * S30 + 0.02 * C30, s1 * C30 - 0.02 * S30
        p1 = s1 * S30 - d * C30, s1 * C30 + d * S30
        C, S = math.CS(gamma + 3 / 8 * math.tau, d)
        p2 = x + S, y + C
        p3 = self.pos
        ps += bezier([p0, p1, p2, p3])[::-1][1:]
        self.cpolygonkey = key
        self.cpolygon = thicken(ps, f * self.width)
        return self.cpolygon
Exemplo n.º 2
0
def addpoint(pos):
	x, y = view.FconvertB(Fspot1, pos)
	r = math.length((x, y))
	na = 12 / math.tau * math.atan2(x, y)
	n, a = divmod(na, 1)
	n = int(n)
	if n % 2 == 1:
		a = 1 - a
	a = round(a, 3)
	r = round(r, 3)
	data = a, r, n

	if n % 2 == 1:
		a = 1 - a
	C, S = math.CS((n + a) / 12 * math.tau, r)
	pF = S, C
	covered = iscovered(pF)
	if covered:
		self.ydata += [data]
		self.yespoints += [pF]
	else:
		self.ndata += [data]
		self.nopoints += [pF]
	print()
	print([self.ydata, self.ndata])
	checkcover()
Exemplo n.º 3
0
 def draw(self):
     glPushMatrix()
     glColor4f(0, 0, 1, 0.3)
     glTranslate(*self.pos)
     glBegin(GL_POLYGON)  # replaced by drawmodel_sect_pool
     for x, y in math.CSround(int(round(10 * self.r)), r=self.r):
         glVertex(x, y, 0)
     glEnd()
     # Fixed barriers
     glColor4f(0.8, 0.8, 0.8, 1)
     for x, y in math.CSround(int(round(2 * self.r)), r=self.r):
         glPushMatrix()
         glTranslate(x, y, 0)
         graphics.drawsphere(0.2)
         glPopMatrix()
     # Food fountain
     if self.hasfood:
         glColor4f(1, 0, 1, 1)
         glPointSize(2)
         glBegin(GL_POINTS)
         for jfood in range(50):
             x, y = math.CS(jfood * math.phi,
                            self.r / 2 * (jfood**2 * math.phi % 1))
             z = 3 * (
                 (jfood**3 * math.phi + pygame.time.get_ticks() * 0.001) %
                 1)**2
             glVertex(x, y, z)
         glEnd()
     glPopMatrix()
Exemplo n.º 4
0
 def polygon(self, f=1):
     s = math.length(self.anchors[0])
     CSs = [math.CS(math.radians(theta)) for theta in range(-1, 35, 3)]
     w = self.width * f
     return [((s + w) * S, (s + w) * C)
             for C, S in CSs] + [((s - w) * S, (s - w) * C)
                                 for C, S in reversed(CSs)]
Exemplo n.º 5
0
def getspec(h):
    C, S = math.CS(h.get("a", 0))
    fx = math.exp(h["sx"] * 0.125) * (-1 if h["xflip"] else 1)
    fy = math.exp(h["sy"] * 0.125)
    return tuple(
        tuple((x * fx * C + y * fy * S, -x * fx * S + y * fy * C)
              for x, y in (reversed(layer) if h["xflip"] else layer))
        for layer in specs[h["specname"]])
Exemplo n.º 6
0
def setpoints():
	self.yespoints = []
	self.nopoints = []
	if self.stage in stagedata.points:
		yes, no = stagedata.points[self.stage]
		for a, r, n in yes:
			if settings.collapsepoints:
				n = 0
			if n % 2 == 1:
				a = 1 - a
			C, S = math.CS((n + a) / 12 * math.tau, r)
			self.yespoints.append((S, C))
		for a, r, n in no:
			if settings.collapsepoints:
				n = 0
			if n % 2 == 1:
				a = 1 - a
			C, S = math.CS((n + a) / 12 * math.tau, r)
			self.nopoints.append((S, C))
	checkcover()
Exemplo n.º 7
0
def sectors(Fspot):
    posB, BrF = Fspot
    color = pygame.Color("#9999aa")
    for j in range(1, 7):
        pygame.draw.circle(pview.screen, color, T(posB), T(BrF * j / 6), T(1))
    for a in (0, 60, 120):
        C, S = math.CS(math.radians(a))
        drawlinesF(Fspot, [(S, C), (-S, -C)], color)
    for C, S in math.CSround(6, 1, 1 / 2):
        drawlinesF(Fspot, [(S, C), (S / 3, C / 3)], color)
    for C, S in math.CSround(12, 1, 1 / 2):
        drawlinesF(Fspot, [(S, C), (2 * S / 3, 2 * C / 3)], color)
Exemplo n.º 8
0
def running(screenpos, scale, fcycle):
    x, y = screenpos
    C, S = math.CS(fcycle * math.tau)
    C2, S2 = math.CS(2 * fcycle * math.tau)
    # Arms and legs don't quite follow a sinusoidal pattern. They spend extra time at the extrema.
    # This gives them a more natural swing.
    fC = abs(C)**0.7 * math.sign(C)
    # foots
    x0, y0 = x - 1 * scale, y - 1 * scale
    dx = 1.3 * fC
    dy = 0.4 * S + 0.2 * C
    drawfoot((x0 + dx * scale, y0 + dy * scale), scale)
    drawfoot((x0 - dx * scale, y0 - dy * scale), scale)
    # back fist
    x0 = x + 0.2 * scale
    y0 = y + (-2.9 - 0.2 * S2) * scale
    dx, dy = 1.6 * fC, 0.4 * abs(S)
    drawfoot((x0 - dx * scale, y0 + dy * scale), scale)
    # dress
    x0, y0 = x - 0.3 * scale, y - (1.7 + 0.2 * S2) * scale
    path = [(-2.5, 0), (-0.5, -0.5), (1.5, -0.8), (1.5, 1), (2, 3), (1, 3.2),
            (-0.7, 1.5)]
    ps = [(i(x0 + scale * dx), i(y0 - scale * dy)) for dx, dy in path]
    pygame.draw.polygon(pview.screen, (0, 0, 0), ps, i(0.6 * scale))
    pygame.draw.polygon(pview.screen, (100, 100, 250), ps, 0)
    # front fist
    x0 = x + 0.2 * scale
    y0 = y + (-2.9 - 0.2 * S2) * scale
    dx, dy = 1.6 * fC, 0.4 * abs(S)
    drawfoot((x0 + dx * scale, y0 + dy * scale), scale)
    # noggin
    Snoggin = math.sin(2 * fcycle * math.tau - 0.6)
    x0, y0 = x + 1.1 * scale, y - (5 + 0.2 * Snoggin) * scale
    drawnoggin((x0, y0), scale, angle=0.2 + 0.1 * Snoggin)

    if settings.DEBUG:
        pygame.draw.circle(pview.screen, (255, 0, 255), screenpos,
                           i(0.3 * scale))
Exemplo n.º 9
0
 def draw(self):
     x0, y0 = self.screenpos()
     C, S = math.CS(math.radians(self.angle))
     # TODO: maff.R
     color = 140, 140, 180
     if self.right:
         dxys = [(1, 5), (6, 0), (1, -5)]
         dxys = [(C * dx + S * dy, -S * dx + C * dy) for dx, dy in dxys]
         ps = [
             view.toscreen(self.x + dx, self.y + dy, self.z)
             for dx, dy in dxys
         ]
         pygame.draw.polygon(pview.screen, color, ps)
     if self.left:
         dxys = [(-1, 5), (-6, 0), (-1, -5)]
         dxys = [(C * dx + S * dy, -S * dx + C * dy) for dx, dy in dxys]
         ps = [
             view.toscreen(self.x + dx, self.y + dy, self.z)
             for dx, dy in dxys
         ]
         pygame.draw.polygon(pview.screen, color, ps)
Exemplo n.º 10
0
def randompoints():
	yout, nout = [], []
	self.yespoints = []
	self.nopoints = []
	for _ in range(16):
		a = random.uniform(0, 1)
		r = random.uniform(0, 1)
		n = 0
		if n % 2 == 1:
			a = 1 - a
		C, S = math.CS((n + a) / 12 * math.tau, r)
		pos = S, C
		covered = self.design.colorat(pos)
		if covered:
			self.yespoints.append((S, C))
			yout.append((a, r, n))
		else:
			self.nopoints.append((S, C))
			nout.append((a, r, n))
	print(yout)
	print(nout)
	checkcover()
Exemplo n.º 11
0
def drawnoggin(pos, scale, angle=0):
    x, y = pos
    C, S = math.CS(angle)

    def p(dx, dy):
        dx, dy = C * dx + S * dy, -S * dx + C * dy
        return (i(x + dx * scale), i(y + dy * scale))

    # The head itself
    pygame.draw.circle(pview.screen, (0, 0, 0), p(0, 0), i(1.4 * scale))
    pygame.draw.circle(pview.screen, scolor, p(0, 0), i(1.1 * scale))
    # Hair or hat or whatever that is on top.
    ps = [
        p(dx, dy) for dx, dy in [(-1.5, 0), (2, -1.5), (-4, -1), (-1.8, -2.5)]
    ]
    pygame.draw.polygon(pview.screen, (240, 40, 180), ps)
    pygame.draw.lines(pview.screen, (0, 0, 0), True, ps, i(0.3 * scale))
    # Eye
    pygame.draw.line(pview.screen, (0, 0, 0), p(0.2, 0.3), p(0.3, -0.7),
                     i(0.3 * scale))
    pygame.draw.line(pview.screen, (255, 255, 255), p(0.45, 0.1), p(0.5, -0.5),
                     i(0.3 * scale))
Exemplo n.º 12
0
 def polygon(self, f=1):
     s = math.length(self.pos)
     x, y = self.pos
     x0 = self.width
     y0 = 2 / math.tan(math.radians(30)) * self.width
     beta = math.atan2(x - x0, y - y0)
     gamma = 4 * beta - math.tau / 8
     ds = beta / (math.tau / 12)
     s0 = (0.6 + 0.2 * ds) * s
     s1 = (0.8 - 0.2 * ds) * s
     d = 0.3 * s
     p0 = -0.01, s0
     p1 = d, s0
     C, S = math.CS(gamma + 3 / 8 * math.tau, d)
     p2 = x + S, y + C
     p3 = self.pos
     ps = bezier([p0, p1, p2, p3])
     p0 = self.pos
     p1 = x + C, y - S
     p2 = s1 * S30 - d * C30, s1 * C30 + d * S30
     p3 = s1 * S30, s1 * C30
     ps += bezier([p0, p1, p2, p3])[1:]
     return thicken(ps, f * self.width)
Exemplo n.º 13
0
	def movedrain(self, dt):
		dr = 5 * self.tdrain * dt
		dl = 10 * dt
		ax, ay, az = self.pos - self.section.pos
		r = math.sqrt(ax ** 2 + ay ** 2)
		dtheta = -dl / max(r, 0.5)
		r = max(r - dr, 0)
		if r > 0.01:
			theta = math.atan2(ay, ax)
			theta += dtheta
		else:
			theta = 0
		ax, ay = math.CS(theta, r)
		self.pos.x = self.section.pos.x + ax
		self.pos.y = self.section.pos.y + ay
		self.draintheta -= dtheta
		if r < 0.1:
			self.drainsink += dt
			if self.drainsink > 0.1:
				self.pos.z -= 20 * dt * (self.drainsink - 0.5) ** 2
				if self.section.dzwater(self.pos) < -2:
					self.section.drop(self)
					self.draining = False
Exemplo n.º 14
0
def draw(color0, color1):
    if settings.lowfi:
        pview.screen.fill(math.imix(color0, color1, 0.5))
        return
    killtime(0)
    w, h = pview.size
    #	w //= 4
    #	h //= 4
    directions = [
        math.CS(math.tau * (0.3 + jtheta / nlayer), 0.05 * 0.9**jtheta)
        for jtheta in range(nlayer)
    ]
    t = 0.001 * pygame.time.get_ticks()
    offsets = [(int(dx * w * t) % w, int(dy * h * t) % h)
               for dx, dy in directions]
    pview.screen.fill(color0)
    dsurf.fill(color1)
    if alayers:
        applyalpha(dsurf, alayers, offsets[:len(alayers)])


#	pview.screen.blit(pygame.transform.scale(dsurf, pview.size), (0, 0))
    pview.screen.blit(dsurf, (0, 0))
Exemplo n.º 15
0
def arc0(r):
    return [(S, C)
            for C, S in [math.CS(math.radians(x), r) for x in range(0, 35, 5)]]
Exemplo n.º 16
0
from __future__ import division
import pygame, math
from . import maff, pview, ptext, view
from .pview import T, I

C15, S15 = math.CS(math.radians(15))
C30, S30 = math.CS(math.radians(30))


def arc0(r):
    return [(S, C)
            for C, S in [math.CS(math.radians(x), r) for x in range(0, 35, 5)]]


def drawlinesF(Fspot, pFs, color):
    pygame.draw.lines(pview.screen, color, False,
                      T([view.BconvertF(Fspot, pF) for pF in pFs]))


def insector0(p):
    x, y = p
    return 0 <= x <= y / math.sqrt(3)


# Return a segment along the given segment within sector 0, or None if completely outside.
def cull(p0, p1):
    x0, y0 = p0
    x1, y1 = p1
    dx, dy = x1 - x0, y1 - y0
    ts = [0, 1]
    if (x0 > 0) != (x1 > 0) and abs(dx) > 0.001: