示例#1
0
    def plot(self, mode):
        if self.state:
            strokeWeight(1)
            if mode == 1:
                self.variation = "a"
            if mode == 2:
                self.variation = "b"
            if mode == 3:
                self.variation = "c"
            if mode == 4:
                self.variation = choice(("a", "b", "c"))
            if mode == -1:
                fill(100)
                noStroke()
                rect(self.pos.x, self.pos.y, self.size_, self.size_)
            noFill()
            """ draws node """
            with pushMatrix():
                translate(self.pos.x, self.pos.y)
                rotate(HALF_PI * self.ang)
                noFill()  # stroke(0)
                siz = self.size_
                l = siz / 2.
                a = l / 2. - 1
                c = l / 2. + 1
                # base rect
                #stroke(0, 0, 200, 50)
                #rect(0, 0, siz, siz)
                #text(self.type, 0, 0)
                # inv t & inv l
                if (self.type == "11110" or self.type == "10110"
                        or self.type == "00101"):
                    rotate(PI)
                if (self.type == "11101" or self.type == "01110"
                        or self.type == "11100"
                        or self.type == "00110"):  # t r & i
                    rotate(HALF_PI)
                if (self.type == "10111" or self.type == "00111"
                        or self.type == "01100"):  # t l
                    rotate(PI + HALF_PI)

                for i in range(Cell.step_start, Cell.step_end,
                               Cell.step):  # (-28, 29, 7):
                    stroke(64 + i * 8, 128, 64 - i * 8)
                    if self.type == "11111" and self.variation == "b":
                        quarter_circle(l, l, c + i, TOP + LEFT)
                        quarter_circle(-l, -l, c + i, BOTTOM + RIGHT)
                        quarter_circle(-l, l, c + i, TOP + RIGHT)
                        quarter_circle(l, -l, c + i, BOTTOM + LEFT)
                    if self.type == "11111" and self.variation == "a":
                        #ellipse(0, 0, (a + i) * 2, (a + i) * 2)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        half_circle(0, l, a - i, TOP)
                        half_circle(0, -l, a - i, BOTTOM)
                    if self.type == "11111" and self.variation == "c":
                        line(+a - i, -l, +a - i, l)
                        line(-a + i, -l, -a + i, l)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                    #     ellipse(0, 0, (a + i) * 2, (a + i) * 2)
                    elif (self.type == "01111" or  # t
                          self.type == "11110" or
                          self.type == "11101" or self.type == "10111"):  # t
                        if self.variation == "b":
                            #line(-l, a + i, l, a + i)
                            line(-l, -a + i, l, -a + i)
                            #half_circle(-l, 0, a - i, RIGHT)
                            #half_circle(l, 0, a - i, LEFT)
                            #half_circle(0, l, a - i, TOP)
                            quarter_circle(l, l, c + i, TOP + LEFT)
                            #quarter_circle(-l, -l, c + i, BOTTOM + RIGHT)
                            quarter_circle(-l, l, c + i, TOP + RIGHT)
                            #quarter_circle(l, -l, c + i, BOTTOM + LEFT)
                            #ellipse(0, 0, (a + i) * 2, (a + i) * 2)
                        elif self.variation == "c":
                            half_circle(-l, 0, a - i, RIGHT)
                            half_circle(l, 0, a - i, LEFT)
                            half_circle(0, l, a - i, TOP)
                            #ellipse(0, 0, (a + i) * 2, (a + i) * 2)
                        else:
                            line(-l, -a + i, l, -a + i)
                            half_circle(-l, 0, a - i, RIGHT)
                            half_circle(l, 0, a - i, LEFT)
                            half_circle(0, l, a - i, TOP)

                    elif self.type == "10101" or self.type == "01110":
                        if self.variation in "a":
                            line(+a - i, -l, +a - i, l)
                            line(-a + i, -l, -a + i, l)
                            half_circle(0, l, a - i, TOP)
                            half_circle(0, -l, a - i, BOTTOM)
                        if self.variation in "b":
                            line(+a - i, -l, +a - i, l)
                            line(-a + i, -l, -a + i, l)
                        elif self.variation == "c":
                            half_circle(0, l, a - i, TOP)
                            half_circle(0, -l, a - i, BOTTOM)
                            #ellipse(0, 0, (a + i) * 2, (a + i) * 2)
                    elif (self.type == "01101" or self.type == "10110"
                          or self.type == "00111"
                          or self.type == "11100"):  # l
                        if self.variation == "c":
                            # stroke(255, 0, 0)
                            # text(self.type, 0, 0)
                            half_circle(-l, 0, a - i, RIGHT)
                            half_circle(0, l, a - i, TOP)
                        elif self.variation == "b":
                            # stroke(0, 255, 0)
                            # text(self.type, 0, 0)
                            quarter_circle(-l, l, siz - c - i, TOP + RIGHT)
                            i *= -1
                            quarter_circle(-l, l, c - i, TOP + RIGHT)
                            #half_circle(-l, 0, a - i, RIGHT)
                            #half_circle(0, l, a - i, TOP)
                        else:
                            quarter_circle(-l, l, siz - c - i, TOP + RIGHT)
                            #i *= -1
                            #quarter_circle(-l, l, c - i, TOP + RIGHT)
                            half_circle(-l, 0, a - i, RIGHT)
                            half_circle(0, l, a - i, TOP)

                    elif (self.type == "01100" or self.type == "00110"
                          or self.type == "00101" or self.type == "10100"):
                        if self.variation in "ab":
                            line(+a - i, -l, +a - i, 0)
                            line(-a + i, -l, -a + i, 0)
                            half_circle(0, 0, a - i, BOTTOM)
                        if self.variation in "ac":
                            half_circle(0, 0, a - i, TOP)
                            half_circle(0, 0, a - i, BOTTOM)
                            half_circle(0, -l, a - i, BOTTOM)

                    elif self.type == "00100":
                        if self.variation == "b":
                            rect(0, 0, (a - i) * 2, (a - i) * 2, (a - i - 1))
                        elif self.variation == "a":
                            ellipse(0, 0, (a + i) * 2.0, (a + i) * 2.0)
                            ellipse(0, 0, (a - i) * 2.5, (a - i) * 2.5)
                        elif self.variation == "c":
                            half_circle(0, 0, a - i, TOP)
                            half_circle(0, 0, a - i, BOTTOM)
