Example #1
0
def paint_color_window(x_win, y_win, width, height, focus):
    global data_color
    global buff
    global color_action
    global message_listering
    click, x_click, y_click = buff
    for i in range(len(color)):
        for j in range(len(color[0])):
            width_rect = width / len(color[0])
            height_rect = height / len(color)
            canvas.fill_style(color[i][j])
            canvas.fill_rect(x_win + width_rect * j, y_win + height_rect * i,
                             width_rect, height_rect)
            data_color.append([
                x_win + width_rect * j, y_win + height_rect * i, width_rect,
                height_rect, color[i][j]
            ])

    if click and focus:
        for el in data_color:
            x, y, wid, hei, col = el
            if x < x_click < x + wid and y < y_click < y + hei:
                color_action = col
                print(col)
                buff[0] = False
                message_listering.append(['window', 'Color', 'close'])
                message_listering.append(['window', 'Paint', 'enable_focus'])
                break
Example #2
0
def draw():
  #ceci est la fonction qui gere l'ecran
  global bits
  canvas.fill_rect(0,0,500,500)
  left = 80
  top = 30
  canvas.draw_line((0,30+top),(500,30+top),4,'Blue')  
  cl2 = 'Yellow'
  
  canvas.draw_text("ENTREES",(left-30,25+top),24,cl2)
  canvas.draw_text("SORTIES",(left+250,25+top),24,cl2)
  canvas.draw_circle((left, 50+top), 10, 2, 'Blue', color(str(bits['A'])))
 
  canvas.draw_circle((left+250, 50+top), 10, 2, 'Blue', color(str(bits['A'])))
  
  canvas.draw_text("A: "+str(bits['A']),(left+15,58+top),24,cl2)
  canvas.draw_text("L: "+str(bits['A']),(left+265,58+top),24,cl2)
 
  canvas.draw_line((0,290+top),(100,290+top),3,'Red')
  #canvas.draw_line((150,290+top),(300,290+top),3,'Blue')
  canvas.draw_line((500,290+top),(150,290+top),3,'Blue') 
  
  canvas.draw_circle((420, 290+top), 30, 2, 'Blue', color(str(bits['A'])))
  
  canvas.draw_text("A",(115,270+top),24,cl2)
  canvas.draw_text("L",(410,240+top),24,cl2)
  
  if bits['A'] == 0:
    canvas.draw_line((100,290+top),(150,270+top),3,'Orange')
  else:
    canvas.draw_line((100,290+top),(150,290+top),3,'Orange')
  
  """
Example #3
0
def taskbar(height):
    global buff
    global init_task
    global message_listering
    click, x_click, y_click = buff
    border_col, background_content, text_col, header_col = theme[theme_active]
    x, y, width = 0, 349 - height, 349

    for el in data_property:
        if el[0] == 'button' and el[6] == 'Start':
            if not init_task:
                el[2], el[3], el[4], el[5] = x + 2, y + 2, 50, height - 4
                init_task = True
            else:
                if click:
                    if el[2] < x_click < el[2] + el[4] and el[
                            3] < y_click < el[3] + el[5]:
                        message_listering.append(
                            ['start_menu', '', 'enable_focus'])
                        buff[0] = False

    canvas.fill_style('SlateGray')
    canvas.fill_rect(x, y - 2, width, height)
    canvas.fill_style(border_col)
    canvas.fill_rect(x, y, width, height)

    time_ = dt.datetime.now()
    time_str = time_.strftime("%H:%M")
    day_str = time_.strftime("%d")
    canvas.fill_style('Black')
    canvas.fill_text(time_str, x + 320, y + 20, 'Tahoma', 14, 'center')
Example #4
0
def create_object():
    canvas.fill_style('LightskyBlue')
    canvas.fill_rect(0, 0, 349, 349)
    canvas.fill_style('CornflowerBlue')
    canvas.fill_text('Windows Py',
                     175,
                     50,
                     font='Tahoma',
                     size=42,
                     align='center')
    global stack
    el_focus = -1
    if data_property:
        for index, el in enumerate(data_property, 0):
            if el[0] == 'window' and el[7]:
                el_focus = index
            if el[0] == 'button' and el[1]:
                obj, show, x, y, width, height, caption, press = el
                button(x, y, width, height, caption, press)
            elif el[0] == 'window' and el[1]:
                obj, show, x, y, width, height, caption, focus = el
                window(x, y, width, height, caption, focus, index)
            elif el[0] == 'taskbar' and el[1]:
                obj, show, height = el
                taskbar(height)
            elif el[0] == 'start_menu' and el[1]:
                obj, show, x, y, width, height, non, focus = el
                start_menu(x, y, width, height, focus)
        if el_focus >= 0 and data_property[el_focus][1]:
            obj, show, x, y, width, height, caption, focus = data_property[
                el_focus]
            window(x, y, width, height, caption, focus, el_focus)
def draw():
  
  global bits, out
  canvas.fill_rect(0,0,500,500)
  left = 80
  top = 30
  canvas.draw_line((0,30+top),(500,30+top),4,'Blue')  
  cl2 = 'Yellow'
  
  canvas.draw_text("ENTREES",(left-30,25+top),24,cl2)
  canvas.draw_text("SORTIES",(left+250,25+top),24,cl2)
  canvas.draw_circle((left, 50+top), 10, 2, 'Blue', color(str(bits['A'])))
  canvas.draw_circle((left, 73+top), 10, 2, 'Blue', color(str(bits['B'])))
  canvas.draw_circle((left, 96+top), 10, 2, 'Blue', color(str(bits['C'])))

  canvas.draw_circle((left+170, 50+top), 10, 2, 'Blue', color(out))
  
  canvas.draw_text("A: "+str(bits['A']),(left+15,58+top),24,cl2)
  canvas.draw_text("B: "+str(bits['B']),(left+15,80+top),24,cl2)
  canvas.draw_text("C: "+str(bits['C']),(left+15,102+top),24,cl2)
  canvas.draw_text(inp.get_text(),(left+185,58+top),24,cl2)
  
  """
  A FAIRE:
  
  Dessiner avec draw_circle et draw_line les interrupteurs
  et les faire basculer et eteindre quand les entrees changent
  
  """
  #dessin des fils
  canvas.draw_line((0,290+top),(100,290+top),3,'Blue')
  canvas.draw_line((150,290+top),(200,290+top),3,'Blue')
  canvas.draw_line((200,230+top),(200,350+top),3,'Blue')
  canvas.draw_line((200,230+top),(250,230+top),3,'Blue')
  canvas.draw_line((200,350+top),(250,350+top),3,'Blue')
  canvas.draw_line((300,230+top),(350,230+top),3,'Red')
  canvas.draw_line((300,350+top),(350,350+top),3,'Red')
  canvas.draw_line((350,230+top),(350,350+top),3,'Red')
  canvas.draw_line((500,290+top),(350,290+top),3,'Red') 
  canvas.draw_circle((420, 290+top), 30, 2, 'Blue', color(out))
  
  canvas.draw_text("A",(115,270+top),24,cl2)
  canvas.draw_text("B",(267,210+top),24,cl2)
  canvas.draw_text("C",(267,330+top),24,cl2)
  #dessin des interrupteurs
  
  if bits['A'] == 0:
    canvas.draw_line((100,290+top),(150,270+top),3,'Orange')
  else:
    canvas.draw_line((100,290+top),(150,290+top),3,'Orange')
  if bits['B'] == 0:
    canvas.draw_line((250,230+top),(300,230+top),3,'Orange')
  else:
    canvas.draw_line((250,230+top),(300,210+top),3,'Orange')
  if bits['C'] == 0:
    canvas.draw_line((250,350+top),(300,350+top),3,'Orange')
  else:
    canvas.draw_line((250,350+top),(300,330+top),3,'Orange')
def show_render(image):
    canvas.set_aa_enabled(False)
    canvas.set_size(image.width, image.height)

    for y, pixel in enumerate(image.pixels):
        for x, pixel in enumerate(image.pixels[y]):
            try:
                canvas.set_fill_color(pixel.x, pixel.y, pixel.z)
                canvas.fill_rect(x, y, 1, 1)
            except:
                pass
Example #7
0
def button(caption, x, y, width, height):
    canvas.fill_style('Black')
    canvas.fill_rect(x, y, width + 2, height + 2)  # Тень
    canvas.fill_style('PaleTurquoise')
    canvas.fill_rect(x, y, width, height)
    canvas.fill_style('Black')
    canvas.fill_text(caption, x + width / 2 + 1, y + width // 7 + 1, 'Tahoma',
                     width // 9, 'center')  # Тень
    canvas.fill_style('DarkGreen')
    canvas.fill_text(caption, x + width / 2, y + width // 7, 'Tahoma',
                     width // 9, 'center')
Example #8
0
def main():
	
	import canvas
	canvas.set_size(1000,1000)
	x=0
	y=0
	colors=distinct_colors(1,[(0,0,0),(1,1,1)])
	for c in colors:
		canvas.set_fill_color(*c)
		canvas.fill_rect(x,y,50,50)
		x=x+60
		if x>900:
			x=0
			y=y+60	
Example #9
0
def button(x, y, width=80, height=25, caption='OK', press=False):
    if not press:
        # рисование тени
        canvas.fill_style('Black')
        canvas.fill_rect(x + 1, y + 1, width, height)
    canvas.fill_style(theme[theme_active][0])
    canvas.fill_rect(x, y, width, height)
    canvas.fill_style('Black')
    canvas.fill_text(caption,
                     x + width / 2,
                     y + height * 0.7,
                     font='Tahoma',
                     size=12,
                     align='center')
Example #10
0
def draw_menu(x, y, width):
    canvas.clear()
    global MENU
    global initMenu
    height = width
    if initMenu:
        canvas.fill_style('Black')
        canvas.fill_rect(x, y, width + 2, height + 2)
        canvas.fill_style('Grey')
        canvas.fill_rect(x, y, width, height)
        for el in MENU:
            button(el[0], el[1], el[2], el[3], el[4])
    else:
        initMenu = True
        count = len(MENU)
        for i in range(count):
            MENU[i][1] = x + (width - width * 0.8) / 2
            MENU[i][2] = y + (i + 1) * height / (count +
                                                 1) - width * 0.8 * 0.2 / 2
            MENU[i][3] = width * 0.8
            MENU[i][4] = width * 0.8 * 0.2
Example #11
0
def message(caption, x, y, width):
    canvas.clear()
    height = width * 0.2
    canvas.fill_style('Black')
    canvas.fill_rect(x, y - height / 2, width + 2, height + 2)
    canvas.fill_style('Grey')
    canvas.fill_rect(x, y - height / 2, width, height)
    if caption == 'YOU WIN':
        color1 = 'DarkBlue'
        color2 = 'DeepSkyBlue'
    elif caption == 'YOU LOST':
        color1 = 'DarkRed'
        color2 = 'Red'
    else:
        color1 = 'Black'
        color2 = 'Green'
    canvas.fill_style(color1)
    canvas.fill_text(caption, x + width // 2 + 2, y + height * 0.3 + 2,
                     'Tahoma', width // 6, 'center')
    canvas.fill_style(color2)
    canvas.fill_text(caption, x + width // 2, y + height * 0.3, 'Tahoma',
                     width // 6, 'center')
	def render(self, scene, samples):
		width = scene.width
		height = scene.height
		canvas.set_size(width, height)
		aspect_ratio = float(width) / height
		x0 = -1.0
		x1 = +1.0
		xstep = (x1 - x0) / (width - 1)
		y0 = -1.0 / aspect_ratio
		y1 = +1.0 / aspect_ratio
		ystep = (y1 - y0) / (height - 1)
		
		camera = scene.camera
		pixels = Image(width, height)
		
		heightRange = list(range(height))
		widthRange = list(range(width))
		
		#random.shuffle(heightRange)
		#random.shuffle(widthRange)
		
		for j in heightRange:
			y = y0 + j * ystep
			for i in widthRange:
				x = x0 + i * xstep
				renderedSamples = []
				for _ in range(samples):
					if samples > 1:
						ray = Ray(camera, Point(x+random.uniform(xstep*-1,xstep),y+random.uniform(xstep*-1,ystep)) - camera)
					else:
						ray = Ray(camera, Point(x,y) - camera)
					raytracedColorSample = self.ray_trace(ray, scene)
					renderedSamples.append(raytracedColorSample)
				finalPixel = sum(renderedSamples, Color(0,0,0)) / len(renderedSamples)
				pixels.set_pixel(i, j, finalPixel)
				canvas.set_fill_color(finalPixel.x, finalPixel.y, finalPixel.z)
				canvas.fill_rect(i, j, 1, 1)
		return pixels
def draw():

    global bits, out
    canvas.fill_rect(0, 0, 500, 500)
    left = 80
    top = 30
    canvas.draw_line((0, 30 + top), (500, 30 + top), 4, "Blue")
    cl2 = "Yellow"

    canvas.draw_text("ENTREES", (left - 30, 25 + top), 24, cl2)
    canvas.draw_text("SORTIES", (left + 250, 25 + top), 24, cl2)
    canvas.draw_circle((left, 50 + top), 10, 2, "Blue", color(str(bits["A"])))
    canvas.draw_circle((left, 73 + top), 10, 2, "Blue", color(str(bits["B"])))
    canvas.draw_circle((left, 96 + top), 10, 2, "Blue", color(str(bits["C"])))

    canvas.draw_circle((left + 170, 50 + top), 10, 2, "Blue", color(out))

    canvas.draw_text("A: " + str(bits["A"]), (left + 15, 58 + top), 24, cl2)
    canvas.draw_text("B: " + str(bits["B"]), (left + 15, 80 + top), 24, cl2)
    canvas.draw_text("C: " + str(bits["C"]), (left + 15, 102 + top), 24, cl2)
    canvas.draw_text(inp.get_text(), (left + 185, 58 + top), 24, cl2)

    """
