User:VulcanWikiEdit/sandbox/expanding Code Example
Appearance
From Wikibooks, open books for an open world
This is the table form of an expanding code block
Exercise Modify this script to improve its readability and to not repeat common math operations. Add two new variables named half_wheelbase and half_track. Use the corresponding mathematical calculation to set these variables equal to half the value of the wheelbase and the track variables accordingly. Replace the repeating mathematical operations in the translation commands with the use of these two variables.
Code
car_with_additional_variables.scad
use <vehicle_parts.scad> $fa = 1; $fs = 0.4; wheelbase = 40; track = 35; half_wheelbase = wheelbase/2; half_track = track/2; // Body body(); // Front left wheel translate([-half_wheelbase,-half_track,0]) simple_wheel(); // Front right wheel translate([-half_wheelbase,half_track,0]) simple_wheel(); // Rear left wheel translate([half_wheelbase,-half_track,0]) simple_wheel(); // Rear right wheel translate([half_wheelbase,half_track,0]) simple_wheel(); // Front axle translate([-half_wheelbase,0,0]) axle(track=track); // Rear axle translate([half_wheelbase,0,0]) axle(track=track);