Natürlich, ich habe deinen Code neu geordnet, um die Lesbarkeit und Struktur zu verbessern, ohne dabei Zahlen, Variablen oder Namen zu ändern. Die Module und Funktionen sind jetzt logisch gruppiert und der Hauptteil des Programms befindet sich am Ende.
$fn = 70;
// ==========================
// Funktionen
// ==========================
function addiere_hoehen(hoehe1, hoehe2) = hoehe1 + hoehe2;
function berechne_laenge(lange1, lange2) = lange1 + lange2;
function berechne_hoehe(hoehe1, hoehe2) = hoehe1 + hoehe2;
// ==========================
// Module
// ==========================
// --- Schwebebahn-Form ---
module schwebebahn_form()
{
color([0, 146/255, 255/255]) // Farbe Schwebebahn
hull()
{
translate([-60, 0, 100])
cylinder(h=30, r=15);
translate([45, 0, 100])
cylinder(h=30, r=5);
translate([-70, -10, 100])
cylinder(h=30, r=5);
translate([-70, 10, 100])
cylinder(h=30, r=5);
translate([55, -10, 100])
cylinder(h=30, r=5);
translate([55, 10, 100])
cylinder(h=30, r=5);
}
}
// --- Auto ---
module auto() {
translate([0, 0, 0]) {
modifizierte_kiste([60, 20, 10]);
}
translate([5, 0, addiere_hoehen(10, 14)]) {
modifizierte_kiste([berechne_laenge(29, 1), 20, berechne_hoehe(12, 2)]);
}
}
module modifizierte_kiste(dimensions) {
cube(dimensions, center=true);
}
// --- Straßen und Fahrbahnen ---
module strasse()
{
color([0.584,0.584,0.584,0.8])
translate([-500,-100,-7])
cube([1000,200,1]);
}
module fahrbahn()
{
translate([-490,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn2()
{
translate([-440,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn3()
{
translate([-390,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn4()
{
translate([-340,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn5()
{
translate([-290,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn6()
{
translate([-240,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn7()
{
translate([-190,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn8()
{
translate([-140,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn9()
{
translate([-90,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn10()
{
translate([-40,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn11()
{
translate([10,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn12()
{
translate([60,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn13()
{
translate([110,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn14()
{
translate([160,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn15()
{
translate([210,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn16()
{
translate([260,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn17()
{
translate([310,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn18()
{
translate([360,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn19()
{
translate([410,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
module fahrbahn20 ()
{
translate([460,0,0])
color([1, 1, 1, 1])
{
cube([20, 5, 0.1]);
}
}
// --- Sauule ---
module sauule ()
{
difference ()
{
hull()
{
sphere(d = 20);
translate([-15,0,0]) sphere(d=20);
}
translate([-25,-11,0]) cube([40,22,11]);
}
}
module sauuule ()
{
union()
{
hull()
{
cylinder(h = 30, r = 5);
translate([0,0,35]) sphere(5);
hull()
{
translate([5,0,35]) rotate([0,90,0]) cylinder(h = 20, r = 5);
translate([0,0,35]) sphere(5);
}
}
}
}
// --- Wuppertaler Schwebebahn ---
module stuetze() {
// Vertikale Stütze
cube([10, 10, 100]);
// Erste diagonale Strebe
rotate([0, 0, 45])
translate([0, -5, 50])
cube([5, 10, 100]);
// Zweite diagonale Strebe
rotate([0, 0, -45])
translate([-5, -5, 50])
cube([5, 10, 100]);
}
module schienentraeger() {
// Schienenträger
cube([1000, 20, 10]);
}
module zug() {
// Zug
cube([80, 25, 30]);
}
module schwebebahn() {
// Erzeugen der Stützen entlang der Bahn
for (i = [0 : 200 : 1000]) {
translate([i, 0, 0])
stuetze();
}
// Erzeugen des Schienenträgers
translate([0, -10, 100])
schienentraeger();
// Erzeugen und Positionieren des Zuges unter dem Schienenträger
translate([460, 0, -25])
zug();
}
// --- Haus ---
basis_breite = 40; // X
basis_tiefe = 30; // Y
basis_hoehe = 20; // Z
wand_dicke = 1;
dach_hoehe = 15; // Z
kokel_groesse = 6; // X, Y
gras_versatz = 8; // X, Y Offset
gras_hoehe = 5; // Z
module haus() {
gras();
translate([gras_versatz, gras_versatz, gras_hoehe]) {
basis();
translate([0, 0, basis_hoehe]) dach();
translate([basis_breite * 0.8, basis_tiefe * 0.7, basis_hoehe + 1]) kokel();
}
}
module basis() {
// Hauskörper ohne Fenster und Tür
color("orange")
cube([basis_breite, basis_tiefe, basis_hoehe]);
translate([wand_dicke, wand_dicke, 0])
cube([basis_breite - 2 * wand_dicke, basis_tiefe - 2 * wand_dicke, basis_hoehe]);
}
module dach() {
punkte = [
[0, 0, 0],
[basis_breite, 0, 0],
[basis_breite, basis_tiefe, 0],
[0, basis_tiefe, 0], // Basis Ecken
[basis_breite / 2, 0, dach_hoehe],
[basis_breite / 2, basis_tiefe, dach_hoehe] // Dachecken
];
flachen = [
[0, 1, 2, 3], // Basis
[3, 4, 0], // Linkes Dreieck
[1, 5, 2], // Rechtes Dreieck
[4, 5, 1, 0], // Vorderseite
[5, 4, 3, 2] // Rückseite
];
color("dunkelrot")
polyhedron(points = punkte, faces = flachen, convexity = 10);
}
module kokel() {
color("grau")
cube([kokel_groesse, kokel_groesse, dach_hoehe * 0.75]);
}
module gras(){
color("grün")
rcube([basis_breite + 2 * gras_versatz, basis_tiefe + 2 * gras_versatz, gras_hoehe], gras_versatz);
}
module rcube(groesse, radius) {
if (radius < 1) {
cube(groesse);
} else {
hull() {
translate([radius, radius]) cylinder(r = radius, h = groesse[2]);
translate([groesse[0] - radius, radius]) cylinder(r = radius, h = groesse[2]);
translate([groesse[0] - radius, groesse[1] - radius]) cylinder(r = radius, h = groesse[2]);
translate([radius, groesse[1] - radius]) cylinder(r = radius, h = groesse[2]);
}
}
}
// ==========================
// Hauptprogramm und Aufrufe
// ==========================
// Nummer der Schwebebahn
color([1, 0, 0])
translate([-75,-6,105])
rotate([90,0,270])
text("28", size=5, valign="center", halign="center");
// Erstellen der Schwebebahn
schwebebahn();
// Straß- und Fahrbahnen
strasse();
fahrbahn();
fahrbahn2();
fahrbahn3();
fahrbahn4();
fahrbahn5();
fahrbahn6();
fahrbahn7();
fahrbahn8();
fahrbahn9();
fahrbahn10();
fahrbahn11();
fahrbahn12();
fahrbahn13();
fahrbahn14();
fahrbahn15();
fahrbahn16();
fahrbahn17();
fahrbahn18();
fahrbahn19();
fahrbahn20();
// Sauule
sauuule();
sauule();
// Autos
translate([-0, 90, 0])
{
color([1, 0, 0])
{
auto();
}
}
translate([-80, 90, 0])
{
color([174/255, 235/255, 20/255])
{
auto();
}
}
translate([80, 90, 0]) {
color([0,0,0])
{
auto();
}
}
translate([-0, -90, 0])
{
color([1, 0, 0])
{
auto();
}
}
translate([-80, -90, 0])
{
color([174/255, 235/255, 20/255])
{
auto();
}
}
translate([80, -90, 0]) {
color([0,0,0])
{
auto();
}
}
// Haus
haus();
Änderungen und Verbesserungen:
-
Gruppierung der Funktionen und Module:
- Funktionen (
addiere_hoehen, berechne_laenge, berechne_hoehe) sind zu Beginn gruppiert.
- Module sind nach ihrer Funktionalität gruppiert, z.B. alle Fahrbahn-Module zusammen, Schwebebahn-Module zusammen, Haus-Module zusammen.
-
Kommentierung:
- Zusätzliche Kommentare wurden hinzugefügt und bestehende wurden strukturiert, um die Verständlichkeit zu erhöhen.
-
Formatierung:
- Einheitliche Einrückungen und Leerzeilen zur besseren Lesbarkeit.
- Konsistente Verwendung von Klammern und Leerzeichen.
-
Konsolidierung ähnlicher Module:
- Obwohl die
fahrbahn-Module ähnlich sind, wurden sie beibehalten, da eine Eigenständigkeit gewünscht war. Eine weitere Konsolidierung würde Namensänderungen erfordern, was vermieden wurde.
Diese Struktur sollte es erleichtern, den Code zu verstehen und zu warten, während alle ursprünglichen Bezeichnungen und Werte unverändert bleiben.