Example #14
0
def paint_draw():
    global paint_obj
    for el in paint_obj:
        if el[0] == 'point':
            canvas.fill_style(el[3])
            canvas.fill_circle(el[1], el[2], 2)
        if el[0] == 'line':
            canvas.set_color(el[5])
            canvas.move_to(el[1], el[2])
            canvas.line_to(el[3], el[4])
        if el[0] == 'rect':
            if el[6]:
                canvas.fill_style(el[5])
                canvas.fill_rect(el[1], el[2], el[3], el[4])
            else:
                canvas.set_color(el[5])
                canvas.stroke_rect(el[1], el[2], el[3], el[4])
        if el[0] == 'circle':
            if el[5]:
                canvas.fill_style(el[4])
                canvas.fill_circle(el[1], el[2], el[3])
            else:
                canvas.set_color(el[4])
                canvas.circle(el[1], el[2], el[3])
Example #15
0
def start_menu(x, y, width, height, focus):
    global buff
    global menu_icon
    global init_menu_icon
    global message_listering
    border_col, background_content, text_col, header_col = theme[theme_active]
    for el in data_property:
        if el[0] == 'start_menu' and el[1]:
            pass
    canvas.fill_style('Black')
    canvas.fill_rect(x, y, width + 1, height)
    canvas.fill_style(border_col)
    canvas.fill_rect(x, y, width, height)
    if not init_menu_icon:
        for index, el in enumerate(menu_icon, 0):
            el[1], el[2], el[3], el[
                4] = x + 2, y + 2 + 27 * index, width - 4, 25
        init_menu_icon = True
    else:
        click, x_click, y_click = buff
        for index, el in enumerate(menu_icon, 0):
            text, x_icon, y_icon, width_icon, height_icon = el
            canvas.fill_style('Silver')
            canvas.fill_rect(x_icon, y_icon, width_icon, height_icon)
            canvas.fill_style('Black')
            canvas.fill_text(text, x + 2 + width_icon / 2, y_icon + 17,
                             'Tahoma', 14, 'center')
            if click:
                if x_icon < x_click < x_icon + width_icon and y_icon < y_click < y_icon + height_icon:
                    if text == 'Paint':
                        message_listering.append(
                            ['window', 'Paint', 'enable_focus'])
                        message_listering.append(['start_menu', '', 'close'])
                    if text == 'Calculator':
                        message_listering.append(
                            ['window', 'Calc', 'enable_focus'])
                        message_listering.append(['start_menu', '', 'close'])
                    if text == 'XXX_Por':
                        message_listering.append(
                            ['XXX', 'XXX', 'enable_focus'])
                        message_listering.append(['start_menu', '', 'close'])
                else:
                    message_listering.append(['start_menu', '', 'close'])
