gridcalc.py

Created by lastfuture

Created on October 18, 2018

739 Bytes

Calculations for creating Layouts with columns. Find out how wide your columns or your gutters have to be to fit your layout. If the result isn’t an integer rounded solutions will be provided


from math import *

def gutters(cols=3, colwidth=410, fullwidth=1280):
  _c2(fullwidth, colwidth, cols, True)
  
def cols(cols=3, gutterwidth=25, fullwidth=1280):
  _c2(fullwidth, gutterwidth, cols, False)

def golden(gw=25, fw=1280):
  c1 = fw/2.618033926
  c2 = round(fw-c1-(gw/2))
  c1 = round(c1-(gw/2))
  print([gw, fw])
  print([c1, c2])
  
def _c(a, b, c, d, z):
  if z:
    return (a-(b*c))/d
  else:
    return (a-(b*d))/c

def _c2(w, x, y, z):
  y = ceil(y)
  v = y-1
  x_ = x
  u1 = u2 = _c(w, x, y, v, z)
  while u1 % 1:
    x += 1
    u1 = _c(w, x, y, v, z)
  print([y, x, w])
  print(u1)
  if u1 != u2:
    x = x_
    while u2 % 1:
      x -= 1
      u2 = _c(w, x, y, v, z)
    print([y, x, w])
    print(u2)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.