예제 #1
0
def draw_grid(min_x, max_x, min_y, max_y):
	w, h = canvas.get_size()
	scale_x = w / (max_x - min_x)
	scale_y = h / (max_y - min_y)
	min_x, max_x = round(min_x), round(max_x)
	min_y, max_y = round(min_y), round(max_y)
	canvas.begin_updates()
	canvas.set_line_width(1)
	canvas.set_stroke_color(0.7, 0.7, 0.7)
	#Draw vertical grid lines:
	x = min_x
	while x <= max_x:
		if x != 0:
			draw_x = round(w / 2 + x * scale_x) + 0.5
			canvas.draw_line(draw_x, 0, draw_x, h)
		x += 0.5
	#Draw horizontal grid lines:
	y = min_y
	while y <= max_y:
		if y != 0:
			draw_y = round(h/2 + y * scale_y) + 0.5
			canvas.draw_line(0, draw_y, w, draw_y)
		y += 0.5
	#Draw x and y axis:
	canvas.set_stroke_color(0, 0, 0)
	canvas.draw_line(0, h/2, w, h/2)
	canvas.draw_line(w/2, 0, w/2, h)
	canvas.end_updates()
예제 #2
0
def draw_grid():
    console.clear()
    canvas.set_size(size_x, size_y)
    canvas.begin_updates()
    canvas.set_line_width(1)
    canvas.set_stroke_color(0.7, 0.7, 0.7)
    #Draw vertical grid lines:
    x = grid
    while x <= max(abs(min_x), abs(max_x)):
        cx = t_c_x(x)
        if cx > 0 and cx < size_x:
            canvas.draw_line(cx, 0, cx, size_y)

        cx = t_c_x(-x)
        if cx > 0 and cx < size_x:
            canvas.draw_line(cx, 0, cx, size_y)

        x += grid

    y = grid
    while y <= max(abs(min_y), abs(max_y)):
        cy = t_c_y(y)
        if cy > 0 and cy < size_y:
            canvas.draw_line(0, cy, size_x, cy)

        cy = t_c_y(-y)
        if cy > 0 and cy < size_y:
            canvas.draw_line(0, cy, size_x, cy)

        y += grid

    canvas.set_stroke_color(0, 0, 0)
    cx = t_c_x(0)
    if cx > 0 and cx < size_x:
        canvas.draw_line(cx, 0, cx, size_y)
    cy = t_c_y(0)
    if cy > 0 and cy < size_y:
        canvas.draw_line(0, cy, size_x, cy)
    canvas.end_updates()
예제 #3
0
                 start_y - (0.5 * circle_size))

    rstrokedline(start_x - step, start_y + (1.5 * circle_size), start_x + step,
                 start_y - (1.5 * circle_size))
    rstrokedline(start_x - step, start_y - (1.5 * circle_size), start_x + step,
                 start_y + (1.5 * circle_size))

    rstrokedline(start_x - step, start_y + (2.5 * circle_size), start_x + step,
                 start_y - (2.5 * circle_size))
    rstrokedline(start_x - step, start_y - (2.5 * circle_size), start_x + step,
                 start_y + (2.5 * circle_size))

    rstrokedline(start_x - (3.0 * step), start_y + (0.5 * circle_size),
                 start_x + (3.0 * step), start_y - (0.5 * circle_size))
    rstrokedline(start_x - (3.0 * step), start_y - (0.5 * circle_size),
                 start_x + (3.0 * step), start_y + (0.5 * circle_size))


for x in xrange(int(math.ceil(width / circle_size)) + 1):
    for y in xrange(int(math.ceil(height / circle_size)) + 1):
        center_x = x * (2.0 * step)
        center_y = y * circle_size
        hexacircle(center_x, center_y)
        hexacircle(center_x + step, center_y + (0.5 * circle_size))

# Mute with a 15% black overlay
canvas.set_fill_color(0, 0, 0, 0.15)
canvas.draw_rect(0, 0, width, height)

canvas.end_updates()
예제 #4
0
canvas.set_size(width, height)
canvas.set_fill_color(*palette['darkest'])
canvas.fill_rect(0, 0, width, height)

canvas.set_fill_color(*random.choice(palette['palette']))
canvas.set_stroke_color(*palette['lightest'])
start_x, start_y = (width / 2.0, height / 2.0)