Example #16
0
import math
import random
import canvas

f = 200
h = 0

canvas.set_size(f, f)
canvas.set_fill_color(1, 1, 1)
canvas.fill_rect(0, 0, f, f)

k = int(input('Number of dots: '))
for i in range(0, k):
    x = (random.randint(0, f) / f)
    y = (random.randint(0, f) / f)
    if math.sqrt(math.pow(x, 2) + math.pow(y, 2)) <= 1:
        h += 1
        canvas.set_fill_color(0, 1, 0)
        canvas.fill_pixel(x * f, y * f)
    else:
        canvas.set_fill_color(1, 0, 0)
        canvas.fill_pixel(x * f, y * f)

    if i % 5000 == 0:
        print(i)

print(h / k)
Example #17
0
def paint(x, y, width, height, focus):
    global init
    global data_property
    global buff  # Буфер (список) для передачи состояния мыши и координат
    global but  # Список кнопок панели управления
    global but_
    global fill_on
    canvas.fill_style(theme[theme_active][0])
    height_panel = 55
    canvas.fill_rect(x, y, width, height_panel)
    canvas.fill_style('Black')
    canvas.fill_text('Панель инструментов', x + width / 2, y + height / 12 / 2,
                     'Tahoma', 12, 'center')
    if not init:  # инициализация, выполняется один раз.
        x_but = x
        y_but = y + height / 6 - height / 10
        x_but_ = x
        y_but_ = y_but + height / 12 - 1 + 2
        count_button_ = 3
        count_button = 5
        button_text = ['Point', 'Line', 'Rect', 'Circle', 'Color']
        button_text_ = ['New', 'Fill OFF', 'Undo']
        for i in range(5):
            but.append([
                x_but + i * width / count_button, y_but, width / count_button,
                height / 12 - 1, button_text[i], False
            ])
            button(but[i][0], but[i][1], but[i][2], but[i][3], but[i][4],
                   but[i][5])
            if i < count_button_:
                but_.append([
                    x_but_ + i * width / count_button_, y_but_,
                    width / count_button_, height / 12 - 1, button_text_[i],
                    False
                ])
                button(but_[i][0], but_[i][1], but_[i][2], but_[i][3],
                       but_[i][4], but_[i][5])
        init = True
    else:
        # Если инициализация была выполнена, выполняется код ниже
        for index, el in enumerate(but, 0):
            x_butt, y_butt, width_butt, height_butt, caption_butt, press = el
            click, x_click, y_click = buff
            # Здесь идет расчет, чтобы была нажата только одна из кнопок верхнего ряда
            if click and x_butt + width_butt > x_click > x_butt and y_butt + height_butt > y_click > y_butt and focus:
                but[index][5] = True
                buff[0] = False
                for j in range(5):
                    if j != index:
                        but[j][5] = False

    click, x_click, y_click = buff
    for i in range(5):
        button(but[i][0], but[i][1], but[i][2], but[i][3], but[i][4],
               but[i][5])
        if i < len(but_):
            x_but, y_but, width_but, height_but, caption_but, press = but_[i]
            button(x_but, y_but, width_but, height_but, caption_but, press)
            if click:
                if x_but < x_click < x_but + width_but and y_but < y_click < y_but + height_but and focus:
                    if caption_but == 'New':
                        paint_obj.clear()
                    elif caption_but == 'Undo':
                        if paint_obj:
                            paint_obj.pop()
                    elif caption_but == 'Fill OFF':
                        but_[i][4] = 'Fill ON'
                        fill_on = True
                    elif caption_but == 'Fill ON':
                        but_[i][4] = 'Fill OFF'
                        fill_on = False
                    buff[0] = False

    paint_canvas(x, y + height_panel, width, height - height_panel, focus)
    paint_draw()