示例#2
0
    def plot(self, mode):
        if self.state:
            strokeWeight(1)
            if mode == 1:
                self.variation = "a"
            if mode == 2:
                self.variation = "b"
            if mode == 3:
                self.variation = "c"
            if mode == 4:
                self.variation = "d"
            if mode == 5:
                self.variation = choice(("a", "b", "c", "d"))
            if mode == -1:
                fill(100, 100)
                noStroke()
                rect(self.pos.x, self.pos.y, self.size_, self.size_)
                noFill()
            siz = self.size_
            l = siz / 2.
            a = l / 2.  #- 1
            c = l / 2.  #+ 1
            # diagonal mode
            if mode == 6:
                i, j = self.index
                for (ni, nj) in Cell.DNL:
                    nb = Cell.grid.get((i + ni, j + nj), None)
                    if nb and nb.state and ni <> 0 and nj <> 0:
                        for ii in range(Cell.step_start, Cell.step_end,
                                        Cell.step):  # (-28, 29, 7):
                            stroke(64 - ii * 8, 128, 64 + ii * 8)
                            bar(self.pos.x,
                                self.pos.y,
                                nb.pos.x,
                                nb.pos.y, (a + ii) * 2,
                                ends=(0, 1))
            """ draws node """
            with pushMatrix():
                translate(self.pos.x, self.pos.y)
                noFill()  # stroke(0)
                if (self.type == "11110" or self.type == "10110"
                        or self.type == "00101"):
                    rotate(PI)
                if (self.type == "11101" or self.type == "01110"
                        or self.type == "11100" or self.type == "00110"
                        or (self.type == "11111" and self.ang % 2)):  # t r & i
                    rotate(HALF_PI)
                if (self.type == "10111" or self.type == "00111"
                        or self.type == "01100"):  # t l
                    rotate(PI + HALF_PI)

                for i in range(Cell.step_start, Cell.step_end,
                               Cell.step):  # (-28, 29, 7):
                    stroke(128, 64 + i * 8, 64 - i * 8)
                    if self.type == "11111" and self.variation in "bd":
                        quarter_circle(l, l, c + i, TOP + LEFT)
                        quarter_circle(-l, -l, c + i, BOTTOM + RIGHT)
                        quarter_circle(-l, l, c + i, TOP + RIGHT)
                        quarter_circle(l, -l, c + i, BOTTOM + LEFT)
                    if self.type == "11111" and self.variation == "d":
                        ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                    if self.type == "11111" and self.variation == "a":
                        # ellipse(0, 0, (a + i) * 2, (a + i) * 2)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        half_circle(0, l, a - i, TOP)
                        half_circle(0, -l, a - i, BOTTOM)
                    if self.type == "11111" and self.variation == "c":
                        line(+a - i, -l, +a - i, l)
                        line(-a + i, -l, -a + i, l)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        #if keyPressed: ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                    elif (self.type == "01111" or  # t
                          self.type == "11110" or
                          self.type == "11101" or self.type == "10111"):  # t
                        if self.variation in "bd":
                            line(-l, -a + i, l, -a + i)
                            quarter_circle(l, l, c + i, TOP + LEFT)
                            quarter_circle(-l, l, c + i, TOP + RIGHT)
                        elif self.variation == "c":
                            half_circle(-l, 0, a - i, RIGHT)
                            half_circle(l, 0, a - i, LEFT)
                            half_circle(0, l, a - i, TOP)
                        if self.variation in "cd":
                            ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                        if self.variation == "a":
                            line(-l, -a + i, l, -a + i)
                            half_circle(-l, 0, a - i, RIGHT)
                            half_circle(l, 0, a - i, LEFT)
                            half_circle(0, l, a - i, TOP)

                    elif self.type == "10101" or self.type == "01110":
                        if self.variation == "d":
                            line(+a - i, -l, +a - i, l)
                            line(-a + i, -l, -a + i, l)
                            half_circle(0, l, a - i, TOP)
                            half_circle(0, -l, a - i, BOTTOM)
                        if self.variation in "abc":
                            line(+a - i, -l, +a - i, l)
                            line(-a + i, -l, -a + i, l)
                        if self.variation in "cd":
                            ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                        elif self.variation == "c":
                            half_circle(0, l, a - i, TOP)
                            half_circle(0, -l, a - i, BOTTOM)
                            #ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                    elif (self.type == "01101" or self.type == "10110"
                          or self.type == "00111"
                          or self.type == "11100"):  # l
                        if self.variation == "c":
                            # stroke(255, 0, 0)
                            # text(self.type, 0, 0)
                            half_circle(-l, 0, a - i, RIGHT)
                            half_circle(0, l, a - i, TOP)
                            ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                        elif self.variation == "b":
                            # stroke(0, 255, 0)
                            # text(self.type, 0, 0)
                            quarter_circle(-l, l, siz - c - i, TOP + RIGHT)
                            i *= -1
                            quarter_circle(-l, l, c - i, TOP + RIGHT)
                        else:
                            quarter_circle(-l, l, siz - c - i, TOP + RIGHT)
                            half_circle(-l, 0, a - i, RIGHT)
                            half_circle(0, l, a - i, TOP)

                    elif (self.type == "01100" or self.type == "00110"
                          or self.type == "00101" or self.type == "10100"):
                        if self.variation in "bd":
                            half_circle(0, 0, a - i, BOTTOM)
                        if self.variation in "abd":
                            line(+a - i, -l, +a - i, 0)
                            line(-a + i, -l, -a + i, 0)
                        if self.variation in "ac":
                            ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                            half_circle(0, -l, a - i, BOTTOM)

                    elif self.type == "00100":
                        ellipse(0, 0, (a - i) * 2, (a - i) * 2)
