<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>รถยนต์ Archives - KarnLab</title>
	<atom:link href="https://karnlab.com/tag/%e0%b8%a3%e0%b8%96%e0%b8%a2%e0%b8%99%e0%b8%95%e0%b9%8c/feed/" rel="self" type="application/rss+xml" />
	<link>https://karnlab.com/tag/รถยนต์/</link>
	<description>Blog รีวิว หนังสือ เขียนโปรแกรม นานาสาระ</description>
	<lastBuildDate>Mon, 01 Oct 2018 11:56:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://karnlab.com/wp-content/uploads/2017/12/Logo-150x150.png</url>
	<title>รถยนต์ Archives - KarnLab</title>
	<link>https://karnlab.com/tag/รถยนต์/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>วาดรูปด้วยภาษาโลโก้ : ตอนที่ 16 – รถยนต์</title>
		<link>https://karnlab.com/logo-tutorial-ep16-car/</link>
					<comments>https://karnlab.com/logo-tutorial-ep16-car/#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Mon, 01 Oct 2018 11:56:46 +0000</pubDate>
				<category><![CDATA[สอนเขียนโปรแกรม]]></category>
		<category><![CDATA[LOGO]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ภาษาโลโก้]]></category>
		<category><![CDATA[รถยนต์]]></category>
		<category><![CDATA[วาดรูป]]></category>
		<category><![CDATA[เขียนโปรแกรม]]></category>
		<guid isPermaLink="false">http://karnlab.com/?p=1296</guid>

					<description><![CDATA[<p>สวัสดีครับ วันนี้เราจะมาวาดรูปรถยนต์ ด้วยภาษาโลโก้กันครับ โดยในตอนนี้เราจะดูแบบที่ต้องการวาดก่อน แล้วค่อยๆ วาดรูปไปพร้อมๆ กันครับ ระหว่างวาดรูปอาจจะมีข้อผิดพลาดบ้าง แต่เราจะแก้ไขข้อผิดพลาดนั้นได้อย่างไร มาติดตามกันดูได้เลยครับ คำสั่งที่น้องๆ จะเจอในบทนี้ คำสั่ง ความสามารถ ตัวอย่าง fd ระยะทาง bk ระยะทาง forward [&#8230;]</p>
<p>The post <a href="https://karnlab.com/logo-tutorial-ep16-car/">วาดรูปด้วยภาษาโลโก้ : ตอนที่ 16 – รถยนต์</a> appeared first on <a href="https://karnlab.com">KarnLab</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>สวัสดีครับ วันนี้เราจะมาวาดรูปรถยนต์ ด้วยภาษาโลโก้กันครับ โดยในตอนนี้เราจะดูแบบที่ต้องการวาดก่อน แล้วค่อยๆ วาดรูปไปพร้อมๆ กันครับ ระหว่างวาดรูปอาจจะมีข้อผิดพลาดบ้าง แต่เราจะแก้ไขข้อผิดพลาดนั้นได้อย่างไร มาติดตามกันดูได้เลยครับ</p>
<p>คำสั่งที่น้องๆ จะเจอในบทนี้</p>
<table>
<tbody>
<tr>
<td width="198"><strong>คำสั่ง</strong></td>
<td width="227"><strong>ความสามารถ</strong></td>
<td width="227"><strong>ตัวอย่าง</strong></td>
</tr>
<tr>
<td width="198">fd ระยะทาง<br />
bk ระยะทาง</td>
<td width="227">forward = เดินหน้า<br />
backward = ถอยหลัง</td>
<td width="227">fd 100 = เดินหน้า 100 pixel<br />
bk 50 = ถอยหลัง 50 pixel</td>
</tr>
<tr>
<td width="198">rt องศา<br />
lt องศา</td>
<td width="227">right turn = หมุนขวา<br />
left turn = หมุนซ้าย</td>
<td width="227">rt 90 = หมุนไปทางขวา 90 องศา<br />
lt 45 = หมุนไปทางซ้าย 45 องศา</td>
</tr>
<tr>
<td width="198">repeat จำนวนครั้ง [ คำสั่ง ]</td>
<td width="227">repeat = ทำคำสั่งต่อไปนี้ ซ้ำ n ครั้ง</td>
<td width="227">repeat 3 [ fd 100 rt 120 ]<br />
repeat 4 [ fd 100 rt 90 ]<br />
repeat 6 [ fd 100 rt 60 ]</td>
</tr>
<tr>
<td width="198">TO ชื่อฟังก์ชัน :ตัวแปร<br />
คำสั่ง<br />
END</td>
<td width="227">function = สร้างชุดคำสั่ง</td>
<td width="227">TO square :size<br />
repeat 4 [ fd :size rt 90 ]<br />
END</td>
</tr>
<tr>
<td width="198">cs<br />
clean</td>
<td width="227">clear screen = ล้างหน้าจอ<br />
clean = ล้างหน้าจอ</td>
<td width="227"></td>
</tr>
<tr>
<td width="198">pu<br />
pd</td>
<td width="227">pen up = ยกปากกา<br />
pen down = วางปากกา</td>
<td width="227"></td>
</tr>
<tr>
<td width="198">ht<br />
st</td>
<td width="227">hide turtle = ซ่อนเต่าโลโก้<br />
show turtle = แสดงเต่าโลโก้</td>
<td width="227"></td>
</tr>
<tr>
<td width="198">setxy พิกัดx พิกัดy</td>
<td width="227">set (x,y) = กำหนดตำแหน่งเต่าโลโก้</td>
<td width="227">setxy 200 100</td>
</tr>
<tr>
<td width="198">setpensize ขนาด<br />
setpencolor รหัสสี<br />
fill<br />
setscreencolor รหัสสี</td>
<td width="227">set pen size = กำหนดขนาดปากกา<br />
set pen color = กำหนดสีปากกา<br />
fill = ระบายสี<br />
set screen color = กำหนดสีพื้นหลัง</td>
<td width="227">setpensize 5<br />
setpencolor 10<br />
fill<br />
setscreencolor 10</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>เราจะมาดูรูปต้นแบบที่เราจะวาดกันก่อนครับ ซึ่งก็คือ Mini Cooper สีแดง เดี๋ยวเราจะมาลองวาดกันดูเลยครับ</p>
<figure id="attachment_1248" aria-describedby="caption-attachment-1248" style="width: 726px" class="wp-caption alignnone"><img fetchpriority="high" decoding="async" class="size-full wp-image-1248" src="https://karnlab.com/wp-content/uploads/2018/10/Mini-Cooper-Red-Car.jpg" alt="Mini Cooper Red Car" width="726" height="545" /><figcaption id="caption-attachment-1248" class="wp-caption-text">Mini Cooper Red Car</figcaption></figure>
<p>รูปภาพจาก &#8211; <a href="https://bay2car.com/">https://bay2car.com/</a></p>
<p>&nbsp;</p>
<p>ก่อนอื่นเราจะเตรียมฟังก์ชันที่จะทำให้เราวาดรูปได้ง่ายขึ้นกันก่อนครับ</p>
<ol>
<li>ฟังก์ชัน setpencolor_default ใช้สำหรับเปลี่ยนสีปากการเป็นสีดำ</li>
<li>ฟังก์ชัน paint ใช้สำหรับระบายสี</li>
<li>ฟังก์ชัน comment ใช้สำหรับอธิบายการทำงานของโค้ด</li>
</ol>
<p>ฟังก์ชัน comment นี้น่าสนใจครับ ต้องอธิบายก่อนว่า ภาษาเขียนโปรแกรมโดยทั่วไปจะมีไวยกรณ์ (syntax) comment เพื่ออธิบายการทำงานของโค้ดเป็นภาษามนุษย์ ทำให้เวลาเรากลับมาอ่านโค้ดในภายหลัง เราก็จะเข้าใจได้ง่ายขึ้นว่าโค้ดส่วนนี้ทำหน้าที่อะไร</p>
<p>แต่เนื่องจากภาษาโลโก้ไม่มี syntax comment ดังนั้น เราก็เลยสร้างฟังก์ชัน comment เพื่อใช้เขียนอธิบายโค้ดครับ โดยในฟังก์ชันนี้ไม่ต้องทำอะไรครับ (ถ้ายังไม่เข้าใจ เดี๋ยวจะเห็นประโยชน์ของฟังก์ชันนี้ในตัวอย่างถัดไปครับ)</p>
<table>
<tbody>
<tr>
<td width="697">TO setpencolor_default<br />
setpencolor &#8220;#9E9E9E<br />
END</p>
<p>TO paint :color<br />
pu rt 45 fd 10 pd<br />
setpencolor :color fill<br />
pu bk 10 lt 45 pd<br />
setpencolor_default<br />
END</p>
<p>TO comment :message<br />
END</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>โอเคครับ เราจะมาเริ่มวาดรถยนต์กันเลยครับ</p>
<table>
<tbody>
<tr>
<td width="697">cs<br />
setpencolor_default<br />
pu setxy -200 -100 pd</p>
<p>comment &#8220;body<br />
fd 75<br />
rt 30 fd 100<br />
rt 60 fd 200<br />
rt 60 fd 100<br />
lt 60 fd 50<br />
rt 90 fd 75<br />
rt 90 fd 350<br />
rt 90<br />
paint &#8220;#d32f2f</td>
</tr>
</tbody>
</table>
<figure id="attachment_1249" aria-describedby="caption-attachment-1249" style="width: 459px" class="wp-caption alignnone"><img decoding="async" class="size-full wp-image-1249" src="https://karnlab.com/wp-content/uploads/2018/10/LOGO-EP16-Car-1.jpg" alt="LOGO EP16 - Car 1" width="459" height="262" /><figcaption id="caption-attachment-1249" class="wp-caption-text">LOGO EP16 &#8211; Car 1</figcaption></figure>
<p>* จะสังเกตว่า คำสั่ง comment “body ไม่ได้ทำหน้าที่วาดรูปอะไรเลยครับ แต่มันจะช่วยให้เข้าใจได้ง่ายขึ้นว่า โค้ดดังต่อไปนี้คือการวาดตัวรถยนต์ (body)</p>
<p>&nbsp;</p>
<p>จากนั้นเราจะวาดล้อรถยนต์กันครับ</p>
<table>
<tbody>
<tr>
<td width="697">comment &#8220;wheel_1<br />
pu rt 90 fd 120 rt 90 pd<br />
repeat 360 [ fd 0.75 rt 1 ]<br />
paint &#8220;#212121<br />
rt 90 fd 15 lt 90<br />
repeat 360 [ fd 0.5 rt 1 ]<br />
paint &#8220;#9E9E9E<br />
rt 90 bk 15 lt 90</td>
</tr>
</tbody>
</table>
<figure id="attachment_1250" aria-describedby="caption-attachment-1250" style="width: 442px" class="wp-caption alignnone"><img decoding="async" class="size-full wp-image-1250" src="https://karnlab.com/wp-content/uploads/2018/10/LOGO-EP16-Car-2.jpg" alt="LOGO EP16 - Car 2" width="442" height="273" /><figcaption id="caption-attachment-1250" class="wp-caption-text">LOGO EP16 &#8211; Car 2</figcaption></figure>
<p>&nbsp;</p>
<table>
<tbody>
<tr>
<td width="697">comment &#8220;wheel_2<br />
pu lt 90 fd 180 rt 90 pd<br />
repeat 360 [ fd 0.75 rt 1 ]<br />
paint &#8220;#212121<br />
rt 90 fd 15 lt 90<br />
repeat 360 [ fd 0.5 rt 1 ]<br />
paint &#8220;#9E9E9E<br />
rt 90 bk 15 lt 90</td>
</tr>
</tbody>
</table>
<figure id="attachment_1251" aria-describedby="caption-attachment-1251" style="width: 444px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-full wp-image-1251" src="https://karnlab.com/wp-content/uploads/2018/10/LOGO-EP16-Car-3.jpg" alt="LOGO EP16 - Car 3" width="444" height="275" /><figcaption id="caption-attachment-1251" class="wp-caption-text">LOGO EP16 &#8211; Car 3</figcaption></figure>
<p>&nbsp;</p>
<p>ต่อไปเราจะมาส่วนของหน้าต่างกันครับ</p>
<table>
<tbody>
<tr>
<td width="697">comment &#8220;window_1<br />
pu lt 90 bk 300 lt 90 pd<br />
pu fd 20 rt 90 fd 20 lt 90 pd<br />
pu fd 55 pd<br />
rt 30 fd 80<br />
rt 60 fd 100<br />
rt 90 fd 60<br />
rt 90 fd 120<br />
rt 120<br />
paint &#8220;#00bcd4</td>
</tr>
</tbody>
</table>
<figure id="attachment_1252" aria-describedby="caption-attachment-1252" style="width: 442px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-full wp-image-1252" src="https://karnlab.com/wp-content/uploads/2018/10/LOGO-EP16-Car-4.jpg" alt="LOGO EP16 - Car 4" width="442" height="269" /><figcaption id="caption-attachment-1252" class="wp-caption-text">LOGO EP16 &#8211; Car 4</figcaption></figure>
<p>&nbsp;</p>
<p>เอ๊ะ! เหมือนว่ารูปภาพที่ได้จะมีปัญหา เนื่องจากสัดส่วนของหน้าต่างไม่พอดี ลองแก้ไขโค้ดส่วนของหน้าต่างกันใหม่ครับ</p>
<table>
<tbody>
<tr>
<td width="697">comment &#8220;window_1<br />
pu lt 90 bk 300 lt 90 pd<br />
pu fd 20 rt 90 fd 20 lt 90 pd<br />
pu fd 55 pd<br />
rt 30 fd 80<br />
<strong>rt 60 fd 80</strong><br />
<strong>rt 90 fd 65</strong><br />
rt 90 fd 120<br />
rt 120<br />
paint &#8220;#00bcd4</td>
</tr>
</tbody>
</table>
<figure id="attachment_1253" aria-describedby="caption-attachment-1253" style="width: 443px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-full wp-image-1253" src="https://karnlab.com/wp-content/uploads/2018/10/LOGO-EP16-Car-5.jpg" alt="LOGO EP16 - Car 5" width="443" height="275" /><figcaption id="caption-attachment-1253" class="wp-caption-text">LOGO EP16 &#8211; Car 5</figcaption></figure>
<p>&nbsp;</p>
<p>เนื่องจากเราค่อยๆ เขียนโค้ด และทยอย run เพื่อดูรูปภาพไปทีและส่วน ดังนั้น เมื่อเกิดปัญหา เราจึงทราบว่าปัญหาเกิดจากจุดไหน และสามารถแก้ไขได้อย่างรวดเร็วครับ (ฝากถึงน้องๆ เช่นกันว่าเวลาเขียนโปรแกรมใหญ่ๆ ค่อยๆ code ค่อยๆ run นะครับ จะได้หา bug ได้ง่าย อย่าเขียน code ยาวๆ แล้ว run ทีเดียว มันจะหา bug ยาก)</p>
<p>ต่อไปเราจะวาดหน้าต่างที่เหลืออีกหนึ่งบานครับ</p>
<table>
<tbody>
<tr>
<td width="697">comment &#8220;window_2<br />
pu rt 60 fd 140 lt 90 pd<br />
fd 65<br />
rt 90 fd 80<br />
rt 60 fd 80<br />
rt 120 fd 120<br />
rt 90<br />
paint &#8220;#00bcd4</td>
</tr>
</tbody>
</table>
<figure id="attachment_1254" aria-describedby="caption-attachment-1254" style="width: 442px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-full wp-image-1254" src="https://karnlab.com/wp-content/uploads/2018/10/LOGO-EP16-Car-6.jpg" alt="LOGO EP16 - Car 6" width="442" height="282" /><figcaption id="caption-attachment-1254" class="wp-caption-text">LOGO EP16 &#8211; Car 6</figcaption></figure>
<p>&nbsp;</p>
<p>เอ๊ะ! รูปภาพที่ได้มีปัญหาอีกแล้ว แม้ดูเหมือนว่ารูปของเราไม่น่าจะมีอะไรผิดพลาด ถ้าเราสังเกตดีๆ จะพบว่าหน้าต่างที่เพิ่งเพิ่มเข้าไป สี่เหลี่ยมยังปิดไม่สนิท ดังนั้น ถ้าเราแก้ไขตัวเลขอีกนิดก็น่าจะพอดีแล้ว</p>
<table>
<tbody>
<tr>
<td width="697">comment &#8220;window_2<br />
pu rt 60 fd 140 lt 90 pd<br />
fd 65<br />
rt 90 fd 80<br />
rt 60 fd 75<br />
rt 120 fd 120<br />
rt 90<br />
paint &#8220;#00bcd4</td>
</tr>
</tbody>
</table>
<figure id="attachment_1255" aria-describedby="caption-attachment-1255" style="width: 440px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-full wp-image-1255" src="https://karnlab.com/wp-content/uploads/2018/10/LOGO-EP16-Car-7.jpg" alt="LOGO EP16 - Car 7" width="440" height="277" /><figcaption id="caption-attachment-1255" class="wp-caption-text">LOGO EP16 &#8211; Car 7</figcaption></figure>
<p>&nbsp;</p>
<p>เสร็จแล้วครับ สำหรับรูปรถยนต์ที่เราต้องการ Code ทั้งหมด สามารถเข้าไปดูได้ที่นี่ครับ <a href="https://github.com/doctorkarn/logo-lang/blob/master/EP16.txt">https://github.com/doctorkarn/logo-lang/blob/master/EP16.txt</a></p>
<p>เป็นอย่างไรกันบ้างครับสำหรับการวาดรูปรถยนต์ จะสังเกตได้ว่าถ้าเราวาดรูปโดยค่อยๆ วาด ค่อยๆ รัน เวลาเกิดปัญหา จะทำให้เราสามารถพบจุดที่มีปัญหา และแก้ไขได้อย่างรวดเร็วครับ</p>
<p>สามารถติดตาม “วาดรูปด้วยภาษาโลโก้” ตอนอื่นๆ ได้ที่นี่ครับ <a href="https://karnlab.com/tag/ภาษาโลโก้">https://karnlab.com/tag/ภาษาโลโก้</a></p>
<p>&nbsp;</p>
<p>The post <a href="https://karnlab.com/logo-tutorial-ep16-car/">วาดรูปด้วยภาษาโลโก้ : ตอนที่ 16 – รถยนต์</a> appeared first on <a href="https://karnlab.com">KarnLab</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://karnlab.com/logo-tutorial-ep16-car/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: karnlab.com @ 2026-05-04 21:02:32 by W3 Total Cache
-->