FC2ブログ

Python::user-defined_class::mark

# -*- coding: utf-8 -*-
import copy
class mark:
    def __init__ (self, name, center, lines):
        self.name = name
        self.center = copy.deepcopy(center)
        self.lines = lines
    
    def shift (self, delta):
        self.center = self.center - delta
        for i, l in enumerate(self.lines):
            self.lines[i] = self.lines[i].shift(-1 * delta)
        
    def print (self):
        print ("name = \"{0}\", center = ({1}, {2})".format(
                self.name, self.center.x, self.center.y))
        for l in self.lines:
            l.print()


from point2d import point2d
from line import line
lines__R = [
    line(*(point2d(-100, +100.0), point2d(+100, +100.0)), 1),
    line(*(point2d(-100, -100.0), point2d(+100, -100.0)), 1),
    line(*(point2d(-100, -100.0), point2d(-100, +100.0)), 1),
    line(*(point2d(+100, -100.0), point2d(+100, +100.0)), 1),
]

mark__R = mark("rectangle",   point2d(0, 0), lines__R)

関連記事
スポンサーサイト



コメント

非公開コメント