lollipop_points = []

for x in xrange(64):
	end_x, end_y = (random.random() * (width * 0.8) + (width * 0.1), random.random() * (height * 0.8) + (height * 0.1))
	lollipop_points.append((end_x, end_y))
	canvas.set_line_width(random.random() * 0.75 + 0.25)
	canvas.draw_line(start_x, start_y, end_x, end_y)
	
for x in xrange(64):
	end_x, end_y = lollipop_points[x]
	size = random.random() * 128.0 + 32.0
	canvas.fill_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size)
	canvas.set_line_width(1.25)
	canvas.draw_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size)

size = random.random() * 128.0 + 32.0
canvas.fill_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size)
canvas.set_line_width(1.25)
canvas.draw_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size)

canvas.end_updates()
예제 #5
0
 def draw_recorded(self):
     canvas.draw_path()
     canvas.end_updates()
예제 #6
0
    def paint(self, width, height):
        # start with unit diagonal
        self.unit_diagonal(self.view_tm)

        # rotate object
        self.rotx(self.xinc, self.rotx_tm)
        self.am4x4(self.view_tm, self.rotx_tm, self.view_tm)

        self.roty(self.yinc, self.roty_tm)
        self.am4x4(self.view_tm, self.roty_tm, self.view_tm)

        self.rotz(self.zinc, self.rotz_tm)
        self.am4x4(self.view_tm, self.rotz_tm, self.view_tm)

        # scale
        self.scaleit(self.scale, self.scale, self.scale, self.scale_tm)
        self.am4x4(self.view_tm, self.scale_tm, self.view_tm)

        # move coordinates to origin
        self.trans(-self.xe, -self.ye, -self.ze, self.trans_tm)
        self.am4x4(self.view_tm, self.trans_tm, self.view_tm)

        # rotate -90 deg. about x axis
        self.rotx(1.5708, self.rotx_tm)
        self.am4x4(self.view_tm, self.rotx_tm, self.view_tm)

        # rotate -theta about y axis
        theta = math.atan2(-(self.xe - self.xt), -(self.ye - self.yt))
        self.roty(-theta, self.roty_tm)
        self.am4x4(self.view_tm, self.roty_tm, self.view_tm)

        # rotate -phi around x axis
        phi = math.atan2((self.ze - self.zt),
                         math.sqrt((self.xe - self.xt) * (self.xe - self.xt) +
                                   (self.ye - self.yt) * (self.ye - self.yt)))
        self.rotx(-phi, self.rotx_tm)
        self.am4x4(self.view_tm, self.rotx_tm, self.view_tm)

        # change rh to lh coordinates
        self.scaleit(1, -1, -1, self.scale_tm)
        self.am4x4(self.view_tm, self.scale_tm, self.view_tm)

        # add perspective
        if self.persp:
            self.perspect(self.s, self.d, self.persp_tm)
            self.am4x4(self.view_tm, self.persp_tm, self.view_tm)

        # transform the view
        self.am20x4(self.view_tm, self.view)

        # draw the view in width/height
        orgx = width / 2
        orgy = height / 2
        if self.persp:
            for i in range(self.vertnum):
                self.view[i][0] = (orgx * self.view[i][0] /
                                   self.view[i][2]) + orgx
                self.view[i][1] = (orgy * self.view[i][1] /
                                   self.view[i][2]) + orgy
        canvas.begin_updates()
        canvas.set_size(width, height)
        canvas.set_stroke_color(0, 1, 0)
        for i in range(self.facenum):
            for j in range(self.edgenum[i] - 1):
                canvas.draw_line(self.view[self.face[i][j]][0],
                                 self.view[self.face[i][j]][1],
                                 self.view[self.face[i][j + 1]][0],
                                 self.view[self.face[i][j + 1]][1])
            canvas.draw_line(self.view[self.face[i][j + 1]][0],
                             self.view[self.face[i][j + 1]][1],
                             self.view[self.face[i][0]][0],
                             self.view[self.face[i][0]][1])
            canvas.set_fill_color(0, 1, 0)
        self.frames += 1
        canvas.draw_text(
            'Object: ' + self.name + '   Frames: ' + str(self.frames) +
            '   Angle: ' + str(self.yinc), 10, 10)
        canvas.end_updates()