コード例 #1
0
ファイル: reference.py プロジェクト: Syclight/ProjectFS
    def __init__(self, *args):
        super(MandelbrotSet, self).__init__(*args)
        self.caption = '测试场景: MandelbrotSet'

        self.width, self.height = 600, 600
        self.canvas = pygame.Surface((self.width, self.height))
        # self.canvas.lock()
        self.max_iteration = 100
        for x in range(self.width):
            for y in range(self.height):
                a = mapping(x, 0, self.width, -1.5, 1.5)
                b = mapping(y, 0, self.height, -1.5, 1.5)
                ca, cb = a, b

                n = 0
                while n < self.max_iteration:  # 迭代
                    aa, bb = a * a - b * b, 2 * a * b
                    a, b = aa + ca, bb + cb
                    if abs(a + b) > 16:
                        break
                    n += 1

                bright = mapping(n, 0, self.max_iteration, 0, 1)
                bright = mapping(math.sqrt(bright), 0, 1, 0, 255)
                if n is self.max_iteration:
                    bright = 0

                self.canvas.set_at([x, y], (bright, bright, bright))
コード例 #2
0
ファイル: reference.py プロジェクト: Syclight/ProjectFS
    def __init__(self, *args):
        super(JuliaSet, self).__init__(*args)
        self.caption = '测试场景: JuliaSet'

        self.real = -0.70176  # 0.285  # -0.70176  # -0.8 # 实部
        self.imaginary = -0.3842  # 0.01  # -0.3842  # 0.156 # 虚部

        self.width, self.height = 600, 600
        self.canvas = pygame.Surface((self.width, self.height))

        self.w = 5
        self.h = (self.w * self.height) / self.width

        self.x_min = - self.w / 2
        self.y_min = - self.h / 2
        self.x_max = self.x_min + self.w
        self.y_max = self.y_min + self.h

        self.dx = (self.x_max - self.x_min) / self.width
        self.dy = (self.y_max - self.y_min) / self.height

        self.max_iteration = 100

        self.y = self.y_min
        for i in range(self.width):
            self.x = self.x_min
            for j in range(self.height):
                a = self.y
                b = self.x

                n = 0
                while n < self.max_iteration:  # 迭代
                    aa, bb = a * a, b * b
                    ab_double = 2 * a * b
                    a, b = aa - bb + self.real, ab_double + self.imaginary
                    if aa * aa + bb * bb > 16:
                        break
                    n += 1

                if n == self.max_iteration:
                    self.canvas.set_at([i, j], (0, 0, 0))
                else:
                    norm = mapping(n, 0, self.max_iteration, 0, 1)
                    norm = mapping(math.sqrt(norm), 0, 1, 0, 255)
                    self.canvas.set_at([i, j], (norm, norm, norm))

                self.x += self.dx
            self.y += self.dy
コード例 #3
0
ファイル: reference.py プロジェクト: Syclight/ProjectFS
    def draw(self):
        if not pygame.mixer.music.get_busy():
            self.player.active('0')
            pygame.mixer.music.play()
        ma, fps = 0, 60
        if self.FPS != 0:
            fps = self.FPS
        lis = self.player.getMsg('0', round(1 / fps * 8000))
        for n in lis:
            if n > ma:
                ma = n

        if ma != 0:
            p = mapping(ma, 0, 6000, 0, 5)
            p = round(p)
        else:
            p = 0

        t = self.frameCount / 180

        for i in range(random.randint(0, p)):
            self.snowflakes.append(snowFlake(self.width, self.height))

        for flake in self.snowflakes:
            flake.update(t, self.snowflakes)
            flake.display(self.screen)
コード例 #4
0
ファイル: reference.py プロジェクト: Syclight/ProjectFS
    def draw(self):
        self.sceneCanvas.fill((0, 0, 0))
        self.sceneCanvas.set_alpha(20)
        # 创建圆
        for i in range(0, 800, 30):
            for j in range(0, 600, 30):
                # 每个圆的初始位置取决于鼠标位置
                ax = mapping(self.mouseX, 0, 800, -4 * PI, 4 * PI)
                ay = mapping(self.mouseY, 0, 600, -4 * PI, 4 * PI)

                # 根据圆的位置获取角度
                angle = ax * (i / 800) + ay * (j / 600)

                # 每个圆做圆周运动
                x = i + 20 * cos(2 * PI * self.t + angle)
                y = j + 20 * sin(2 * PI * self.t + angle)

                Painter(self.sceneCanvas).Circle(Circle(x, y, 10), (0, 255, 0), 0)
        self.t += 0.01  # 更新时间
        self.screen.blit(self.sceneCanvas, (0, 0))
コード例 #5
0
ファイル: reference.py プロジェクト: Syclight/ProjectFS
    def __init__(self, *args):
        super(IFS, self).__init__(*args)
        self.caption = '测试场景: Iterated function system 迭代分形系统'

        self.width, self.height = 600, 600
        self.canvas = pygame.Surface((self.width, self.height))

        self.max_iteration = 100
        for x in range(self.width):
            for y in range(self.height):
                a = mapping(x, 0, self.width, -1.5, 1.5)
                b = mapping(y, 0, self.height, -1.5, 1.5)
                ca, cb = a, b

                n = 0
                while n < self.max_iteration:  # 迭代
                    ran = random.randint(0, 3)
                    if ran == 0:
                        a, b = self.__rul_0(a, b, ca, cb)
                    elif ran == 1:
                        a, b = self.__rul_1(a, b, ca, cb)
                    elif ran == 2:
                        a, b = self.__rul_2(a, b, ca, cb)
                    elif ran == 3:
                        a, b = self.__rul_3(a, b, ca, cb)
                    # aa, bb = a * a - b * b, 2 * a * b
                    # a, b = aa + ca, bb + cb
                    if abs(a + b) > 16:
                        break
                    n += 1

                bright = mapping(n, 0, self.max_iteration, 0, 1)
                bright = mapping(math.sqrt(bright), 0, 1, 0, 255)
                if n is self.max_iteration:
                    bright = 0

                self.canvas.set_at([x, y], (bright, bright, bright))
コード例 #6
0
 def setup(self):
     for i in range(0, self.width, 20):
         y = mapping(noise(10), 0, 1, 0, 600)
         self.pixies.append(point2(i - 1, y))
         self.pixies.append(point2(i, 300))
コード例 #7
0
 def __getBgPosBySlidY(self):
     return self.__areaBgPos[0], int(mapping(self.__slidPosY, 0, self.area.h, 0, self.__allTextLength))
コード例 #8
0
 def __getSlidYByBgPos(self):
     return int(mapping(abs(self.__areaBgPos[1]), 0, self.__allTextLength, 0, self.area.h))