Commit 7b4526ca by Einar Andersen

worked on more typographic layouts

parent bc483e5b
This source diff could not be displayed because it is too large. You can view the blob instead.
# -*- coding: utf-8 -*-
import random
import math
import json
from chiplotle import *
from chiplotle.hpgl import commands
##################
## VIRTUAL ##
##################
from chiplotle.tools.plottertools import instantiate_virtual_plotter
plotter = instantiate_virtual_plotter(type="DPX330")
plotter.margins.hard.draw_outline()
plotter.select_pen(1)
##################
## HARDWARE ##
##################
# plotter = instantiate_plotters( )[0]
# plotter.select_pen(1)
################
def mm(amount):
return amount * 40
def cm(amount):
return amount * 400
def units_to_cm(amount):
return amount / 400.0
def title(input_text):
input_text = input_text.upper()
line_height = ((3*y_unit)/(2*y_unit*2))-1
if " " in input_text:
formatted_text = input_text.replace(" ", "\r\n")
input_text = formatted_text
title = shapes.group([])
movement = 0
for i in range(4):
title_text = shapes.label(input_text, units_to_cm(0.8 * x_unit), units_to_cm(2 * y_unit),0.2,line_height)
transforms.center_at(title_text, (movement,0))
title.append(title_text)
movement += mm(0.8)
return title
def header(input_text):
input_text = input_text.upper()
header_text = shapes.label(input_text, units_to_cm(0.5 * x_unit), units_to_cm(0.3 * y_unit), -0.1, 0.4)
return header_text
def body(input_text, text_box, char_width, char_height, line_height):
text = input_text
fixed_text = ""
width_counter = 0
line_spacing = ((line_height)/(char_height * 2.0))-1.0
line_h = (line_height - (2.0 * char_height))/char_height
print(line_spacing, line_h)
for word in text.split(" "):
word = word + " "
if width_counter + len(word) * (char_width + char_width * 0.25) < text_box:
fixed_text += word
width_counter += len(word) * (char_width + char_width * 0.25)
else:
fixed_text += "\r\n" + word
width_counter = 0
width_counter += len(word) * (char_width + char_width * 0.25)
body_text = shapes.label(fixed_text, units_to_cm(char_width), units_to_cm(char_height), -0.1, line_h)
return body_text
def list_body(input_text, text_box, char_width, char_height, line_height):
text = input_text
indent = " "
fixed_text = ""
line_spacing = ((line_height)/(char_height * 2.0))-1.0
for line in text.split('"newline"'):
width_counter = 0
sentence = line.split(": ")
identifier = sentence[0].upper()
content = indent + sentence[1]
if len(identifier + content) * (char_width + char_width * 0.25) > text_box:
fixed_content = ""
width_counter = len(identifier) * (char_width + char_width * 0.25)
for word in content.split(" "):
word = word + " "
if width_counter + len(word) * (char_width + char_width * 0.25) < text_box:
fixed_content += word
width_counter += len(word) * (char_width + char_width * 0.25)
else:
fixed_content += "\r\n" + indent + word
width_counter = 0
width_counter += len(word) * (char_width + char_width * 0.25)
content = fixed_content
fixed_text += identifier + ":"
fixed_text += content + "\r\n"
list_body_text = shapes.label(fixed_text, units_to_cm(char_width), units_to_cm(char_height), -0.1, line_spacing)
return list_body_text
with open("formatted_content.json", "r") as read_file:
content = json.load(read_file)
plotter.set_origin_bottom_left()
width = plotter.margins.hard.width
height = plotter.margins.hard.height
print(width)
print(height)
x_unit = width/3.0/3.0/8.0
y_unit = height/2.0/3.0/8.0
print(x_unit)
print(y_unit)
x_movement = 2 * (32*x_unit)
y_movement = 0
base_x = 0
base_y = 0
### PAGE 1 ###
title_input = content[0]["title"].encode("latin-1")
b_header = content[0]["b_header"].encode("latin-1")
p_header = content[0]["p_header"].encode("latin-1")
b_body = content[0]["b_body"].encode("latin-1")
p_body = content[0]["p_body"].encode("latin-1")
text = content[0]["main"].encode("latin-1")
list_text = content[0]["list_info"].encode("latin-1")
spirulina_page = shapes.group([])
title_plot = title(title_input)
transforms.offset(title_plot, (2*x_unit, 21*y_unit))
bio_header = header(b_header)
pig_header = header(p_header)
transforms.offset(bio_header, (3 * x_unit, 20*y_unit))
transforms.offset(pig_header, (14 * x_unit, 19*y_unit))
bio_body = body(b_body, 10*x_unit, 0.28 * x_unit, 0.28 * y_unit, 0.5 * y_unit)
pig_body = body(p_body, 10*x_unit, 0.28 * x_unit, 0.28 * y_unit, 0.5 * y_unit)
transforms.offset(bio_body, (3 * x_unit, 19*y_unit))
transforms.offset(pig_body, (14 * x_unit, 18*y_unit))
main_text = body(text, 11*x_unit, 0.25 * x_unit, 0.3 * y_unit, 0.5 * y_unit)
transforms.offset(main_text, ( 1 * x_unit, 12 * y_unit))
list_txt = list_body(list_text, 10 * x_unit, 0.25 * x_unit, 0.3 * y_unit, 0.5 * y_unit)
transforms.offset(list_txt, ( 13 * x_unit, 8 * y_unit))
spirulina_page.append(title_plot)
spirulina_page.append(bio_header)
spirulina_page.append(pig_header)
spirulina_page.append(bio_body)
spirulina_page.append(pig_body)
spirulina_page.append(main_text)
spirulina_page.append(list_txt)
plotter.write(spirulina_page)
##############
base_x = 24
base_y = 0
# ### PAGE 2 ###
# title_input = content[1]["title"].encode("latin-1")
# b_header = content[1]["b_header"].encode("latin-1")
# p_header = content[1]["p_header"].encode("latin-1")
# b_body = content[1]["b_body"].encode("latin-1")
# p_body = content[1]["p_body"].encode("latin-1")
# text = content[1]["main"].encode("latin-1")
# list_text = content[1]["list_info"].encode("latin-1")
# nannochloropsis_page = shapes.group([])
# title_plot = title(title_input)
# transforms.offset(title_plot, ((base_x + 2) * x_unit, (base_y + 21) * y_unit))
# bio_header = header(b_header)
# pig_header = header(p_header)
# transforms.offset(bio_header, ((base_x + 3) * x_unit, (base_y + 20) * y_unit))
# transforms.offset(pig_header, ((base_x + 14) * x_unit, (base_y + 19) * y_unit))
# bio_body = body(b_body, 10*x_unit, 0.3 * x_unit, 0.3 * y_unit)
# pig_body = body(p_body, 10*x_unit, 0.3 * x_unit, 0.3 * y_unit)
# transforms.offset(bio_body, ((base_x + 3) * x_unit, (base_y + 19)*y_unit))
# transforms.offset(pig_body, ((base_x + 14) * x_unit, (base_y + 18)*y_unit))
# main_text = body(text, 11*x_unit, 0.25 * x_unit, 0.3 * y_unit)
# transforms.offset(main_text, ((base_x + 1) * x_unit, (base_y + 12) * y_unit))
# list_txt = list_body(list_text, 10 * x_unit, 0.25 * x_unit, 0.3 * y_unit)
# transforms.offset(list_txt, ((base_x + 13) * x_unit, (base_y + 14) * y_unit))
# nannochloropsis_page.append(title_plot)
# nannochloropsis_page.append(bio_header)
# nannochloropsis_page.append(pig_header)
# nannochloropsis_page.append(bio_body)
# nannochloropsis_page.append(pig_body)
# nannochloropsis_page.append(main_text)
# nannochloropsis_page.append(list_txt)
# plotter.write(nannochloropsis_page)
# ##############
# base_x = 48
# base_y = 0
# ### PAGE 3 ###
# title_input = content[2]["title"].encode("latin-1")
# b_header = content[2]["b_header"].encode("latin-1")
# p_header = content[2]["p_header"].encode("latin-1")
# b_body = content[2]["b_body"].encode("latin-1")
# p_body = content[2]["p_body"].encode("latin-1")
# text = content[2]["main"].encode("latin-1")
# list_text = content[2]["list_info"].encode("latin-1")
# dunaliella_page = shapes.group([])
# title_plot = title(title_input)
# transforms.offset(title_plot, ((base_x + 2) * x_unit, (base_y + 21) * y_unit))
# bio_header = header(b_header)
# pig_header = header(p_header)
# transforms.offset(bio_header, ((base_x + 3) * x_unit, (base_y + 20) * y_unit))
# transforms.offset(pig_header, ((base_x + 14) * x_unit, (base_y + 20) * y_unit))
# bio_body = body(b_body, 10*x_unit, 0.3 * x_unit, 0.3 * y_unit)
# pig_body = body(p_body, 10*x_unit, 0.3 * x_unit, 0.3 * y_unit)
# transforms.offset(bio_body, ((base_x + 3) * x_unit, (base_y + 19)*y_unit))
# transforms.offset(pig_body, ((base_x + 14) * x_unit, (base_y + 19)*y_unit))
# main_text = body(text, 11*x_unit, 0.25 * x_unit, 0.3 * y_unit)
# transforms.offset(main_text, ((base_x + 1) * x_unit, (base_y + 16) * y_unit))
# list_txt = list_body(list_text, 10 * x_unit, 0.25 * x_unit, 0.3 * y_unit)
# transforms.offset(list_txt, ((base_x + 13) * x_unit, (base_y + 7) * y_unit))
# dunaliella_page.append(title_plot)
# dunaliella_page.append(bio_header)
# dunaliella_page.append(pig_header)
# dunaliella_page.append(bio_body)
# dunaliella_page.append(pig_body)
# dunaliella_page.append(main_text)
# dunaliella_page.append(list_txt)
# plotter.write(dunaliella_page)
# ### PAGE 4 ###
# ### PAGE 5 ###
# ### PAGE 6 ###
plotter.select_pen(0)
io.view(plotter)
......@@ -9,15 +9,29 @@ plotter = instantiate_virtual_plotter(type="HP7576A")
plotter.margins.hard.draw_outline()
plotter.select_pen(1)
# text = shapes.label("hello humans", 2, 2)
textgroup = shapes.group([])
text = hpgl.LB("Hello")
textgroup.append(text)
# # text = shapes.label("hello humans", 2, 2)
# textgroup = shapes.group([])
# text = hpgl.LB("Hello")
# textgroup.append(text)
plotter.write(hpgl.SL(math.tan(20)))
plotter.write(textgroup)
# plotter.write(hpgl.SL(math.tan(20)))
# plotter.write(textgroup)
# plotter.write(shapes.label("hello", 2,2))
# plotter.write(text)
# # plotter.write(shapes.label("hello", 2,2))
# # plotter.write(text)
# for i in range(1, 11):
char_height = 2
des = 2.73
line_height = ((des)/(char_height*2.0))-1.0
print line_height
text = shapes.label("HELLO\n\rHELLO\n\rHELLO\n\rHELLO\n\rHELLO\n\rHELLO\n\r", 1, char_height, 0, line_height)
# transforms.center_at(text, (i * 5000, 2000))
plotter.write(text)
# for i in range(11):
# text = shapes.label("HELLO\n\rHELLO\n\rHELLO\n\rHELLO\n\rHELLO\n\rHELLO\n\r", 1, 2.5, 0, i * 0.1)
# transforms.center_at(text, (i * 5000, 2000))
# plotter.write(text)
io.view(plotter)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment