Exemple #1
0
 def parse(self, screen, fill_color, line_color):
     screen.fill(fill_color)
     m = Edge_Matrix()
     t = m.get_identity()
     i = 0
     while i < len(self.lines):
         if self.lines[i] == "c":
             i += 1
             m.add_circle(*self.lines[i])
         elif self.lines[i] == "h":
             i += 1
             args = self.lines[i]
             m.add_curve(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], 0)
         elif self.lines[i] == "b":
             i += 1
             args = self.lines[i]
             m.add_curve(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], 1)
         elif self.lines[i] == "l":
             i += 1
             m.add_edge(*self.lines[i])
         elif self.lines[i] == "i":
             t = m.get_identity()
         elif self.lines[i] == "s":
             i += 1
             #print("s", self.lines[i])
             sm = m.get_scale_matrix(*self.lines[i])
             #print(sm)
             t = t.matrix_mult(sm)
             #print(t)
         elif self.lines[i] == "t":
             i += 1
             tm = m.get_translation_matrix(*self.lines[i])
             t = t.matrix_mult(tm)
         elif self.lines[i] == "x":
             i += 1
             xr = m.get_rotation_matrix_x(*self.lines[i])
             t = t.matrix_mult(xr)
         elif self.lines[i] == "y":
             i += 1
             yr = m.get_rotation_matrix_y(*self.lines[i])
             t = t.matrix_mult(yr)
         elif self.lines[i] == "z":
             i += 1
             zr = m.get_rotation_matrix_z(*self.lines[i])
             t = t.matrix_mult(zr)
         elif self.lines[i] == "a":
             #print(str(m) + "\n")
             #print(str(t) + "\n")
             m = m.matrix_mult_by(t)
             #print(str(m) + "\n")
         elif self.lines[i] == "v":
             temp_name = "/var/tmp/temp.ppm"
             with open(temp_name, "w") as f:
                 draw_matrix(m, screen, line_color)
                 f.write(screen.gen_ppm())
             os.system("display %s" %(temp_name, ))
             os.remove(temp_name)
             screen.fill(fill_color)
         elif self.lines[i] == "g":
             i += 1
             with open(self.lines[i], "w") as f:
                 draw_matrix(m, screen, line_color)
                 f.write(screen.gen_ppm())
             os.system("convert %s %s" %(str(self.lines[i]), str(self.lines[i])))
             screen.fill(fill_color)
         elif self.lines[i] == "q":
             return
         else:
             print("line %i: %s" %(i, str(self.lines[i])))
             raise Exception
         i += 1
Exemple #2
0
GREEN = 0
BLUE = 0
YRES = 500
XRES = 500

screen = Screen(XRES, YRES)
color = RGB(red=RED, green=GREEN, blue=BLUE)

for x in range(XRES):
    for y in range(XRES):
        screen.plot(x, y, color.copy())

color.set_colors(red=0)

mid_y = YRES // 2
mid_x = XRES // 2
m = Edge_Matrix()

for i in range(11):
    m.add_edge(mid_x, mid_y, 0, i * 50, 0, 0)
    m.add_edge(mid_x, mid_y, 0, 0, i * 50, 0)
    m.add_edge(mid_x, mid_y, 0, 500, i * 50, 0)
    m.add_edge(mid_x, mid_y, 0, i * 50, 500, 0)

draw_matrix(m, screen, color)

with open("result.ppm", "w") as f:
    f.write(screen.gen_ppm())

os.system("display result.ppm")