February 21, 2022 )

## 不可變動的變數

``````my_text = "Hello, OpenSCAD!";
step_angle = 30;
height = 5;
``````

OpenSCAD is a Functional programming language, as such variables are bound to expressions and keep a single value during their entire lifetime due to the requirements of referential transparency.

``````x = 1;
echo(x); // 顯示 2
x = 2;
echo(x); // 顯示 2
``````

## for 迴圈

``````for (a =[3:5]) {
echo(a);
}
``````

``````for (a =[1, 2, 3]) {
echo(a);     // 逐一顯示 1 2 3
}

for (c = "abc") {
echo(c);      // 逐一顯示  a b c
}
``````

``````sum = 0;
for (a =[0:5]) {
sum = sum + 1;
echo(sum);
}
``````

## 內建 2D 模組

`text` 參數沒有問題，就是你要指定的文字，不好打出來的特殊字元，也可以使用 Unicode 碼指定，例如：

``````text("\u20AC 10 \u263A");
`````` `size` 參數預設是 10，單位是 mm，至於 `font`字型名稱，如果要建立中文，原始碼 .scad 檔案要是 UTF-8 編碼，而 `font` 指定中文字型，例如，來個「標楷體」的「春」字：

``````text("春", font = "標楷體");
`````` ## 擠出（extrude）

``````linear_extrude(10)
text("春", font = "標楷體");
``````

`linear_extrude(10)` 之後不用分號，這類輔助某個模組的操作，後頭都是接上某個完成操作的模組。這會建立以下的 3D 模型： ## 轉換（transformation）

``````translate([-5, -5, -5])
linear_extrude(10)
text("春", font = "標楷體");
`````` ``````rotate([90, 0, 0])
translate([-5, -5, -5])
linear_extrude(10)
text("春", font = "標楷體");
``````
{"ft_lang_label":"__label__zh","ft_lang_prob":0.91946924,"math_prob":0.99420553,"size":3888,"snap":"2022-27-2022-33","text_gpt3_token_len":3038,"char_repetition_ratio":0.12409887,"word_repetition_ratio":0.043879908,"special_character_ratio":0.26800412,"punctuation_ratio":0.0907781,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9768018,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12],"im_url_duplicate_count":[null,1,null,1,null,1,null,1,null,1,null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-09T20:43:00Z\",\"WARC-Record-ID\":\"<urn:uuid:03e4f290-f6f3-4525-9bd3-22cc742c909a>\",\"Content-Length\":\"38097\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:dd963f4a-ad56-4498-a2e4-af0aa340fb82>\",\"WARC-Concurrent-To\":\"<urn:uuid:6297c51a-7815-4541-9785-0803977d5e62>\",\"WARC-IP-Address\":\"203.98.64.6\",\"WARC-Target-URI\":\"https://openhome.cc/zh-tw/openscad/basics/cheatsheet/\",\"WARC-Payload-Digest\":\"sha1:EM5MJRZIYAX5SMDFG5CUGIYWZ45HSDLR\",\"WARC-Block-Digest\":\"sha1:VCL4AS3TPXPKNTQQVP5GQTO6HNTFRA6Y\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882571086.77_warc_CC-MAIN-20220809185452-20220809215452-00260.warc.gz\"}"}