Warning, /frameworks/syntax-highlighting/autotests/input/highlight.scad is written in an unsupported language. File is not indexed.

0001 /*Basic test file
0002 Written by Julian Stirling, 2018
0003 License: MIT*/
0004 
0005 // This is a comment
0006 x=5;
0007 y=6;
0008 z=5;
0009 r=2;
0010 for (n = [-1.5:1:1.5]){
0011     translate([n*x,0,0]){cubehole([x,y,z],r);}
0012 }
0013 
0014 module cubehole(size,holerad)
0015 {
0016     $fn=28;
0017     difference()
0018     {
0019         cube(size,center=true);
0020         cylinder(size[2]+1,r=holerad,center=true);
0021     }
0022 }
0023 
0024 // some examples adapted from https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/General
0025 cube(5);
0026 x = 4 + y;
0027 rotate(40) square(5,10);
0028 translate([10, 5]) {
0029     circle(5);
0030     square(4);
0031 }
0032 rotate(60) color("red") {
0033     circle(5);
0034     square(4);
0035 }
0036 color("blue") {
0037     translate([5, 3, 0]) sphere(5);
0038     rotate([45, 0, 45]) {
0039         cylinder(10);
0040         cube([5, 6, 7]);
0041     }
0042 }
0043 
0044 aNumber = 42;
0045 aBoolean = true;
0046 anotherBoolean = false;
0047 aString = "foo";
0048 aRange = [0: 1: 10];
0049 aVector = [1, 2, 3];
0050 aUndef = undef;
0051 moreNumbers = [-1, 42, 0.5, 2.99792458e+8, 1.337e3, 314e-2];
0052 echo(moreNumbers)
0053 echo("The quick brown fox \tjumps \"over\" the lazy dog.\rThe quick brown fox.\nThe \\lazy\\ dog. \x21 \u03a9 \U01F98A \U01f43e");
0054 
0055 vector1 = [1,2,3]; vector2 = [4]; vector3 = [5,6];
0056 new_vector = concat(vector1, vector2, vector3); // [1,2,3,4,5,6]
0057 
0058 string_vector = concat("abc","def");                 // ["abc", "def"]
0059 one_string = str(string_vector[0],string_vector[1]); // "abcdef"
0060 
0061 a = [1,2,3]; echo(len(a));   //  3
0062 
0063 // Example which defines a 2D rotation matrix
0064 mr = [
0065     [cos(angle), -sin(angle)],
0066     [sin(angle),  cos(angle)]
0067 ];
0068 
0069 // modifiers
0070 % cube([10, 10, 10]);  // background
0071 # cube([10, 10, 10]);  // debug
0072 ! cube([10, 10, 10]);  // root
0073 * cube([10, 10, 10]);  // disable
0074 
0075 // if example taken from https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Rounding_examples
0076 if(a==b){
0077     echo ("a==b");
0078 }else if(a>b){
0079     echo ("a>b");
0080 }else if(a<b){
0081     echo ("a<b");
0082 }else{
0083     echo ("???");
0084 }
0085 
0086 // assert example taken from https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#assert
0087 module row(cnt = 3){
0088     // Count has to be a positive integer greater 0
0089     assert(cnt > 0);
0090     for (i = [1 : cnt]) {
0091         translate([i * 2, 0, 0]) sphere();
0092     }
0093 }
0094 row(0);