def left_hand(self, left_arm, colour, angle=0, part=Hand): # Displacement from left hand displacement = left_arm.position + left_arm.matrix * Vector(4, 17, -9) matrix = left_arm.matrix * Identity().rotate( 40, XAxis) * Identity().rotate(angle, ZAxis) piece = Piece(colour, displacement, matrix, part, self.group) self.pieces_info["left hand"] = piece return piece
def head(self, colour, angle=0, part=Head): """ Displacement from torso """ displacement = self.matrix * Vector(0, -24, 0) piece = Piece(colour, self.position + displacement, self.matrix * Identity().rotate(angle, YAxis), part, self.group) self.pieces_info["head"] = piece return piece
def right_leg(self, colour, angle=0, part=LegRight): """" Add a right leg""" displacement = self.matrix * Vector(0, 44, 0) piece = Piece(colour, self.position + displacement, self.matrix * Identity().rotate(angle, XAxis), part, self.group) self.pieces_info["right leg"] = piece return piece
def left_shoe(self, left_leg, colour, angle=0, part=None): """ Add a shoe on the left""" if not part: return None # Displacement from left leg displacement = left_leg.position + left_leg.matrix * Vector(10, 28, 0) matrix = left_leg.matrix * Identity().rotate(angle, YAxis) piece = Piece(colour, displacement, matrix, part, self.group) return piece
def left_arm(self, colour, angle=0, part=ArmLeft): """ Displacement from torso """ displacement = self.matrix * Vector(15, 8, 0) piece = Piece( colour, self.position + displacement, self.matrix * Identity().rotate(-10, ZAxis) * Identity().rotate(angle, XAxis), part, self.group) self.pieces_info["left arm"] = piece return piece
def right_hand(self, right_arm, colour, angle=0, part=Hand): # Displacement from right arm displacement = right_arm.position + right_arm.matrix * Vector( -4, 17, -9) matrix = right_arm.matrix * Identity().rotate( 40, XAxis) * Identity().rotate(angle, ZAxis) piece = Piece(colour, displacement, matrix, part, self.group) self.pieces_info["right hand"] = piece return piece
def test_add_piece(): group1 = Group() group2 = Group() piece = Piece(White, Vector(0, 0, 0), Identity(), Brick1X1, group=group1) assert piece in group1.pieces assert piece not in group2.pieces group2.add_piece(piece) assert piece in group2.pieces assert piece not in group1.pieces
def _sub_file(pieces): if len(pieces) != 14: raise PartError("Invalid part data") colour = colour_from_str(pieces[0]) position = list(map(float, pieces[1:4])) rows = [ list(map(float, pieces[4:7])), list(map(float, pieces[7:10])), list(map(float, pieces[10:13])) ] part = pieces[13].upper() if re.search(ENDS_DOT_DAT, part): part = part[:-4] return Piece(Colour(colour), Vector(*position), Matrix(rows), part)
def right_hand_item(self, right_hand, colour, displacement, angle=0, part=None): """ Add a right hand item""" if not part: return None # Displacement from right hand displacement = right_hand.position + right_hand.matrix * displacement matrix = right_hand.matrix * Identity().rotate( 10, XAxis) * Identity().rotate(angle, YAxis) piece = Piece(colour, displacement, matrix, part, self.group) return piece
def left_hand_item(self, left_hand, colour, displacement, angle=0, part=None): """ Displacement from left hand """ if not part: return None # Displacement from left hand displacement = left_hand.position + left_hand.matrix * displacement matrix = left_hand.matrix * Identity().rotate( 10, XAxis) * Identity().rotate(angle, YAxis) piece = Piece(colour, displacement, matrix, part, self.group) return piece
def hips(self, colour, part=Hips): """ Displacement from torso """ displacement = self.matrix * Vector(0, 32, 0) return Piece(colour, self.position + displacement, self.matrix, part, self.group)
def backpack(self, colour, displacement=Vector(0, 0, 0), part=Airtanks): """ Displacement from torso """ displacement = self.matrix * displacement return Piece(colour, self.position + displacement, self.matrix, part, self.group)
def torso(self, colour, part=Torso): """ torso piece """ return Piece(colour, self.position, self.matrix, part, self.group)
def hat(self, head, colour, part="3901"): # Displacement from head displacement = head.position + head.matrix * Vector(0, 0, 0) piece = Piece(colour, displacement, head.matrix, part, self.group) return piece
# print(figure.head(Yellow, 30)) # print(figure.hat(White, "193B")) # print(figure.torso(White, "973P90")) # print(figure.backpack(White, Vector(0, -2, 0))) # print(figure.hips(White)) # print(figure.left_leg(White, 0)) # print(figure.right_leg(White, 0)) # print(figure.left_arm(White, -45)) # print(figure.left_hand(White, 0)) # print(figure.left_hand_item(Grey, Vector(0, -11, -12), 0, "3959") # Torch) # print(figure.right_arm(White, 0)) # print(figure.right_hand(White, 0)) # print() rover = Group(Vector(0, 48, 60), Identity().rotate(-15, YAxis)) print( Piece(Light_Grey, Vector(0, 0, 0), Identity(), Plate2X2WithRedWheels_Complete_, rover)) print( Piece(Rubber_Black, Vector(30, 6, 0), Identity().rotate(90, YAxis), Tyre6_50X8OffsetTread, rover)) print( Piece(Rubber_Black, Vector(-30, 6, 0), Identity().rotate(90, YAxis), Tyre6_50X8OffsetTread, rover)) print( Piece(Light_Grey, Vector(0, 0, -80), Identity(), Plate2X2WithRedWheels_Complete_, rover)) print( Piece(Rubber_Black, Vector(30, 6, -80), Identity().rotate(90, YAxis), Tyre6_50X8OffsetTread, rover)) print( Piece(Rubber_Black, Vector(-30, 6, -80), Identity().rotate(90, YAxis), Tyre6_50X8OffsetTread, rover))
print(figure.hips_and_legs(White)) print(figure.left_arm(White, -45)) print(figure.left_hand(White, 0)) print(figure.left_hand_item(Light_Grey, Vector(0, -11, -12), 0, Torch)) # Torch print(figure.right_arm(White, 0)) print(figure.right_hand(White, 0)) print( figure.right_hand_item(Light_Grey, Vector(0, -23, -12), 90, MetalDetector)) # Metal detector figure = Person(Vector(97.5, 0, 57.5), Identity().rotate(45, YAxis)) print(figure.head(Yellow, -15)) print(figure.hat(Red, HelmetClassic)) print(figure.torso(Red, TorsoWithClassicSpacePattern)) print(figure.backpack(Red, Vector(0, -2, 0))) print(figure.hips(Red)) print(figure.left_leg(Red, -55)) print(figure.right_leg(Red, 0)) print(figure.left_arm(Red, -45)) print(figure.left_hand(Red, 0)) print(figure.right_arm(Red, -30)) print(figure.right_hand(Red, 0)) print(figure.right_hand_item(Light_Grey, Vector(0, -11, -12), 0, Torch)) # Torch print('') print(Piece(Light_Grey, Vector(0, 72, 0), Identity(), Baseplate16X16)) print(Piece(Light_Grey, Vector(60, 72, -60), Identity(), Rock1X1Crystal5Point)) # Camera should be at 160.0,-80.0,-240.0 in LDraw coordinates.
""" import random from ldraw.colours import * from ldraw.figure import * from ldraw.pieces import Piece figure = Person(Vector(0, 0, -10), Identity().rotate(-15, ZAxis).rotate(20, XAxis)) print figure.head(Yellow, -15) print figure.hat(Black, "30090") # Diver Mask print figure.hat(Black, "3901") # Hair Male print figure.torso(Yellow, "973") # Torso print figure.backpack(Black, Vector(0, -2, 0), "3838") # Airtanks print figure.hips(Green) print figure.left_leg(Yellow, 30) print figure.left_shoe(Black, 10, "2599") # Flipper print figure.right_leg(Yellow, -10) print figure.right_shoe(Black, -10, "2599") # Flipper print figure.left_arm(Yellow, -45) print figure.left_hand(Yellow, 10) print figure.left_hand_item(Grey, Vector(0, 0, -12), -15, "30148") # Camera Movie print figure.right_arm(Yellow, 60) print figure.right_hand(Yellow, 0) print print Piece(Colour(15), Vector(-50, -200, -50), Identity(), "LIGHT") print Piece(Colour(15), Vector(50, -200, 0), Identity(), "LIGHT") print Piece(Colour(15), Vector(0, -200, 50), Identity(), "LIGHT") # Camera should be at 120.0,40.0,-200.0 in LDraw coordinates.
print(figure.torso(White, TorsoWithClassicSpacePattern)) print(figure.backpack(White, Vector(0, -2, 0))) print(figure.hips(White)) print(figure.left_leg(White, 0)) print(figure.right_leg(White, 0)) print(figure.left_arm(White, -45)) print(figure.left_hand(White, 0)) print(figure.left_hand_item(Light_Grey, Vector(0, -11, -12), 0, Torch)) # Torch print(figure.right_arm(White, 0)) print(figure.right_hand(White, 0)) print('') rover = Group(Vector(80, 48, 20), Identity()) print( Piece(Light_Grey, Vector(0, 0, 0), Identity(), Plate2X2WithRedWheels_Complete_, rover)) print( Piece(Black, Vector(30, 6, 0), Identity().rotate(90, YAxis), Tyre6_50X8OffsetTread, rover)) print( Piece(Black, Vector(-30, 6, 0), Identity().rotate(90, YAxis), Tyre6_50X8OffsetTread, rover)) print( Piece(Light_Grey, Vector(0, 0, -80), Identity(), Plate2X2WithRedWheels_Complete_, rover)) print( Piece(Black, Vector(30, 6, -80), Identity().rotate(90, YAxis), Tyre6_50X8OffsetTread, rover)) print( Piece(Black, Vector(-30, 6, -80), Identity().rotate(90, YAxis), Tyre6_50X8OffsetTread, rover))
print figure.head(Yellow, 30) print figure.hat(White, "193B") print figure.torso(White, "973P90") print figure.backpack(White, Vector(0, -2, 0)) print figure.hips(White) print figure.left_leg(White, 0) print figure.right_leg(White, 0) print figure.left_arm(White, -45) print figure.left_hand(White, 0) print figure.left_hand_item(Grey, Vector(0, -11, -12), 0, "3959") # Torch print figure.right_arm(White, 0) print figure.right_hand(White, 0) print rover = Group(Vector(80, 48, 20), Identity()) print Piece(Grey, Vector(0, 0, 0), Identity(), "122C01", rover) print Piece(Black, Vector(30, 6, 0), Identity().rotate(90, YAxis), "3641", rover) print Piece(Black, Vector(-30, 6, 0), Identity().rotate(90, YAxis), "3641", rover) print Piece(Grey, Vector(0, 0, -80), Identity(), "122C01", rover) print Piece(Black, Vector(30, 6, -80), Identity().rotate(90, YAxis), "3641", rover) print Piece(Black, Vector(-30, 6, -80), Identity().rotate(90, YAxis), "3641", rover) print Piece(Grey, Vector(0, 0, -40), Identity(), "3022", rover) print Piece(Grey, Vector(0, -24, -10), Identity().rotate(180, YAxis), "3039", rover) print Piece(Grey, Vector(0, -32, -10),
colors = list(rgb_code_dictionary.keys()) closest_colors = sorted(colors, key=lambda color: distance(color, point)) closest_color = closest_colors[0] code = rgb_code_dictionary[closest_color] #set the Lego colour to the colour code col = int(code) #Up the counter and increment the brick position counter += 1 y += 20 #Create a new row when the counter is greater than the width of the image if counter > width: #print "new row" LDrawFile.write('0 // NEW ROW ' + str(x / 20) + '\n') x += 20 y = 0 counter = 1 #print i,j,x,y,col,code #Used for checking #Write the brick to the file #print "Wrting brick here..." LDrawFile.write( str( Piece(Colour(col), Vector(x, z, y), Identity().rotate(rot, YAxis), "3024", onexonexone)) + '\n') print print "Your mosiac file", mosaicFilename, "is ready"
from ldraw.library.colours import * from ldraw.figure import * from ldraw.library.parts.minifig.accessories import HelmetClassicWithThickChinGuardAndVisorDimples as HelmetClassic, Torch, MetalDetector from ldraw.library.parts.minifig.torsos import TorsoWithClassicSpacePattern # from ldraw.library.parts.others import Baseplate16X16, Rock1X1Crystal5Point from ldraw.pieces import Piece, Group rover = Group(Vector(0, 0, 0), Identity()) r = Piece(White, Vector(0, 0, 0), Identity(), "44728", rover) print(r)
figure.hips(Black) figure.left_leg(Black, 50) figure.right_leg(Black, -40) group.position = Vector(-100, 40, -120) group.matrix = Identity().rotate(-30, ZAxis).rotate(90, YAxis) for piece in group.pieces: print(piece) stairs = Group() x = -120 y = 144 z = -160 steps = 5 Piece(Dark_Blue, Vector(x, y, z + 40), Identity(), Plate6X6, group=stairs) for i in range(0, steps): for pz in range(z, z + 120, 40): Piece(Dark_Blue, Vector(x + 50 + (i * 40), y - 24 - (i * 24), pz), Identity(), Brick2X3, group=stairs) for piece in stairs.pieces: print(piece) staircases = 7 for i in range(1, staircases + 1): stairs.position = Vector(0, i * (8 + steps * 24), 0) stairs.matrix = Identity().rotate(-90 * i, YAxis)
print figure.left_leg(White, 0) print figure.right_leg(White, 0) print figure.left_arm(White, -45) print figure.left_hand(White, 0) print figure.left_hand_item(Grey, Vector(0, -11, -12), 0, "3959") # Torch print figure.right_arm(White, 0) print figure.right_hand(White, 0) print figure.right_hand_item(Grey, Vector(0, -23, -12), 90, "4479") # Metal detector print figure = Person(Vector(97.5, 0, 57.5), Identity().rotate(45, YAxis)) print figure.head(Yellow, -15) print figure.hat(Red, "193B") print figure.torso(Red, "973P90") print figure.backpack(Red, Vector(0, -2, 0)) print figure.hips(Red) print figure.left_leg(Red, -55) print figure.right_leg(Red, 0) print figure.left_arm(Red, -45) print figure.left_hand(Red, 0) print figure.right_arm(Red, -30) print figure.right_hand(Red, 0) print figure.right_hand_item(Grey, Vector(0, -11, -12), 0, "3959") # Torch print print Piece(Grey, Vector(0, 72, 0), Identity(), "3867") print Piece(Grey, Vector(60, 72, -60), Identity(), "52") # Camera should be at 160.0,-80.0,-240.0 in LDraw coordinates.
figure.right_hand_item(ChromeSilver, Vector(0, -58, -20), 0, parts.parts["Minifig Tool Magnifying Glass"]) figure.hips(Black) figure.left_leg(Black, 50) figure.right_leg(Black, -40) group.position = Vector(-100, 40, -120) group.matrix = Identity().rotate(-30, ZAxis).rotate(90, YAxis) for piece in group.pieces: print piece stairs = Group() x = -120 y = 144 z = -160 steps = 5 Piece(DarkBlue, Vector(x, y, z + 40), Identity(), "3958", group = stairs) for i in range(0, steps): for pz in range(z, z + 120, 40): Piece(DarkBlue, Vector(x + 50 + (i * 40), y - 24 - (i * 24), pz), Identity(), "3002", group = stairs) for piece in stairs.pieces: print piece staircases = 7 for i in range(1, staircases + 1): stairs.position = Vector(0, i * (8 + steps * 24), 0) stairs.matrix = Identity().rotate(-90 * i, YAxis) for piece in stairs.pieces: print piece top_y = y - (steps * 24) - 8 print Piece(DarkBlue, Vector(120, top_y, -120), Identity(), "3958")
from ldraw.library.colours import * from ldraw.figure import * from ldraw.library.parts.minifig.accessories import DiverMask, HairMale, Airtanks, Flipper, CameraMovie from ldraw.library.parts.minifig.torsos import Torso from ldraw.pieces import Piece figure = Person(Vector(0, 0, -10), Identity().rotate(-15, ZAxis).rotate(20, XAxis)) print(figure.head(Yellow, -15)) print(figure.hat(Black, DiverMask)) print(figure.hat(Black, HairMale)) print(figure.torso(Yellow, Torso)) print(figure.backpack(Black, Vector(0, -2, 0), Airtanks)) print(figure.hips(Green)) print(figure.left_leg(Yellow, 30)) print(figure.left_shoe(Black, 10, Flipper)) print(figure.right_leg(Yellow, -10)) print(figure.right_shoe(Black, -10, Flipper)) print(figure.left_arm(Yellow, -45)) print(figure.left_hand(Yellow, 10)) print(figure.left_hand_item(Light_Grey, Vector(0, 0, -12), -15, CameraMovie)) # Camera Movie print(figure.right_arm(Yellow, 60)) print(figure.right_hand(Yellow, 0)) print('') print(Piece(White, Vector(-50, -200, -50), Identity(), "LIGHT")) print(Piece(White, Vector(50, -200, 0), Identity(), "LIGHT")) print(Piece(White, Vector(0, -200, 50), Identity(), "LIGHT")) # Camera should be at 120.0,40.0,-200.0 in LDraw coordinates.
#print figure.head(Yellow, 30) #print figure.hat(White, "193B") #print figure.torso(White, "973P90") #print figure.backpack(White, Vector(0, -2, 0)) #print figure.hips(White) #print figure.left_leg(White, 0) #print figure.right_leg(White, 0) #print figure.left_arm(White, -45) #print figure.left_hand(White, 0) #print figure.left_hand_item(Grey, Vector(0, -11, -12), 0, "3959") # Torch #print figure.right_arm(White, 0) #print figure.right_hand(White, 0) #print rover = Group(Vector(0, 48, 60), Identity().rotate(-15, YAxis)) print Piece(Grey, Vector(0, 0, 0), Identity(), "122C01", rover) print Piece(BlackRubber, Vector(30, 6, 0), Identity().rotate(90, YAxis), "3641", rover) print Piece(BlackRubber, Vector(-30, 6, 0), Identity().rotate(90, YAxis), "3641", rover) print Piece(Grey, Vector(0, 0, -80), Identity(), "122C01", rover) print Piece(BlackRubber, Vector(30, 6, -80), Identity().rotate(90, YAxis), "3641", rover) print Piece(BlackRubber, Vector(-30, 6, -80), Identity().rotate(90, YAxis), "3641", rover) print Piece(Grey, Vector(0, 0, -40), Identity(), "3022", rover) print Piece(ChromeSilver, Vector(0, -24, -10), Identity().rotate(180, YAxis), "3039", rover) print Piece(ChromeSilver, Vector(0, -32, -10),