File:Apollonian gasket symmetrical 3.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file(SVG file, nominally 202 × 202 pixels, file size: 316 KB)

Summary

Description
English: A radially-symmetric Apollonian gasket rendered using the algorithm at http://codegolf.stackexchange.com/questions/38450/draw-an-apollonian-gasket by CMG Lee.
Date
Source Own work
Author Cmglee
Other versions
Sorry, this SVG file is solely a source for re-utilization, editing or printing purposes. Please do not use this graphic within Wikipedia articles! MediaWiki isn't able to render this image correctly. Some details may be missing or look wrong. When you include the image in a Wikipedia or any other Wikimedia project site's page, you may want to use the other file, until the support increases.

File:Apollonian gasket symmetrical 3.svg File:Apollonian gasket symmetrical 3.png

Deutsch  English  español  italiano  日本語  한국어  македонски  português do Brasil  русский  sicilianu  slovenščina  简体中文  繁體中文  +/−

{{{svgImageLabel}}}

SVG development
InfoField
 
The SVG code is valid.
 
This diagram was created with Python.
Source code
InfoField

Python code

#Please retain this and other comments, which contain Python code to generate this SVG. """

import re, math, colorsys

def fmt(string): ## string.format(**vars()) using tags {expression!format} by CMG Lee
 def f(tag): i_sep = tag.rfind('!'); return (re.sub('\.0+$', '', str(eval(tag[1:-1])))
  if (i_sep < 0) else ('{:%s}' % tag[i_sep + 1:-1]).format(eval(tag[1:i_sep])))
 return (re.sub(r'(?<!{){[^{}]+}', lambda m:f(m.group()), string)
         .replace('{{', '{').replace('}}', '}'))
def append(obj, string): return obj.append(fmt(string))
def tabbify(cellss, separator='|'):
 cellpadss = [list(rows) + [''] * (len(max(cellss, key=len)) - len(rows)) for rows in cellss]
 fmts = ['%%%ds' % (max([len(str(cell)) for cell in cols])) for cols in zip(*cellpadss)]
 return '\n'.join([separator.join(fmts) % tuple(rows) for rows in cellpadss])

def draw(circles):
 radius = abs(scale / circles[0])
 # radius += 20 if (radius == size) else -20
 if (radius > 0):
  colour = '#%06x' % (0xffffff * ((radius / size + 0.65) % 1))
  # colour = '#%02x%02x%02x' % tuple(
   # [int(255 * component) for component in colorsys.hsv_to_rgb((radius / size) ** 0.75, 1, 1)])
  # luma = 0xff * (radius / size) ** 0.25; colour = '#%02x%02x%02x' % (0, 0xff - luma * 3 // 4, luma)
  # out_mains.append('''<circles cx="%.0f" cy="%.0f" r="%.0f" stroke="%s"/>''' %
   # (scale * circles[1] / circles[0], scale * circles[2] / circles[0], radius, colour))
  # out_mains.append('''<use xlink:href="#s" transform="translate(%.0f,%.0f) scale(%.0f)"/>''' %
   # (scale * circles[1] / circles[0], scale * circles[2] / circles[0], radius))
  out_mains.append(
   '''<use xlink:href="#s" transform="translate(%.0f,%.0f) scale(%.0f)" fill="%s"/>''' %
   (scale * circles[1] / circles[0], scale * circles[2] / circles[0], radius, colour))

def distance(point1s,point2s):
 return ((point1s[0] - point2s[0]) ** 2 + (point1s[1] - point2s[1]) ** 2) ** 0.5

# centress = [[0,-17/15.*32], [-16/17.*32, 161/255.*32], [18/17.*33,48/85.*33]]
centress = [[math.sin(math.radians(angle * 120)),math.cos(math.radians(angle * 120))]
            for angle in range(3)]
(centre0s, centre1s, centre2s) = centress
d01 = distance(centre0s,centre1s)
d12 = distance(centre1s,centre2s)
d20 = distance(centre2s,centre0s)
(k0, k1, k2) = ((d01 - d12 + d20) / 2, (d01 + d12 - d20) / 2, (-d01 + d20 + d12) / 2)
k3 = k0 + k1 + k2 - 2 * (k0 * k1 + k1 * k2 + k2 * k0) ** 0.5
circless = [[k3,0.,0.],                         [k0,centre0s[0]/k0,centre0s[1]/k0],
            [k1,centre1s[0]/k1,centre1s[1]/k1], [k2,centre2s[0]/k2,centre2s[1]/k2]]