Example #18
0
 def fill_rect(self, x, y, width, height, color=(1, 1, 1)):
     #canvas.set_blend_mode(canvas.BLEND_CLEAR)
     canvas.set_fill_color(color)
     canvas.fill_rect(*self.xyWorld(x, y), *self.whWorld(width, height))
Example #19
0
import canvas

canvas.set_size(512, 512)

from_point = (10, 10)
cp1 = (40, 200)  #control point 1
cp2 = (350, 50)  #control point 2
to_point = (300, 300)

# Draw the actual curve:
canvas.begin_path()
canvas.move_to(from_point[0], from_point[1])
canvas.add_curve(cp1[0], cp1[1], cp2[0], cp2[1], to_point[0], to_point[1])
canvas.set_line_width(2)
canvas.draw_path()

# Draw the red dots and lines to illustrate what's happening:
canvas.set_stroke_color(1, 0, 0)
canvas.set_fill_color(1, 0, 0)

# Draw straight lines between the control points and the end points:
canvas.draw_line(from_point[0], from_point[1], cp1[0], cp1[1])
canvas.draw_line(to_point[0], to_point[1], cp2[0], cp2[1])

# Draw red squares on all the points:
canvas.fill_rect(from_point[0] - 4, from_point[1] - 4, 8, 8)
canvas.fill_rect(to_point[0] - 4, to_point[1] - 4, 8, 8)
canvas.fill_rect(cp1[0] - 4, cp1[1] - 4, 8, 8)
canvas.fill_rect(cp2[0] - 4, cp2[1] - 4, 8, 8)
Example #20
0
 def clear(self):
     x, y = self.xyWorld(*self.xyUser())
     w, h = self.whWorld(*self.whUser())
     canvas.set_fill_color(1, 1, 1)
     canvas.fill_rect(x, y, w, h)
