Created
March 29, 2013 09:15
-
-
Save scardine/5269738 to your computer and use it in GitHub Desktop.
Exemplo de pycairo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cairo | |
pol = 72.0 | |
mm = pol / 25.4 | |
surface = cairo.PDFSurface('teste.pdf', 210*mm, 297*mm) | |
ctx = cairo.Context(surface) | |
ctx.set_source_rgb (0, 0, 0) | |
# Linha do horizonte | |
ctx.move_to(0, 40*mm) | |
ctx.line_to(210*mm, 40*mm) | |
# Parede 1 | |
def desenha_casinha(x, y, tam): | |
ctx.move_to(x, y) | |
ctx.rel_line_to(0, -tam) | |
ctx.rel_line_to(0.5*tam, -0.5*tam) | |
ctx.rel_line_to(0.5*tam, 0.5*tam) | |
ctx.rel_line_to(0, tam) | |
# Parede 2 | |
ctx.move_to(x+0.5*tam, y-1.5*tam) | |
ctx.line_to(x+2.5*tam, y-1.5*tam) | |
ctx.line_to(x+3*tam, y-tam) | |
ctx.line_to(x+3*tam, y) | |
ctx.stroke() | |
x = 20 | |
for i in range(4): | |
desenha_casinha(x*mm, 40*mm, 5*mm) | |
x = x + 30 | |
def retangulo(x, y, largura, altura): | |
ctx.set_source_rgb (1, 0, 0) | |
ctx.rectangle(x*mm, y*mm, largura*mm, altura*mm) | |
ctx.stroke() | |
retangulo(10, 10, 50, 25) | |
retangulo(10, 10, 25, 50) | |
retangulo(10, 10, 50, 50) | |
ctx.move_to(20*mm, 20*mm) | |
ctx.select_font_face('Times New Roman', cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) | |
ctx.set_font_size(72) | |
ctx.show_text('Nancy eu te Amo!') | |
ctx.stroke() | |
ctx.show_page() | |
surface.finish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment