Diese Datei stammt aus Wikimedia Commons und kann von anderen Projekten verwendet werden. Die Beschreibung von deren Dateibeschreibungsseite wird unten angezeigt.
A lattice of the non-negative integers partially ordered by divisibility; each number is connected to its divisors in the row below. Re-working of File:Infinite lattice of divisors.svg
Ich, der Urheberrechtsinhaber dieses Werkes, veröffentliche es als gemeinfrei. Dies gilt weltweit. In manchen Staaten könnte dies rechtlich nicht möglich sein. Sofern dies der Fall ist: Ich gewähre jedem das bedingungslose Recht, dieses Werk für jedweden Zweck zu nutzen, es sei denn, Bedingungen sind gesetzlich erforderlich.
importmathdefcreate_lattice_svg():# --- Configuration ---# SVG dimensions.row_height=95node_spacing=77node_radius=20# --- Lattice Data ---# Define the numbers for each row of the lattice based on number of prime factors.# The key (0-4) serves as both the number of factors and the row identifier.lattice_data={4:[0],# The top node (0)3:[8,12,18,20,27],# Numbers with three prime factors2:[4,6,9,10,14],# Numbers with two prime factors1:[2,3,5,7],# Prime numbers0:[1]# The number 1 (zero factors)}# --- Create a list of node objects with positions ---nodes=[]# Determine the widest row to calculate total SVG width.max_nodes_per_row=0forrowinlattice_data.values():iflen(row)>max_nodes_per_row:max_nodes_per_row=len(row)# Adjust for ellipsis nodemax_nodes_per_row+=1# Calculate total SVG dimensions with padding.width=max_nodes_per_row*node_spacingnum_rows=len(lattice_data)height=num_rows*row_height# Build the nodes list and calculate their positions.row_keys=sorted(lattice_data.keys(),reverse=True)fori,num_factorsinenumerate(row_keys):numbers=sorted(lattice_data[num_factors])# Ellipses are added to rows that aren't the top or bottomhas_ellipsis=num_factorsnotin[0,4]# Calculate the y-position for the current row, from the top down.y_pos=row_height*i+row_height/2# Calculate x-positions to center the numbers in the row.num_nodes_in_row=len(numbers)+(1ifhas_ellipsiselse0)half_width=width/2half_node_span=((num_nodes_in_row-1)/2)*node_spacingstart_x=half_width-half_node_spanforj,numberinenumerate(numbers):x_pos=start_x+j*node_spacingnode={'value':number,'type':'number','num_factors':num_factors,'x_pos':x_pos,'y_pos':y_pos}nodes.append(node)# Add positions for ellipsis nodes.ifhas_ellipsis:ellipsis_x_pos=start_x+len(numbers)*node_spacingellipsis_y_pos=y_posellipsis_node={'value':'···','type':'ellipsis','num_factors':num_factors,'x_pos':ellipsis_x_pos,'y_pos':ellipsis_y_pos}nodes.append(ellipsis_node)# --- Start the SVG string with the header and styles ---svg_string=f'''<svg width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg"> <defs> <style type="text/css"> .solid-line {{ fill: none; stroke: #000000; stroke-width: 1.5; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; stroke-opacity: 1; stroke-dasharray: none; stroke-dashoffset: 0;}} .dotted-line {{ fill: none; stroke: #000000; stroke-width: 1.5; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; stroke-opacity: 1; stroke-dasharray: 1.5, 4.5; stroke-dashoffset: 0;}} .node-circle {{ fill: #ffffff; fill-opacity: 1; fill-rule: evenodd; stroke: none;}} .node-text {{ font-size: 30px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; text-indent: 0; text-align: start; text-decoration: none; line-height: normal; letter-spacing: normal; word-spacing: normal; text-transform: none; direction: ltr; block-progression: tb; writing-mode: lr-tb; text-anchor: middle; dominant-baseline: middle; color: #000000; fill: #000000; fill-opacity: 1; fill-rule: nonzero; stroke: none; stroke-width: 1px; marker: none; visibility: visible; display: inline; overflow: visible; enable-background: accumulate; font-family: Liberation Serif, Times New Roman, serif;}} </style> </defs>'''# Painting order: lines first, then circles, then text on top. This is the order in which we add elements to the SVG string.# --- Step 1: Draw all Lattice Lines ---forparent_nodeinnodes:forchild_nodeinnodes:# Skip if they are the same nodeifparent_node==child_node:continue# Only connect nodes that are one level apart in terms of prime factorsifparent_node['num_factors']!=child_node['num_factors']+1:continuex1,y1=parent_node['x_pos'],parent_node['y_pos']x2,y2=child_node['x_pos'],child_node['y_pos']line_class=None# Solid lines between numbers based on divisibilityif(parent_node['type']=='number'andchild_node['type']=='number'andparent_node['value']%child_node['value']==0):line_class="solid-line"# Dotted lines from numbers/ellipsis in the row below to the ellipsisif(parent_node['type']=='ellipsis'):line_class="dotted-line"# Dotted lines from 0 to the top rowif(parent_node['value']==0andchild_node['num_factors']==3):line_class="dotted-line"# If a condition is met, draw the lineifline_class:# Adjust start and end points of lines to meet the circle edges.dy=y2-y1dx=x2-x1angle=math.atan2(dy,dx)x1_adj=x1+node_radius*math.cos(angle)y1_adj=y1+node_radius*math.sin(angle)x2_adj=x2-node_radius*math.cos(angle)y2_adj=y2-node_radius*math.sin(angle)svg_string+=f''' <line x1="{x1_adj}" y1="{y1_adj}" x2="{x2_adj}" y2="{y2_adj}" class="{line_class}" />'''# --- Step 2: Draw all Lattice Nodes ---# actually, it looks better without the circles, they just cut off the lines#for node in nodes:# svg_string += f'''#<circle cx="{node['x_pos']}" cy="{node['y_pos']}" r="{node_radius}" class="node-circle" />'''# --- Step 3: Draw all Lattice Node Text --- fornodeinnodes:text_content=node['value']svg_string+=f''' <text x="{node['x_pos']}" y="{node['y_pos']}" dy="0.1em" class="node-text">{text_content}</text>'''# --- Close the SVG tag ---svg_string+="\n</svg>"returnsvg_stringif__name__=="__main__":svg_code=create_lattice_svg()# Write the SVG string to a filefile_path="divisibility_lattice.svg"withopen(file_path,"w")asf:f.write(svg_code)print(f"SVG file generated successfully at: {file_path}")
Lizenz
Ich, der Urheber dieses Werkes, veröffentliche es unter der folgenden Lizenz:
Die Person, die das Werk mit diesem Dokument verbunden hat, übergibt dieses weltweit der Gemeinfreiheit, indem sie alle Urheberrechte und damit verbundenen weiteren Rechte – im Rahmen der jeweils geltenden gesetzlichen Bestimmungen – aufgibt. Das Werk kann – selbst für kommerzielle Zwecke – kopiert, modifiziert und weiterverteilt werden, ohne hierfür um Erlaubnis bitten zu müssen.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse
Kurzbeschreibungen
Ergänze eine einzeilige Erklärung, was diese Datei darstellt.
Diese Datei enthält weitere Informationen, die in der Regel von der Digitalkamera oder dem verwendeten Scanner stammen. Durch nachträgliche Bearbeitung der Originaldatei können einige Details verändert worden sein.