Example #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()
Example #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()
Example #3
0
import canvas
import random
import math

from urbanape import common_devices
from kuler import *

random.seed()

width, height = common_devices['ipad_r']
circle_size = 192.0
step = math.sqrt(circle_size**2 - (circle_size / 2.0)**2)

palette = let_the_rays_fall_on_the_earth

canvas.begin_updates()

canvas.set_size(width, height)
canvas.set_fill_color(*random.choice(palette))
canvas.fill_rect(0, 0, width, height)

for x in range(100):
    r, g, b = random.choice(palette)
    a = random.random() * 0.5 + 0.25
    canvas.set_fill_color(r, g, b, a)
    origin_x = random.random() * width
    origin_y = random.random() * height
    csize = random.random() * (width / 8.0) + (width / 16.0)
    canvas.fill_ellipse(origin_x, origin_y, csize, csize)

Example #4
0
import canvas
import random
import math

from urbanape import common_devices
from kuler import *

random.seed()

width, height = common_devices['ipad_r']
palette = robots_are_cool

canvas.begin_updates()

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):
Example #5
0
 def record_drawing(self):
     canvas.begin_updates()
Example #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()