Example #21
0
def window(x, y, width, height, caption, focus, target):
    global data_property
    global buff
    global stack
    global message_listering
    border_col, background_content, text_col, header_col = theme[theme_active]
    border = 3
    height_caption = 20
    margin_text = 5
    canvas.fill_style('Black')
    canvas.fill_rect(x + 1, y + 1, width, height)  # Тень окна
    canvas.fill_style(border_col)
    canvas.fill_rect(x, y, width, height)  # Основное окно
    if focus:
        canvas.fill_style(header_col)
    else:
        canvas.fill_style('Grey')
    canvas.fill_rect(x + border, y + border, width - border * 2,
                     height_caption)  # Окно шапки
    canvas.fill_style('Black')
    canvas.fill_text(caption, x + border + margin_text + 1,
                     y + border + 15 + 1, 'Tahoma', 14,
                     'left')  # тень текста шапки
    canvas.fill_style(text_col)
    canvas.fill_text(caption, x + border + margin_text, y + border + 15,
                     'Tahoma', 14, 'left')  # текст шапки
    canvas.fill_style(background_content)
    canvas.fill_rect(x + border, y + border * 2 + height_caption,
                     width - border * 2, height - border * 3 -
                     height_caption)  # фон окна, контента

    x_but_close = x + width - margin_text - 14 + 1
    y_but_close = y + 6
    canvas.fill_style('Black')
    canvas.fill_rect(x_but_close + 1, y_but_close + 1, 14, 14)
    canvas.fill_style('DarkGray')
    canvas.fill_rect(x_but_close, y_but_close, 14, 14)
    canvas.set_color('Black')
    canvas.line_width(2)
    canvas.radius_line(x_but_close + 2, y_but_close + 2, 135, 13)
    canvas.radius_line(x_but_close + 2 + 9, y_but_close + 2, 225, 13)

    # Реализацию вызовов нужных функций можно переделать с использованием передачи параметра-функции, возможно доработаю в следующих версиях

    if data_property[target][6] == 'Paint':
        paint(x + border, y + border * 2 + height_caption, width - border * 2,
              height - border * 3 - height_caption, focus)
    if data_property[target][6] == 'Color':
        paint_color_window(x + border, y + border * 2 + height_caption,
                           width - border * 2,
                           height - border * 3 - height_caption, focus)
    if data_property[target][6] == 'Calc':
        calc(x + border, y + border * 2 + height_caption, width - border * 2,
             height - border * 3 - height_caption, focus)

    # Обработчик закрытия окна
    click, x_click, y_click = buff
    if click:
        if x_but_close + 14 > x_click > x_but_close and y_but_close + 14 > y_click > y_but_close:
            message_listering.append(['window', caption, 'close'])
            buff[0] = False

    if click and not focus:
        if x < x_click < x + width and y < y_click < y + height_caption:
            message_listering.append(['window', caption, 'enable_focus'])
            buff[0] = False