示例#3
0
    def draw_node(self):
        """ draws node """
        siz = self.size_
        l = siz / 2.
        a = l / 2.  # - 1
        c = l / 2.  # + 1
        with pushMatrix():
            translate(self.pos.x, self.pos.y)
            if Cell.debug_mode:
                fill(0)
                text(self.type, 0, 0)
            noFill()  # stroke(0)
            rotation = {
                "11110": PI,
                "10110": PI,
                "00101": PI,
                "11101": HALF_PI,
                "01110": HALF_PI,
                "11100": HALF_PI,
                "00110": HALF_PI,
                "11111": HALF_PI * self.ang,
                "10111": PI + HALF_PI,
                "00111": PI + HALF_PI,
                "01100": PI + HALF_PI
            }
            # rotation appropriate for each type
            rotate(rotation.get(self.module, 0))

            for i in range(Cell.step_start, Cell.step_end,
                           Cell.step):  # (-28, 29, 7):
                stroke(16 + i * 8, 255, 255)

                if self.type == Cell.A:
                    if self.variation in "bd":
                        quarter_circle(l, l, c + i, TOP + LEFT)
                        quarter_circle(-l, -l, c + i, BOTTOM + RIGHT)
                        quarter_circle(-l, l, c + i, TOP + RIGHT)
                        quarter_circle(l, -l, c + i, BOTTOM + LEFT)
                    if self.variation in "de":
                        rect(0, 0, (a - i) * 2, (a - i) * 2)
                    if self.variation in "ae":
                        # rect(0, 0, (a + i) * 2, (a + i) * 2)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        half_circle(0, l, a - i, TOP)
                        half_circle(0, -l, a - i, BOTTOM)
                    if self.variation == "c":
                        line(+a - i, -l, +a - i, l)
                        line(-a + i, -l, -a + i, l)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        # if keyPressed: rect(0, 0, (a - i) * 2, (a - i) * 2)

                elif self.type == Cell.T:
                    if self.variation in "bde":
                        line(-l, -a + i, l, -a + i)
                        quarter_circle(l, l, c + i, TOP + LEFT)
                        quarter_circle(-l, l, c + i, TOP + RIGHT)
                    elif self.variation == "c":
                        pass
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        half_circle(0, l, a - i, TOP)
                    if self.variation in "ce":
                        box((a - i) * 2)
                    if self.variation == "a":
                        line(-l, -a + i, l, -a + i)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        half_circle(0, l, a - i, TOP)

                elif self.type == Cell.I:
                    if self.variation == "ce":
                        box((a - i) * 2)
                    if self.variation in "abde":
                        line(+a - i, -l, +a - i, l)
                        line(-a + i, -l, -a + i, l)
                    if self.variation in "ca":
                        half_circle(0, l, a - i, TOP)
                        half_circle(0, -l, a - i, BOTTOM)

                elif self.type == Cell.L:
                    if self.variation in "a":
                        quarter_circle(-l, l, siz - c - i, TOP + RIGHT)
                    elif self.variation == "b":
                        quarter_circle(-l, l, siz - c - i, TOP + RIGHT)
                        i *= -1
                        quarter_circle(-l, l, c - i, TOP + RIGHT)
                    elif self.variation in "ce":
                        box((a - i) * 2)
                    if self.variation in "acde":
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(0, l, a - i, TOP)

                elif self.type == Cell.C:
                    if self.variation in "ac":
                        half_circle(0, -l, a - i, BOTTOM)
                    if self.variation in "abe":
                        half_circle(0, 0, a - i, BOTTOM)
                    if self.variation in "abde":
                        line(+a - i, -l, +a - i, 0)
                        line(-a + i, -l, -a + i, 0)
                    if self.variation in "dc":
                        box((a - i) * 2)
                    if self.variation == "e":
                        half_circle(0, -l / 2, a - i, TOP)

                elif self.type == Cell.N:
                    box((a - i) * 2)