# circless = [[-6.,0.,0.], [10.,2/3.,0.], [15.,-3/2.,0.], [19.,-5/6.,2.]]
# circless = [[-15.,0.,0.], [32.,0.,-17/15.], [32.,-16/17.,161/255.], [33.,18/17.,48/85.]]
print(circless)
size     = 10000
scale    = -size * circless[0][0]
queue    = []
(out_defs, out_mains) = ([], [])

# append(out_mains, '''  <g fill="none" stroke="#000000" stroke-width="{size / 1000.}">''')
append(out_mains, '''  <g stroke="none">''')
for circles in circless:
 queue.append(circless)
 draw(circless[0])
 circless = circless[1:] + [circless[0]]
while (len(queue) > 0):
 circless = queue[0]
 circles  = [2 * (circless[0][i] + circless[1][i] + circless[2][i]) - circless[3][i]
             for i in range(3)]
 if (circles[0] < scale / 20):
  for i in range(6, 0, -2):
   queue.append([circless[i % 3], circless[(i - 1) % 3], circles, circless[(i - 2) % 3]])
 draw(circles)
 queue = queue[1:]
append(out_mains, '''  </g>''')

(x, width) = (-1.01 * size, 2.02 * size)
out_p      = fmt('''width="100%" height="100%" viewBox="{x} {x} {width} {width}"''')

## Compile everything into an .svg file
myself   = open(__file__, 'r').read() ## the contents of this very file
file_out = open(__file__[:__file__.rfind('.')] + '.svg', 'wb') ## *.* -> *.svg
try: ## use try/finally so that file is closed even if write fails
 file_out.write('''<?xml version="1.0" encoding="utf-8"?><!%s%s
%s%s%s\n%s%s\n%s%s''' % ('-', '-', ## because SVG comments cannot have 2 consecutive '-'s
  myself[:myself.find('width',myself.find('<svg'))], ## assume width specified before height/viewBox
  out_p, ## replace SVG width/height/viewBox with {out_p} & dynamic SVG blocks with {out*s} contents
  myself[myself.find ('>',myself.find('<svg')):
         myself.find ('\n',myself.find('BEGIN_'+'DYNAMIC_DEFS'))], '\n'.join(out_defs),
  myself[myself.rfind('\n',0,myself.find('END_'+'DYNAMIC_DEFS')):
         myself.find ('\n',myself.find('BEGIN_'+'DYNAMIC_MAIN'))], '\n'.join(out_mains),
  myself[myself.rfind('\n',0,myself.find('END_'+'DYNAMIC_MAIN')):]))
finally:
 file_out.close()

## SVG-Python near-polyglot framework version 3 by CMG Lee (March 2018)

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Captions

A radially-symmetric Apollonian gasket rendered using the algorithm at http://codegolf.stackexchange.com/questions/38450/draw-an-apollonian-gasket by CMG Lee.

Items portrayed in this file

depicts

30 March 2019

image/svg+xml

6403925ea4dd41ff9dd19c5fd9d83595f154d43b

323,643 byte

202 pixel

202 pixel

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current06:28, 23 June 2019Thumbnail for version as of 06:28, 23 June 2019202 × 202 (316 KB)JoKalliauerSorry User:Cmglee I had removed comments and desc and title, I now reinsered them, if there is still something missing, revert it or reupload it, also several defs seems to be not needed such as: 1) <filter id="filter_outline"> 2) <radialGradient id="grad" 3)<circles id="c" 4) <ellipse cx="0" cy="-45" rx="70" ry="50" fill="url(#grad_highlight)" fill-opacity="0.75"/>
20:27, 22 June 2019Thumbnail for version as of 20:27, 22 June 2019202 × 202 (311 KB)JoKalliaueren:Wikipedia:SVG_help#Server_error_when_generating_SVG_thumbnail deledted invalid line <circles id="c" r="1" fill="url(#grad)" stroke="none"/>, there is no plural, reduced preview-size
00:33, 1 April 2019Thumbnail for version as of 00:33, 1 April 2019512 × 512 (330 KB)CmgleeColour by radius.
00:03, 1 April 2019Thumbnail for version as of 00:03, 1 April 2019512 × 512 (330 KB)CmgleeFix symmetry.
11:01, 30 March 2019Thumbnail for version as of 11:01, 30 March 2019512 × 512 (330 KB)CmgleeUse File:Kugelball.svg shading.
09:23, 30 March 2019Thumbnail for version as of 09:23, 30 March 2019512 × 512 (270 KB)CmgleeUser created page with UploadWizard
The following pages on the English Wikipedia use this file (pages on other projects are not listed):

Metadata