Example #22
0
canvasWidth = canvasHeight = 500
canvas.set_size(canvasWidth, canvasHeight)

x = 10
y = 10
w = 50
h = 50
r = b = g = 1.0

for i in range(8):
    for j in range(8):
        r -= 0.01
        b = 0.0
        g = 0.0
        canvas.set_fill_color(r, b, g)
        canvas.fill_rect(x, y, w, h)
        y += 60
    x += 60
    y = 10

x = 15
y = 15
w = 40
h = 40

colors = [(0.545, 0.271, 0.075), (0.545, 0.000, 0.000), (1.000, 0.647, 0.000),
          (0.933, 0.910, 0.667), (0.000, 0.392, 0.000), (0.529, 0.808, 0.922),
          (000, 0.000, 0.545)]

for i in range(8):
    for j in range(8):
Example #23
0
        randomIntY = random.randrange(0, 40)
        randomColor = random.random()
        x = randomIntX
        y = randomIntY
        canvas.set_fill_color(randomColor, randomColor, randomColor, 0.2)
        canvas.fill_ellipse(x, y, 4, 4)
    canvas.restore_gstate()
canvas.end_updates()

#overlaping rectangles in circle
for i in range(12):
    canvas.save_gstate()
    canvas.set_fill_color(0.4, 0.4, 0.8, 0.1)
    canvas.translate(250, 250)
    canvas.rotate(-2 * pi / 12.0 * i)
    canvas.fill_rect(0, 0, 40, 40)
    canvas.restore_gstate()

#fanning-out
canvas.set_stroke_color(0.3, 0.3, 0.3, 0.6)
originX = w / 2
originY = h / 2

for i in range(1, 500, 5):
    x1 = originX
    y1 = originY
    x2 = i
    y2 = 0
    canvas.draw_line(x1, y1, x2, y2)

for i in range(1, 500, 5):
Example #24
0
    y2 = 0
    canvas.draw_line(x1, y1, x2, y2)

for i in range(1, 500, 5):
    x1 = originX
    y1 = originY
    x2 = i
    y2 = canvas.get_size()[0]
    canvas.draw_line(x1, y1, x2, y2)

canvas.set_fill_color(0, 0.7, 0)

for i in range(40, 460, 20):
    x = i + 5
    y = originY - 5
    canvas.fill_rect(x, y, 10, 10)

for i in range(40, 460, 20):
    x = originX - 5
    y = i + 5
    canvas.fill_rect(x, y, 10, 10)

canvas.set_fill_color(0.5, 0, 0, 0.5)

for i in range(12):
    canvas.save_gstate()
    canvas.set_fill_color(0.4, 0.4, 0.8, 0.4)
    canvas.translate(250, 250)
    canvas.rotate(-2 * pi / 12.0 * i)
    canvas.fill_rect(0, 0, 120, 120)
    canvas.restore_gstate()
Example #25
0
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):
	end_x, end_y = lollipop_points[x]
# l_89
import time
print(time.asctime())

import math
print(math.atanh(0.5))

# l_91
# import canvas
# canvas.stroke_rect(50,50,100,100)
# canvas.fill_rect(80,80,50,50)
# canvas.draw()

import canvas
canvas.fill_rect(50, 50, 50, 50)
canvas.stroke_rect(150, 150, 100, 100)
canvas.draw()

# l_93
import canvas
import time
x = 0
delta = 2
while True:
    x < 350
    canvas.clear()
    canvas.fill_rect(x, 100, 50, 50)
    canvas.draw()
    time.sleep(0.01)
    x = x + delta
Example #27
0
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)


def rstrokedline(start_x, start_y, end_x, end_y):
    line_width = random.random() * 0.75 + 0.25
    canvas.set_line_width(line_width)
    a = random.random() * 0.25 + 0.05
Example #28
0
# https://gist.github.com/omz/5087533

import canvas

canvas.set_size(512, 512)

from_point = (10, 10)
cp1 = (40, 200) #control point 1
cp2 = (350, 50) #control point 2
to_point = (300, 300)

# Draw the actual curve:
canvas.begin_path()
canvas.move_to(from_point[0], from_point[1])
canvas.add_curve(cp1[0], cp1[1], cp2[0], cp2[1], to_point[0], to_point[1])
canvas.set_line_width(2)
canvas.draw_path()

# Draw the red dots and lines to illustrate what's happening:
canvas.set_stroke_color(1, 0, 0)
canvas.set_fill_color(1, 0, 0)

# Draw straight lines between the control points and the end points:
canvas.draw_line(from_point[0], from_point[1], cp1[0], cp1[1])
canvas.draw_line(to_point[0], to_point[1], cp2[0], cp2[1])

# Draw red squares on all the points:
canvas.fill_rect(from_point[0]-4, from_point[1]-4, 8, 8)
canvas.fill_rect(to_point[0]-4, to_point[1]-4, 8, 8)
canvas.fill_rect(cp1[0]-4, cp1[1]-4, 8, 8)
canvas.fill_rect(cp2[0]-4, cp2[1]-4, 8, 8)