示例#4
0
    def draw_node(self):
        """ draws node """
        if Cell.debug_mode:
            stroke(0, 255, 0)
            text(Cell.types(self.type), 0, 0)
        siz = self.size_
        l = siz / 2.
        a = l / 2.  # - 1
        c = l / 2.  # + 1
        with pushMatrix():
            translate(self.pos.x, self.pos.y)
            noFill()  # stroke(0)
            rotation = {
                "11110": PI,
                "10110": PI,
                "00101": PI,
                "11101": HALF_PI,
                "01110": HALF_PI,
                "11100": HALF_PI,
                "00110": HALF_PI,
                "11111": HALF_PI * self.ang,
                "10111": PI + HALF_PI,
                "00111": PI + HALF_PI,
                "01100": PI + HALF_PI
            }
            rotate(rotation.get(self.type, 0))

            for i in range(Cell.step_start, Cell.step_end,
                           Cell.step):  # (-28, 29, 7):
                stroke(8, 64 + i * 8, 64 - i * 8)

                if Cell.types[self.type] == Cell.A:
                    if self.variation in "bd":
                        quarter_circle(l, l, c + i, TOP + LEFT)
                        quarter_circle(-l, -l, c + i, BOTTOM + RIGHT)
                        quarter_circle(-l, l, c + i, TOP + RIGHT)
                        quarter_circle(l, -l, c + i, BOTTOM + LEFT)
                    if self.variation == "d":
                        ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                    if self.variation == "a":
                        # ellipse(0, 0, (a + i) * 2, (a + i) * 2)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        half_circle(0, l, a - i, TOP)
                        half_circle(0, -l, a - i, BOTTOM)
                    if self.variation == "c":
                        line(+a - i, -l, +a - i, l)
                        line(-a + i, -l, -a + i, l)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        # if keyPressed: ellipse(0, 0, (a - i) * 2, (a - i) * 2)

                elif Cell.types[self.type] == Cell.T:
                    if self.variation in "bd":
                        line(-l, -a + i, l, -a + i)
                        quarter_circle(l, l, c + i, TOP + LEFT)
                        quarter_circle(-l, l, c + i, TOP + RIGHT)
                    elif self.variation == "c":
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        half_circle(0, l, a - i, TOP)
                    if self.variation in "cd":
                        ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                    if self.variation == "a":
                        line(-l, -a + i, l, -a + i)
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(l, 0, a - i, LEFT)
                        half_circle(0, l, a - i, TOP)

                elif Cell.types[self.type] == Cell.I:
                    if self.variation == "d":
                        ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                    if self.variation in "abd":
                        line(+a - i, -l, +a - i, l)
                        line(-a + i, -l, -a + i, l)
                    if self.variation in "ca":
                        half_circle(0, l, a - i, TOP)
                        half_circle(0, -l, a - i, BOTTOM)

                elif Cell.types[self.type] == Cell.L:
                    if self.variation in "a":
                        quarter_circle(-l, l, siz - c - i, TOP + RIGHT)
                    elif self.variation == "b":
                        quarter_circle(-l, l, siz - c - i, TOP + RIGHT)
                        i *= -1
                        quarter_circle(-l, l, c - i, TOP + RIGHT)
                    elif self.variation == "c":
                        ellipse(0, 0, (a - i) * 2, (a - i) * 2)
                    if self.variation in "acd":
                        half_circle(-l, 0, a - i, RIGHT)
                        half_circle(0, l, a - i, TOP)

                elif Cell.types[self.type] == Cell.C:
                    if self.variation in "ac":
                        half_circle(0, -l, a - i, BOTTOM)
                    if self.variation in "ab":
                        half_circle(0, 0, a - i, BOTTOM)
                    if self.variation in "abd":
                        line(+a - i, -l, +a - i, 0)
                        line(-a + i, -l, -a + i, 0)
                    if self.variation in "dc":
                        ellipse(0, 0, (a - i) * 2, (a - i) * 2)

                elif Cell.types[self.type] == Cell.N:
                    ellipse(0, 0, (a - i) * 2, (a - i) * 2)