Learning Python

Learning Python III

27.05.2019

Heute habe ich mich mit der Lineal-Aufgabe bei pythonfordesigners.com von Roberto Arista beschäftigt.

Screenshot of pythonfordesigners.com/how-to-make-choices/#workbook

Mein Lineal sieht so aus:

Und hier ist mein Code dazu:

page_width = 100
page_height = page_width / 2

newPage(page_width, page_height)

line_count = 0
distance_corner = 10
ruler_height = 5

line_start_x = distance_corner
line_start_y = page_height - distance_corner
line_end_x = distance_corner
line_end_y = page_height - distance_corner - ruler_height

font("Arial", 3)

while line_count < page_width - distance_corner * 2 + 1:
・・・・stroke(0)
・・・・if line_count % 5:
・・・・・・・・strokeWidth(0.1)
・・・・・・・・line_end_y = line_start_y - ruler_height
・・・・elif line_count % 10:
・・・・・・・・strokeWidth(0.2)
・・・・・・・・line_end_y = line_start_y - ruler_height - 2
・・・・else:
・・・・・・・・strokeWidth(0.5)
・・・・・・・・line_end_y = line_start_y - ruler_height - 4
・・・・・・・・number = line_start_x - distance_corner
・・・・・・・・text("%s" % number, (line_end_x, line_end_y  - 4), align = "center")

・・・・line((line_start_x, line_start_y), (line_end_x, line_end_y))
    
・・・・line_count += 1
・・・・line_start_x += 1
・・・・line_end_x += 1