gopl-zh.github.com/ch1/ch1-04.html

2143 lines
70 KiB
HTML
Raw Normal View History

2015-12-09 07:57:17 +00:00
<!DOCTYPE HTML>
<html lang="zh-tw" >
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
2015-12-31 08:20:27 +00:00
<title>GIF動畵 | Go语言圣经</title>
2015-12-09 07:57:17 +00:00
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="">
2016-01-02 08:04:45 +00:00
<meta name="generator" content="GitBook 2.6.6">
2015-12-09 07:57:17 +00:00
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="../gitbook/style.css">
2015-12-28 08:08:26 +00:00
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-katex/katex.min.css">
2015-12-09 07:57:17 +00:00
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
<link rel="next" href="../ch1/ch1-05.html" />
<link rel="prev" href="../ch1/ch1-03.html" />
</head>
<body>
2016-01-02 08:04:45 +00:00
<div class="book"
data-level="1.4"
data-chapter-title="GIF動畵"
data-filepath="ch1/ch1-04.md"
data-basepath=".."
data-revision="Sat Jan 02 2016 16:00:23 GMT+0800 (中国标准时间)"
data-innerlanguage="">
2015-12-09 07:57:17 +00:00
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="0" data-path="index.html">
<a href="../index.html">
<i class="fa fa-check"></i>
前言
</a>
<ul class="articles">
<li class="chapter " data-level="0.1" data-path="ch0/ch0-01.html">
<a href="../ch0/ch0-01.html">
<i class="fa fa-check"></i>
<b>0.1.</b>
Go語言起源
</a>
</li>
<li class="chapter " data-level="0.2" data-path="ch0/ch0-02.html">
<a href="../ch0/ch0-02.html">
<i class="fa fa-check"></i>
<b>0.2.</b>
Go語言項目
</a>
</li>
<li class="chapter " data-level="0.3" data-path="ch0/ch0-03.html">
<a href="../ch0/ch0-03.html">
<i class="fa fa-check"></i>
<b>0.3.</b>
本書的組織
</a>
</li>
<li class="chapter " data-level="0.4" data-path="ch0/ch0-04.html">
<a href="../ch0/ch0-04.html">
<i class="fa fa-check"></i>
<b>0.4.</b>
更多的信息
</a>
</li>
<li class="chapter " data-level="0.5" data-path="ch0/ch0-05.html">
<a href="../ch0/ch0-05.html">
<i class="fa fa-check"></i>
<b>0.5.</b>
2015-12-21 04:55:18 +00:00
致謝
2015-12-09 07:57:17 +00:00
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1" data-path="ch1/ch1.html">
<a href="../ch1/ch1.html">
<i class="fa fa-check"></i>
<b>1.</b>
入門
</a>
<ul class="articles">
<li class="chapter " data-level="1.1" data-path="ch1/ch1-01.html">
<a href="../ch1/ch1-01.html">
<i class="fa fa-check"></i>
<b>1.1.</b>
Hello, World
</a>
</li>
<li class="chapter " data-level="1.2" data-path="ch1/ch1-02.html">
<a href="../ch1/ch1-02.html">
<i class="fa fa-check"></i>
<b>1.2.</b>
命令行參數
</a>
</li>
<li class="chapter " data-level="1.3" data-path="ch1/ch1-03.html">
<a href="../ch1/ch1-03.html">
<i class="fa fa-check"></i>
<b>1.3.</b>
2015-12-21 04:55:18 +00:00
査找重複的行
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter active" data-level="1.4" data-path="ch1/ch1-04.html">
<a href="../ch1/ch1-04.html">
<i class="fa fa-check"></i>
<b>1.4.</b>
2015-12-21 04:55:18 +00:00
GIF動畵
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="1.5" data-path="ch1/ch1-05.html">
<a href="../ch1/ch1-05.html">
<i class="fa fa-check"></i>
<b>1.5.</b>
2015-12-28 08:08:26 +00:00
獲取URL
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="1.6" data-path="ch1/ch1-06.html">
<a href="../ch1/ch1-06.html">
<i class="fa fa-check"></i>
<b>1.6.</b>
2015-12-28 08:08:26 +00:00
併發獲取多個URL
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="1.7" data-path="ch1/ch1-07.html">
<a href="../ch1/ch1-07.html">
<i class="fa fa-check"></i>
<b>1.7.</b>
Web服務
</a>
</li>
<li class="chapter " data-level="1.8" data-path="ch1/ch1-08.html">
<a href="../ch1/ch1-08.html">
<i class="fa fa-check"></i>
<b>1.8.</b>
本章要點
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2" data-path="ch2/ch2.html">
<a href="../ch2/ch2.html">
<i class="fa fa-check"></i>
<b>2.</b>
程序結構
</a>
<ul class="articles">
<li class="chapter " data-level="2.1" data-path="ch2/ch2-01.html">
<a href="../ch2/ch2-01.html">
<i class="fa fa-check"></i>
<b>2.1.</b>
命名
</a>
</li>
<li class="chapter " data-level="2.2" data-path="ch2/ch2-02.html">
<a href="../ch2/ch2-02.html">
<i class="fa fa-check"></i>
<b>2.2.</b>
聲明
</a>
</li>
<li class="chapter " data-level="2.3" data-path="ch2/ch2-03.html">
<a href="../ch2/ch2-03.html">
<i class="fa fa-check"></i>
<b>2.3.</b>
變量
</a>
</li>
<li class="chapter " data-level="2.4" data-path="ch2/ch2-04.html">
<a href="../ch2/ch2-04.html">
<i class="fa fa-check"></i>
<b>2.4.</b>
賦值
</a>
</li>
<li class="chapter " data-level="2.5" data-path="ch2/ch2-05.html">
<a href="../ch2/ch2-05.html">
<i class="fa fa-check"></i>
<b>2.5.</b>
類型
</a>
</li>
<li class="chapter " data-level="2.6" data-path="ch2/ch2-06.html">
<a href="../ch2/ch2-06.html">
<i class="fa fa-check"></i>
<b>2.6.</b>
包和文件
</a>
</li>
<li class="chapter " data-level="2.7" data-path="ch2/ch2-07.html">
<a href="../ch2/ch2-07.html">
<i class="fa fa-check"></i>
<b>2.7.</b>
作用域
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="3" data-path="ch3/ch3.html">
<a href="../ch3/ch3.html">
<i class="fa fa-check"></i>
<b>3.</b>
基礎數據類型
</a>
<ul class="articles">
<li class="chapter " data-level="3.1" data-path="ch3/ch3-01.html">
<a href="../ch3/ch3-01.html">
<i class="fa fa-check"></i>
<b>3.1.</b>
整型
</a>
</li>
<li class="chapter " data-level="3.2" data-path="ch3/ch3-02.html">
<a href="../ch3/ch3-02.html">
<i class="fa fa-check"></i>
<b>3.2.</b>
浮點數
</a>
</li>
<li class="chapter " data-level="3.3" data-path="ch3/ch3-03.html">
<a href="../ch3/ch3-03.html">
<i class="fa fa-check"></i>
<b>3.3.</b>
2015-12-21 04:55:18 +00:00
複數
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="3.4" data-path="ch3/ch3-04.html">
<a href="../ch3/ch3-04.html">
<i class="fa fa-check"></i>
<b>3.4.</b>
2015-12-21 04:55:18 +00:00
布爾型
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="3.5" data-path="ch3/ch3-05.html">
<a href="../ch3/ch3-05.html">
<i class="fa fa-check"></i>
<b>3.5.</b>
字符串
</a>
</li>
<li class="chapter " data-level="3.6" data-path="ch3/ch3-06.html">
<a href="../ch3/ch3-06.html">
<i class="fa fa-check"></i>
<b>3.6.</b>
常量
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="4" data-path="ch4/ch4.html">
<a href="../ch4/ch4.html">
<i class="fa fa-check"></i>
<b>4.</b>
2015-12-21 04:55:18 +00:00
複合數據類型
2015-12-09 07:57:17 +00:00
</a>
<ul class="articles">
<li class="chapter " data-level="4.1" data-path="ch4/ch4-01.html">
<a href="../ch4/ch4-01.html">
<i class="fa fa-check"></i>
<b>4.1.</b>
數組
</a>
</li>
<li class="chapter " data-level="4.2" data-path="ch4/ch4-02.html">
<a href="../ch4/ch4-02.html">
<i class="fa fa-check"></i>
<b>4.2.</b>
2015-12-31 08:20:27 +00:00
Slice
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="4.3" data-path="ch4/ch4-03.html">
<a href="../ch4/ch4-03.html">
<i class="fa fa-check"></i>
<b>4.3.</b>
2015-12-31 08:20:27 +00:00
Map
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="4.4" data-path="ch4/ch4-04.html">
<a href="../ch4/ch4-04.html">
<i class="fa fa-check"></i>
<b>4.4.</b>
結構體
</a>
</li>
<li class="chapter " data-level="4.5" data-path="ch4/ch4-05.html">
<a href="../ch4/ch4-05.html">
<i class="fa fa-check"></i>
<b>4.5.</b>
JSON
</a>
</li>
<li class="chapter " data-level="4.6" data-path="ch4/ch4-06.html">
<a href="../ch4/ch4-06.html">
<i class="fa fa-check"></i>
<b>4.6.</b>
文本和HTML模闆
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="5" data-path="ch5/ch5.html">
<a href="../ch5/ch5.html">
<i class="fa fa-check"></i>
<b>5.</b>
函數
</a>
<ul class="articles">
<li class="chapter " data-level="5.1" data-path="ch5/ch5-01.html">
<a href="../ch5/ch5-01.html">
<i class="fa fa-check"></i>
<b>5.1.</b>
函數聲明
</a>
</li>
<li class="chapter " data-level="5.2" data-path="ch5/ch5-02.html">
<a href="../ch5/ch5-02.html">
<i class="fa fa-check"></i>
<b>5.2.</b>
遞歸
</a>
</li>
<li class="chapter " data-level="5.3" data-path="ch5/ch5-03.html">
<a href="../ch5/ch5-03.html">
<i class="fa fa-check"></i>
<b>5.3.</b>
多返迴值
</a>
</li>
<li class="chapter " data-level="5.4" data-path="ch5/ch5-04.html">
<a href="../ch5/ch5-04.html">
<i class="fa fa-check"></i>
<b>5.4.</b>
錯誤
</a>
</li>
<li class="chapter " data-level="5.5" data-path="ch5/ch5-05.html">
<a href="../ch5/ch5-05.html">
<i class="fa fa-check"></i>
<b>5.5.</b>
函數值
</a>
</li>
<li class="chapter " data-level="5.6" data-path="ch5/ch5-06.html">
<a href="../ch5/ch5-06.html">
<i class="fa fa-check"></i>
<b>5.6.</b>
匿名函數
</a>
</li>
<li class="chapter " data-level="5.7" data-path="ch5/ch5-07.html">
<a href="../ch5/ch5-07.html">
<i class="fa fa-check"></i>
<b>5.7.</b>
可變參數
</a>
</li>
<li class="chapter " data-level="5.8" data-path="ch5/ch5-08.html">
<a href="../ch5/ch5-08.html">
<i class="fa fa-check"></i>
<b>5.8.</b>
Deferred函數
</a>
</li>
<li class="chapter " data-level="5.9" data-path="ch5/ch5-09.html">
<a href="../ch5/ch5-09.html">
<i class="fa fa-check"></i>
<b>5.9.</b>
Panic異常
</a>
</li>
<li class="chapter " data-level="5.10" data-path="ch5/ch5-10.html">
<a href="../ch5/ch5-10.html">
<i class="fa fa-check"></i>
<b>5.10.</b>
2015-12-28 08:08:26 +00:00
Recover捕獲異常
2015-12-09 07:57:17 +00:00
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="6" data-path="ch6/ch6.html">
<a href="../ch6/ch6.html">
<i class="fa fa-check"></i>
<b>6.</b>
方法
</a>
<ul class="articles">
<li class="chapter " data-level="6.1" data-path="ch6/ch6-01.html">
<a href="../ch6/ch6-01.html">
<i class="fa fa-check"></i>
<b>6.1.</b>
方法聲明
</a>
</li>
<li class="chapter " data-level="6.2" data-path="ch6/ch6-02.html">
<a href="../ch6/ch6-02.html">
<i class="fa fa-check"></i>
<b>6.2.</b>
2015-12-21 04:55:18 +00:00
基於指針對象的方法
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="6.3" data-path="ch6/ch6-03.html">
<a href="../ch6/ch6-03.html">
<i class="fa fa-check"></i>
<b>6.3.</b>
通過嵌入結構體來擴展類型
</a>
</li>
<li class="chapter " data-level="6.4" data-path="ch6/ch6-04.html">
<a href="../ch6/ch6-04.html">
<i class="fa fa-check"></i>
<b>6.4.</b>
2015-12-21 04:55:18 +00:00
方法值和方法表達式
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="6.5" data-path="ch6/ch6-05.html">
<a href="../ch6/ch6-05.html">
<i class="fa fa-check"></i>
<b>6.5.</b>
示例: Bit數組
</a>
</li>
<li class="chapter " data-level="6.6" data-path="ch6/ch6-06.html">
<a href="../ch6/ch6-06.html">
<i class="fa fa-check"></i>
<b>6.6.</b>
封裝
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="7" data-path="ch7/ch7.html">
<a href="../ch7/ch7.html">
<i class="fa fa-check"></i>
<b>7.</b>
接口
</a>
<ul class="articles">
<li class="chapter " data-level="7.1" data-path="ch7/ch7-01.html">
<a href="../ch7/ch7-01.html">
<i class="fa fa-check"></i>
<b>7.1.</b>
2015-12-21 04:55:18 +00:00
接口是合約
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="7.2" data-path="ch7/ch7-02.html">
<a href="../ch7/ch7-02.html">
<i class="fa fa-check"></i>
<b>7.2.</b>
接口類型
</a>
</li>
<li class="chapter " data-level="7.3" data-path="ch7/ch7-03.html">
<a href="../ch7/ch7-03.html">
<i class="fa fa-check"></i>
<b>7.3.</b>
實現接口的條件
</a>
</li>
<li class="chapter " data-level="7.4" data-path="ch7/ch7-04.html">
<a href="../ch7/ch7-04.html">
<i class="fa fa-check"></i>
<b>7.4.</b>
flag.Value接口
</a>
</li>
<li class="chapter " data-level="7.5" data-path="ch7/ch7-05.html">
<a href="../ch7/ch7-05.html">
<i class="fa fa-check"></i>
<b>7.5.</b>
接口值
</a>
</li>
<li class="chapter " data-level="7.6" data-path="ch7/ch7-06.html">
<a href="../ch7/ch7-06.html">
<i class="fa fa-check"></i>
<b>7.6.</b>
sort.Interface接口
</a>
</li>
<li class="chapter " data-level="7.7" data-path="ch7/ch7-07.html">
<a href="../ch7/ch7-07.html">
<i class="fa fa-check"></i>
<b>7.7.</b>
http.Handler接口
</a>
</li>
<li class="chapter " data-level="7.8" data-path="ch7/ch7-08.html">
<a href="../ch7/ch7-08.html">
<i class="fa fa-check"></i>
<b>7.8.</b>
error接口
</a>
</li>
<li class="chapter " data-level="7.9" data-path="ch7/ch7-09.html">
<a href="../ch7/ch7-09.html">
<i class="fa fa-check"></i>
<b>7.9.</b>
2015-12-21 04:55:18 +00:00
示例: 表達式求值
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="7.10" data-path="ch7/ch7-10.html">
<a href="../ch7/ch7-10.html">
<i class="fa fa-check"></i>
<b>7.10.</b>
類型斷言
</a>
</li>
<li class="chapter " data-level="7.11" data-path="ch7/ch7-11.html">
<a href="../ch7/ch7-11.html">
<i class="fa fa-check"></i>
<b>7.11.</b>
2015-12-21 04:55:18 +00:00
基於類型斷言識别錯誤類型
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="7.12" data-path="ch7/ch7-12.html">
<a href="../ch7/ch7-12.html">
<i class="fa fa-check"></i>
<b>7.12.</b>
通過類型斷言査詢接口
</a>
</li>
<li class="chapter " data-level="7.13" data-path="ch7/ch7-13.html">
<a href="../ch7/ch7-13.html">
<i class="fa fa-check"></i>
<b>7.13.</b>
類型分支
</a>
</li>
<li class="chapter " data-level="7.14" data-path="ch7/ch7-14.html">
<a href="../ch7/ch7-14.html">
<i class="fa fa-check"></i>
<b>7.14.</b>
示例: 基於標記的XML解碼
</a>
</li>
<li class="chapter " data-level="7.15" data-path="ch7/ch7-15.html">
<a href="../ch7/ch7-15.html">
<i class="fa fa-check"></i>
<b>7.15.</b>
補充幾點
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="8" data-path="ch8/ch8.html">
<a href="../ch8/ch8.html">
<i class="fa fa-check"></i>
<b>8.</b>
Goroutines和Channels
</a>
<ul class="articles">
<li class="chapter " data-level="8.1" data-path="ch8/ch8-01.html">
<a href="../ch8/ch8-01.html">
<i class="fa fa-check"></i>
<b>8.1.</b>
Goroutines
</a>
</li>
<li class="chapter " data-level="8.2" data-path="ch8/ch8-02.html">
<a href="../ch8/ch8-02.html">
<i class="fa fa-check"></i>
<b>8.2.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的Clock服務
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.3" data-path="ch8/ch8-03.html">
<a href="../ch8/ch8-03.html">
<i class="fa fa-check"></i>
<b>8.3.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的Echo服務
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.4" data-path="ch8/ch8-04.html">
<a href="../ch8/ch8-04.html">
<i class="fa fa-check"></i>
<b>8.4.</b>
Channels
</a>
</li>
<li class="chapter " data-level="8.5" data-path="ch8/ch8-05.html">
<a href="../ch8/ch8-05.html">
<i class="fa fa-check"></i>
<b>8.5.</b>
併行的循環
</a>
</li>
<li class="chapter " data-level="8.6" data-path="ch8/ch8-06.html">
<a href="../ch8/ch8-06.html">
<i class="fa fa-check"></i>
<b>8.6.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的Web爬蟲
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.7" data-path="ch8/ch8-07.html">
<a href="../ch8/ch8-07.html">
<i class="fa fa-check"></i>
<b>8.7.</b>
2015-12-21 04:55:18 +00:00
基於select的多路複用
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.8" data-path="ch8/ch8-08.html">
<a href="../ch8/ch8-08.html">
<i class="fa fa-check"></i>
<b>8.8.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的字典遍歷
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.9" data-path="ch8/ch8-09.html">
<a href="../ch8/ch8-09.html">
<i class="fa fa-check"></i>
<b>8.9.</b>
2015-12-28 08:08:26 +00:00
併發的退出
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="8.10" data-path="ch8/ch8-10.html">
<a href="../ch8/ch8-10.html">
<i class="fa fa-check"></i>
<b>8.10.</b>
示例: 聊天服務
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="9" data-path="ch9/ch9.html">
<a href="../ch9/ch9.html">
<i class="fa fa-check"></i>
<b>9.</b>
2015-12-21 04:55:18 +00:00
基於共享變量的併發
2015-12-09 07:57:17 +00:00
</a>
<ul class="articles">
<li class="chapter " data-level="9.1" data-path="ch9/ch9-01.html">
<a href="../ch9/ch9-01.html">
<i class="fa fa-check"></i>
<b>9.1.</b>
競爭條件
</a>
</li>
<li class="chapter " data-level="9.2" data-path="ch9/ch9-02.html">
<a href="../ch9/ch9-02.html">
<i class="fa fa-check"></i>
<b>9.2.</b>
sync.Mutex互斥鎖
</a>
</li>
<li class="chapter " data-level="9.3" data-path="ch9/ch9-03.html">
<a href="../ch9/ch9-03.html">
<i class="fa fa-check"></i>
<b>9.3.</b>
sync.RWMutex讀寫鎖
</a>
</li>
<li class="chapter " data-level="9.4" data-path="ch9/ch9-04.html">
<a href="../ch9/ch9-04.html">
<i class="fa fa-check"></i>
<b>9.4.</b>
2015-12-21 04:55:18 +00:00
內存同步
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="9.5" data-path="ch9/ch9-05.html">
<a href="../ch9/ch9-05.html">
<i class="fa fa-check"></i>
<b>9.5.</b>
sync.Once初始化
</a>
</li>
<li class="chapter " data-level="9.6" data-path="ch9/ch9-06.html">
<a href="../ch9/ch9-06.html">
<i class="fa fa-check"></i>
<b>9.6.</b>
競爭條件檢測
</a>
</li>
<li class="chapter " data-level="9.7" data-path="ch9/ch9-07.html">
<a href="../ch9/ch9-07.html">
<i class="fa fa-check"></i>
<b>9.7.</b>
2015-12-21 04:55:18 +00:00
示例: 併發的非阻塞緩存
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="9.8" data-path="ch9/ch9-08.html">
<a href="../ch9/ch9-08.html">
<i class="fa fa-check"></i>
<b>9.8.</b>
2015-12-21 04:55:18 +00:00
Goroutines和線程
2015-12-09 07:57:17 +00:00
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="10" data-path="ch10/ch10.html">
<a href="../ch10/ch10.html">
<i class="fa fa-check"></i>
<b>10.</b>
包和工具
</a>
<ul class="articles">
<li class="chapter " data-level="10.1" data-path="ch10/ch10-01.html">
<a href="../ch10/ch10-01.html">
<i class="fa fa-check"></i>
<b>10.1.</b>
簡介
</a>
</li>
<li class="chapter " data-level="10.2" data-path="ch10/ch10-02.html">
<a href="../ch10/ch10-02.html">
<i class="fa fa-check"></i>
<b>10.2.</b>
導入路徑
</a>
</li>
<li class="chapter " data-level="10.3" data-path="ch10/ch10-03.html">
<a href="../ch10/ch10-03.html">
<i class="fa fa-check"></i>
<b>10.3.</b>
包聲明
</a>
</li>
<li class="chapter " data-level="10.4" data-path="ch10/ch10-04.html">
<a href="../ch10/ch10-04.html">
<i class="fa fa-check"></i>
<b>10.4.</b>
導入聲明
</a>
</li>
<li class="chapter " data-level="10.5" data-path="ch10/ch10-05.html">
<a href="../ch10/ch10-05.html">
<i class="fa fa-check"></i>
<b>10.5.</b>
匿名導入
</a>
</li>
<li class="chapter " data-level="10.6" data-path="ch10/ch10-06.html">
<a href="../ch10/ch10-06.html">
<i class="fa fa-check"></i>
<b>10.6.</b>
包和命名
</a>
</li>
<li class="chapter " data-level="10.7" data-path="ch10/ch10-07.html">
<a href="../ch10/ch10-07.html">
<i class="fa fa-check"></i>
<b>10.7.</b>
工具
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="11" data-path="ch11/ch11.html">
<a href="../ch11/ch11.html">
<i class="fa fa-check"></i>
<b>11.</b>
測試
</a>
<ul class="articles">
<li class="chapter " data-level="11.1" data-path="ch11/ch11-01.html">
<a href="../ch11/ch11-01.html">
<i class="fa fa-check"></i>
<b>11.1.</b>
go test
</a>
</li>
<li class="chapter " data-level="11.2" data-path="ch11/ch11-02.html">
<a href="../ch11/ch11-02.html">
<i class="fa fa-check"></i>
<b>11.2.</b>
測試函數
</a>
</li>
<li class="chapter " data-level="11.3" data-path="ch11/ch11-03.html">
<a href="../ch11/ch11-03.html">
<i class="fa fa-check"></i>
<b>11.3.</b>
測試覆蓋率
</a>
</li>
<li class="chapter " data-level="11.4" data-path="ch11/ch11-04.html">
<a href="../ch11/ch11-04.html">
<i class="fa fa-check"></i>
<b>11.4.</b>
基準測試
</a>
</li>
<li class="chapter " data-level="11.5" data-path="ch11/ch11-05.html">
<a href="../ch11/ch11-05.html">
<i class="fa fa-check"></i>
<b>11.5.</b>
剖析
</a>
</li>
<li class="chapter " data-level="11.6" data-path="ch11/ch11-06.html">
<a href="../ch11/ch11-06.html">
<i class="fa fa-check"></i>
<b>11.6.</b>
示例函數
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="12" data-path="ch12/ch12.html">
<a href="../ch12/ch12.html">
<i class="fa fa-check"></i>
<b>12.</b>
反射
</a>
<ul class="articles">
<li class="chapter " data-level="12.1" data-path="ch12/ch12-01.html">
<a href="../ch12/ch12-01.html">
<i class="fa fa-check"></i>
<b>12.1.</b>
2015-12-21 04:55:18 +00:00
爲何需要反射?
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="12.2" data-path="ch12/ch12-02.html">
<a href="../ch12/ch12-02.html">
<i class="fa fa-check"></i>
<b>12.2.</b>
reflect.Type和reflect.Value
</a>
</li>
<li class="chapter " data-level="12.3" data-path="ch12/ch12-03.html">
<a href="../ch12/ch12-03.html">
<i class="fa fa-check"></i>
<b>12.3.</b>
Display遞歸打印
</a>
</li>
<li class="chapter " data-level="12.4" data-path="ch12/ch12-04.html">
<a href="../ch12/ch12-04.html">
<i class="fa fa-check"></i>
<b>12.4.</b>
2015-12-21 04:55:18 +00:00
示例: 編碼S表達式
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="12.5" data-path="ch12/ch12-05.html">
<a href="../ch12/ch12-05.html">
<i class="fa fa-check"></i>
<b>12.5.</b>
通過reflect.Value脩改值
</a>
</li>
<li class="chapter " data-level="12.6" data-path="ch12/ch12-06.html">
<a href="../ch12/ch12-06.html">
<i class="fa fa-check"></i>
<b>12.6.</b>
2015-12-21 04:55:18 +00:00
示例: 解碼S表達式
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="12.7" data-path="ch12/ch12-07.html">
<a href="../ch12/ch12-07.html">
<i class="fa fa-check"></i>
<b>12.7.</b>
2015-12-28 08:08:26 +00:00
獲取結構體字段標識
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="chapter " data-level="12.8" data-path="ch12/ch12-08.html">
<a href="../ch12/ch12-08.html">
<i class="fa fa-check"></i>
<b>12.8.</b>
顯示一個類型的方法集
</a>
</li>
<li class="chapter " data-level="12.9" data-path="ch12/ch12-09.html">
<a href="../ch12/ch12-09.html">
<i class="fa fa-check"></i>
<b>12.9.</b>
幾點忠告
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="13" data-path="ch13/ch13.html">
<a href="../ch13/ch13.html">
<i class="fa fa-check"></i>
<b>13.</b>
底層編程
</a>
<ul class="articles">
<li class="chapter " data-level="13.1" data-path="ch13/ch13-01.html">
<a href="../ch13/ch13-01.html">
<i class="fa fa-check"></i>
<b>13.1.</b>
unsafe.Sizeof, Alignof 和 Offsetof
</a>
</li>
<li class="chapter " data-level="13.2" data-path="ch13/ch13-02.html">
<a href="../ch13/ch13-02.html">
<i class="fa fa-check"></i>
<b>13.2.</b>
unsafe.Pointer
</a>
</li>
<li class="chapter " data-level="13.3" data-path="ch13/ch13-03.html">
<a href="../ch13/ch13-03.html">
<i class="fa fa-check"></i>
<b>13.3.</b>
示例: 深度相等判斷
</a>
</li>
<li class="chapter " data-level="13.4" data-path="ch13/ch13-04.html">
<a href="../ch13/ch13-04.html">
<i class="fa fa-check"></i>
<b>13.4.</b>
通過cgo調用C代碼
</a>
</li>
<li class="chapter " data-level="13.5" data-path="ch13/ch13-05.html">
<a href="../ch13/ch13-05.html">
<i class="fa fa-check"></i>
<b>13.5.</b>
幾點忠告
</a>
</li>
</ul>
</li>
2015-12-24 06:47:06 +00:00
<li class="chapter " data-level="14" data-path="CONTRIBUTORS.html">
2015-12-09 07:57:17 +00:00
2015-12-24 06:47:06 +00:00
<a href="../CONTRIBUTORS.html">
2015-12-09 07:57:17 +00:00
<i class="fa fa-check"></i>
2015-12-21 04:55:18 +00:00
<b>14.</b>
2015-12-09 07:57:17 +00:00
2015-12-24 06:47:06 +00:00
附録
2015-12-09 07:57:17 +00:00
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
本書使用 GitBook 釋出
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Actions Left -->
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
2015-12-31 08:20:27 +00:00
<a href="../" >Go语言圣经</a>
2015-12-09 07:57:17 +00:00
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
2015-12-21 04:55:18 +00:00
<h2 id="14-gif&#x52D5;&#x7575;">1.4. GIF&#x52D5;&#x7575;</h2>
2015-12-28 08:08:26 +00:00
<p>&#x4E0B;&#x9762;&#x7684;&#x7A0B;&#x5E8F;&#x6703;&#x6F14;&#x793A;Go&#x8A9E;&#x8A00;&#x6A19;&#x6E96;&#x5EAB;&#x91CC;&#x7684;image&#x9019;&#x500B;package&#x7684;&#x7528;&#x6CD5;&#xFF0C;&#x6211;&#x5011;&#x6703;&#x7528;&#x9019;&#x500B;&#x5305;&#x4F86;&#x751F;&#x6210;&#x4E00;&#x7E6B;&#x5217;&#x7684;bit-mapped&#x5716;&#xFF0C;&#x7136;&#x5F8C;&#x5C07;&#x9019;&#x4E9B;&#x5716;&#x7247;&#x7DE8;&#x78BC;&#x7232;&#x4E00;&#x500B;GIF&#x52D5;&#x7575;&#x3002;&#x6211;&#x5011;&#x751F;&#x6210;&#x7684;&#x5716;&#x5F62;&#x540D;&#x5B57;&#x53EB;&#x5229;&#x85A9;&#x5982;&#x5716;&#x5F62;(Lissajous figures)&#xFF0C;&#x9019;&#x7A2E;&#x6548;&#x679C;&#x662F;&#x5728;1960&#x5E74;&#x4EE3;&#x7684;&#x8001;&#x96FB;&#x5F71;&#x91CC;&#x51FA;&#x73FE;&#x7684;&#x4E00;&#x7A2E;&#x8996;&#x89BA;&#x7279;&#x6548;&#x3002;&#x5B83;&#x5011;&#x662F;&#x5354;&#x632F;&#x5B50;&#x5728;&#x5169;&#x500B;&#x7DEF;&#x5EA6;&#x4E0A;&#x632F;&#x52D5;&#x6240;&#x7523;&#x751F;&#x7684;&#x9EB4;&#x7DDA;&#xFF0C;&#x6BD4;&#x5982;&#x5169;&#x500B;sin&#x6B63;&#x7D43;&#x6CE2;&#x5206;&#x522B;&#x5728;x&#x8EF8;&#x548C;y&#x8EF8;&#x8F38;&#x5165;&#x6703;&#x7523;&#x751F;&#x7684;&#x9EB4;&#x7DDA;&#x3002;&#x5716;1.1&#x662F;&#x9019;&#x6A23;&#x7684;&#x4E00;&#x500B;&#x4F8B;&#x5B50;&#xFF1A;</p>
2015-12-09 07:57:17 +00:00
<p><img src="../images/ch1-01.png" alt=""></p>
2015-12-28 08:08:26 +00:00
<p>&#x8B6F;&#x8A3B;&#xFF1A;&#x8981;&#x770B;&#x9019;&#x500B;&#x7A0B;&#x5E8F;&#x7684;&#x7D50;&#x679C;&#xFF0C;&#x9700;&#x8981;&#x5C07;&#x6A19;&#x6E96;&#x8F38;&#x51FA;&#x91CD;&#x5B9A;&#x5411;&#x5230;&#x4E00;&#x500B;GIF&#x5716;&#x50CF;&#x6587;&#x4EF6;&#xFF08;&#x4F7F;&#x7528; <code>./lissajous &gt; output.gif</code> &#x547D;&#x4EE4;&#xFF09;&#x3002;&#x4E0B;&#x9762;&#x662F;GIF&#x5716;&#x50CF;&#x52D5;&#x7575;&#x6548;&#x679C;&#xFF1A;</p>
2015-12-24 06:47:06 +00:00
<p><img src="../images/ch1-01.gif" alt=""></p>
<p>&#x9019;&#x6BB5;&#x4EE3;&#x78BC;&#x91CC;&#x6211;&#x5011;&#x7528;&#x4E86;&#x4E00;&#x4E9B;&#x65B0;&#x7684;&#x7D50;&#x69CB;&#xFF0C;&#x5305;&#x62EC;const&#x8072;&#x660E;&#xFF0C;struct&#x7D50;&#x69CB;&#x9AD4;&#x985E;&#x578B;&#xFF0C;&#x8907;&#x5408;&#x8072;&#x660E;&#x3002;&#x548C;&#x6211;&#x5011;&#x8209;&#x7684;&#x5176;&#x5B83;&#x7684;&#x4F8B;&#x5B50;&#x4E0D;&#x592A;&#x4E00;&#x6A23;&#xFF0C;&#x9019;&#x4E00;&#x500B;&#x4F8B;&#x5B50;&#x5305;&#x542B;&#x4E86;&#x6D6E;&#x9EDE;&#x6578;&#x904B;&#x7B97;&#x3002;&#x9019;&#x4E9B;&#x6982;&#x5FF5;&#x6211;&#x5011;&#x96BB;&#x5728;&#x9019;&#x91CC;&#x7C21;&#x55AE;&#x5730;&#x8AAC;&#x660E;&#x4E00;&#x4E0B;&#xFF0C;&#x4E4B;&#x5F8C;&#x7684;&#x7AE0;&#x7BC0;&#x6703;&#x66F4;&#x8A73;&#x7D30;&#x5730;&#x8B1B;&#x89E3;&#x3002;</p>
2015-12-09 07:57:17 +00:00
<pre><code class="lang-go">gopl.io/ch1/lissajous
<span class="hljs-comment">// Lissajous generates GIF animations of random Lissajous figures.</span>
<span class="hljs-keyword">package</span> main
<span class="hljs-keyword">import</span> (
<span class="hljs-string">&quot;image&quot;</span>
<span class="hljs-string">&quot;image/color&quot;</span>
<span class="hljs-string">&quot;image/gif&quot;</span>
<span class="hljs-string">&quot;io&quot;</span>
<span class="hljs-string">&quot;math&quot;</span>
<span class="hljs-string">&quot;math/rand&quot;</span>
<span class="hljs-string">&quot;os&quot;</span>
)
<span class="hljs-keyword">var</span> palette = []color.Color{color.White, color.Black}
2015-12-24 06:47:06 +00:00
2015-12-09 07:57:17 +00:00
<span class="hljs-keyword">const</span> (
whiteIndex = <span class="hljs-number">0</span> <span class="hljs-comment">// first color in palette</span>
blackIndex = <span class="hljs-number">1</span> <span class="hljs-comment">// next color in palette</span>
)
2015-12-24 06:47:06 +00:00
2015-12-09 07:57:17 +00:00
<span class="hljs-keyword">func</span> main() {
lissajous(os.Stdout)
}
<span class="hljs-keyword">func</span> lissajous(out io.Writer) {
<span class="hljs-keyword">const</span> (
cycles = <span class="hljs-number">5</span> <span class="hljs-comment">// number of complete x oscillator revolutions</span>
res = <span class="hljs-number">0.001</span> <span class="hljs-comment">// angular resolution</span>
size = <span class="hljs-number">100</span> <span class="hljs-comment">// image canvas covers [-size..+size]</span>
nframes = <span class="hljs-number">64</span> <span class="hljs-comment">// number of animation frames</span>
delay = <span class="hljs-number">8</span> <span class="hljs-comment">// delay between frames in 10ms units</span>
)
freq := rand.Float64() * <span class="hljs-number">3.0</span> <span class="hljs-comment">// relative frequency of y oscillator</span>
anim := gif.GIF{LoopCount: nframes}
phase := <span class="hljs-number">0.0</span> <span class="hljs-comment">// phase difference</span>
<span class="hljs-keyword">for</span> i := <span class="hljs-number">0</span>; i &lt; nframes; i++ {
rect := image.Rect(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">2</span>*size+<span class="hljs-number">1</span>, <span class="hljs-number">2</span>*size+<span class="hljs-number">1</span>)
img := image.NewPaletted(rect, palette)
<span class="hljs-keyword">for</span> t := <span class="hljs-number">0.0</span>; t &lt; cycles*<span class="hljs-number">2</span>*math.Pi; t += res {
x := math.Sin(t)
y := math.Sin(t*freq + phase)
img.SetColorIndex(size+<span class="hljs-typename">int</span>(x*size+<span class="hljs-number">0.5</span>), size+<span class="hljs-typename">int</span>(y*size+<span class="hljs-number">0.5</span>),
2015-12-24 06:47:06 +00:00
bla kIndex)
2015-12-09 07:57:17 +00:00
}
phase += <span class="hljs-number">0.1</span>
anim.Delay = <span class="hljs-built_in">append</span>(anim.Delay, delay)
anim.Image = <span class="hljs-built_in">append</span>(anim.Image, img)
}
gif.EncodeAll(out, &amp;anim) <span class="hljs-comment">// <span class="hljs-doctag">NOTE:</span> ignoring encoding errors</span>
}
</code></pre>
2015-12-24 06:47:06 +00:00
<p>&#x7576;&#x6211;&#x5011;import&#x4E86;&#x4E00;&#x500B;&#x5305;&#x8DEF;&#x5F91;&#x5305;&#x542B;&#x6709;&#x591A;&#x500B;&#x55AE;&#x8A5E;&#x7684;package&#x6642;&#xFF0C;&#x6BD4;&#x5982;image/color&#xFF08;image&#x548C;color&#x5169;&#x500B;&#x55AE;&#x8A5E;&#xFF09;&#xFF0C;&#x901A;&#x5E38;&#x6211;&#x5011;&#x96BB;&#x9700;&#x8981;&#x7528;&#x6700;&#x5F8C;&#x90A3;&#x500B;&#x55AE;&#x8A5E;&#x8868;&#x793A;&#x9019;&#x500B;&#x5305;&#x5C31;&#x53EF;&#x4EE5;&#x3002;&#x6240;&#x4EE5;&#x7576;&#x6211;&#x5011;&#x5BEB;color.White&#x6642;&#xFF0C;&#x9019;&#x500B;&#x8B8A;&#x91CF;&#x6307;&#x5411;&#x7684;&#x662F;image/color&#x5305;&#x91CC;&#x7684;&#x8B8A;&#x91CF;&#xFF0C;&#x540C;&#x7406;gif.GIF&#x662F;&#x5C6C;&#x65BC;image/gif&#x5305;&#x91CC;&#x7684;&#x8B8A;&#x91CF;&#x3002;</p>
2015-12-28 08:08:26 +00:00
<p>&#x9019;&#x500B;&#x7A0B;&#x5E8F;&#x91CC;&#x7684;&#x5E38;&#x91CF;&#x8072;&#x660E;&#x7D66;&#x51FA;&#x4E86;&#x4E00;&#x7E6B;&#x5217;&#x7684;&#x5E38;&#x91CF;&#x503C;&#xFF0C;&#x5E38;&#x91CF;&#x662F;&#x6307;&#x5728;&#x7A0B;&#x5E8F;&#x7DE8;&#x8B6F;&#x5F8C;&#x904B;&#x884C;&#x6642;&#x59CB;&#x7D42;&#x90FD;&#x4E0D;&#x6703;&#x8B8A;&#x5316;&#x7684;&#x503C;&#xFF0C;&#x6BD4;&#x5982;&#x5708;&#x6578;&#x3001;&#x5E40;&#x6578;&#x3001;&#x5EF6;&#x9072;&#x503C;&#x3002;&#x5E38;&#x91CF;&#x8072;&#x660E;&#x548C;&#x8B8A;&#x91CF;&#x8072;&#x660E;&#x4E00;&#x822C;&#x90FD;&#x6703;&#x51FA;&#x73FE;&#x5728;&#x5305;&#x7D1A;&#x522B;&#xFF0C;&#x6240;&#x4EE5;&#x9019;&#x4E9B;&#x5E38;&#x91CF;&#x5728;&#x6574;&#x500B;&#x5305;&#x4E2D;&#x90FD;&#x662F;&#x53EF;&#x4EE5;&#x5171;&#x4EAB;&#x7684;&#xFF0C;&#x6216;&#x8005;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x628A;&#x5E38;&#x91CF;&#x8072;&#x660E;&#x5B9A;&#x7FA9;&#x5728;&#x51FD;&#x6578;&#x9AD4;&#x5167;&#x90E8;&#xFF0C;&#x90A3;&#x9EBD;&#x9019;&#x7A2E;&#x5E38;&#x91CF;&#x5C31;&#x96BB;&#x80FD;&#x5728;&#x51FD;&#x6578;&#x9AD4;&#x5167;&#x7528;&#x3002;&#x76EE;&#x524D;&#x5E38;&#x91CF;&#x8072;&#x660E;&#x7684;&#x503C;&#x5FC5;&#x9B1A;&#x662F;&#x4E00;&#x500B;&#x6578;&#x5B57;&#x503C;&#x3001;&#x5B57;&#x7B26;&#x4E32;&#x6216;&#x8005;&#x4E00;&#x500B;&#x56FA;&#x5B9A;&#x7684;boolean&#x503C;&#x3002;</p>
2015-12-24 06:47:06 +00:00
<p>[]color.Color{...}&#x548C;gif.GIF{...}&#x9019;&#x5169;&#x500B;&#x8868;&#x9054;&#x5F0F;&#x5C31;&#x662F;&#x6211;&#x5011;&#x8AAC;&#x7684;&#x8907;&#x5408;&#x8072;&#x660E;&#xFF08;4.2&#x548C;4.4.1&#x7BC0;&#x6709;&#x8AAC;&#x660E;&#xFF09;&#x3002;&#x9019;&#x662F;&#x5BE6;&#x4F8B;&#x5316;Go&#x8A9E;&#x8A00;&#x91CC;&#x7684;&#x8907;&#x5408;&#x985E;&#x578B;&#x7684;&#x4E00;&#x7A2E;&#x5BEB;&#x6CD5;&#x3002;&#x9019;&#x91CC;&#x7684;&#x524D;&#x8005;&#x751F;&#x6210;&#x7684;&#x662F;&#x4E00;&#x500B;slice&#x5207;&#x7247;&#xFF0C;&#x5F8C;&#x8005;&#x751F;&#x6210;&#x7684;&#x662F;&#x4E00;&#x500B;struct&#x7D50;&#x69CB;&#x9AD4;&#x3002;</p>
<p>gif.GIF&#x662F;&#x4E00;&#x500B;struct&#x985E;&#x578B;&#xFF08;&#x53C3;&#x8003;4.4&#x7BC0;&#xFF09;&#x3002;struct&#x662F;&#x4E00;&#x7D44;&#x503C;&#x6216;&#x8005;&#x53EB;&#x5B57;&#x6BB5;&#x7684;&#x96C6;&#x5408;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x985E;&#x578B;&#x96C6;&#x5408;&#x5728;&#x4E00;&#x500B;struct&#x53EF;&#x4EE5;&#x8B93;&#x6211;&#x5011;&#x4EE5;&#x4E00;&#x500B;&#x7D71;&#x4E00;&#x7684;&#x55AE;&#x5143;&#x9032;&#x884C;&#x8655;&#x7406;&#x3002;anim&#x662F;&#x4E00;&#x500B;gif.GIF&#x985E;&#x578B;&#x7684;struct&#x8B8A;&#x91CF;&#x3002;&#x9019;&#x7A2E;&#x5BEB;&#x6CD5;&#x6703;&#x751F;&#x6210;&#x4E00;&#x500B;struct&#x8B8A;&#x91CF;&#xFF0C;&#x4F75;&#x4E14;&#x5176;&#x5167;&#x90E8;&#x8B8A;&#x91CF;LoopCount&#x5B57;&#x6BB5;&#x6703;&#x88AB;&#x8A2D;&#x7F6E;&#x7232;nframes&#xFF1B;&#x800C;&#x5176;&#x5B83;&#x7684;&#x5B57;&#x6BB5;&#x6703;&#x88AB;&#x8A2D;&#x7F6E;&#x7232;&#x5404;&#x81EA;&#x985E;&#x578B;&#x9ED8;&#x8A8D;&#x7684;&#x96F6;&#x503C;&#x3002;struct&#x5167;&#x90E8;&#x7684;&#x8B8A;&#x91CF;&#x53EF;&#x4EE5;&#x4EE5;&#x4E00;&#x500B;&#x9EDE;(.)&#x4F86;&#x9032;&#x884C;&#x8A2A;&#x554F;&#xFF0C;&#x5C31;&#x50CF;&#x5728;&#x6700;&#x5F8C;&#x5169;&#x500B;&#x8CE6;&#x503C;&#x8A9E;&#x53E5;&#x4E2D;&#x986F;&#x5F0F;&#x5730;&#x66F4;&#x65B0;&#x4E86;anim&#x9019;&#x500B;struct&#x7684;Delay&#x548C;Image&#x5B57;&#x6BB5;&#x3002;</p>
2015-12-28 08:08:26 +00:00
<p>lissajous&#x51FD;&#x6578;&#x5167;&#x90E8;&#x6709;&#x5169;&#x5C64;&#x5D4C;&#x5957;&#x7684;for&#x5FAA;&#x74B0;&#x3002;&#x5916;&#x5C64;&#x5FAA;&#x74B0;&#x6703;&#x5FAA;&#x74B0;64&#x6B21;&#xFF0C;&#x6BCF;&#x4E00;&#x6B21;&#x90FD;&#x6703;&#x751F;&#x6210;&#x4E00;&#x500B;&#x55AE;&#x7368;&#x7684;&#x52D5;&#x7575;&#x5E40;&#x3002;&#x5B83;&#x751F;&#x6210;&#x4E86;&#x4E00;&#x500B;&#x5305;&#x542B;&#x5169;&#x7A2E;&#x9854;&#x8272;&#x7684;201&amp;201&#x5927;&#x5C0F;&#x7684;&#x5716;&#x7247;&#xFF0C;&#x767D;&#x8272;&#x548C;&#x9ED1;&#x8272;&#x3002;&#x6240;&#x6709;&#x50CF;&#x7D20;&#x9EDE;&#x90FD;&#x6703;&#x88AB;&#x9ED8;&#x8A8D;&#x8A2D;&#x7F6E;&#x7232;&#x5176;&#x96F6;&#x503C;&#xFF08;&#x4E5F;&#x5C31;&#x662F;palette&#x91CC;&#x7684;&#x7B2C;0&#x500B;&#x503C;&#xFF09;&#xFF0C;&#x9019;&#x91CC;&#x6211;&#x5011;&#x8A2D;&#x7F6E;&#x7684;&#x662F;&#x767D;&#x8272;&#x3002;&#x6BCF;&#x6B21;&#x7D93;&#x904E;&#x5167;&#x5B58;&#x5FAA;&#x74B0;&#x90FD;&#x6703;&#x901A;&#x904E;&#x8A2D;&#x7F6E;&#x50CF;&#x7D20;&#x7232;&#x9ED1;&#x8272;&#xFF0C;&#x751F;&#x6210;&#x4E00;&#x5F35;&#x65B0;&#x5716;&#x7247;&#x3002;&#x5176;&#x7D50;&#x679C;&#x6703;append&#x5230;&#x4E4B;&#x524D;&#x7D50;&#x679C;&#x4E4B;&#x5F8C;&#x3002;&#x9019;&#x91CC;&#x6211;&#x5011;&#x7528;&#x5230;&#x4E86;append(&#x53C3;&#x8003;4.2.1)&#x9019;&#x500B;&#x5167;&#x7F6E;&#x51FD;&#x6578;&#xFF0C;&#x5C07;&#x7D50;&#x679C;appen&#x5230;anim&#x4E2D;&#x7684;&#x5E40;&#x5217;&#x8868;&#x672B;&#x5C3E;&#xFF0C;&#x4F75;&#x6703;&#x8A2D;&#x7F6E;&#x4E00;&#x500B;&#x9ED8;&#x8A8D;&#x7684;80ms&#x7684;&#x5EF6;&#x9072;&#x503C;&#x3002;&#x6700;&#x7D42;&#x5FAA;&#x74B0;&#x7D50;&#x675F;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x5EF6;&#x9072;&#x503C;&#x4E5F;&#x88AB;&#x7DE8;&#x78BC;&#x9032;&#x4E86;GIF&#x5716;&#x7247;&#x4E2D;&#xFF0C;&#x4F75;&#x5C07;&#x7D50;&#x679C;&#x5BEB;&#x5165;&#x5230;&#x8F38;&#x51FA;&#x6D41;&#x3002;out&#x9019;&#x500B;&#x8B8A;&#x91CF;&#x662F;io.Writer&#x985E;&#x578B;&#xFF0C;&#x9019;&#x500B;&#x985E;&#x578B;&#x8B93;&#x6211;&#x5011;&#x53EF;&#x4EE5;&#x53EF;&#x4EE5;&#x8B93;&#x6211;&#x5011;&#x628A;&#x8F38;&#x51FA;&#x7D50;&#x679C;&#x5BEB;&#x5230;&#x5F88;&#x591A;&#x76EE;&#x6A19;&#xFF0C;&#x5F88;&#x5FEB;&#x6211;&#x5011;&#x5C31;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x4E86;&#x3002;</p>
2015-12-21 04:55:18 +00:00
<p>&#x5167;&#x5B58;&#x5FAA;&#x74B0;&#x8A2D;&#x7F6E;&#x4E86;&#x5169;&#x500B;&#x504F;&#x632F;&#x3002;x&#x8EF8;&#x504F;&#x632F;&#x4F7F;&#x7528;&#x7684;&#x662F;&#x4E00;&#x500B;sin&#x51FD;&#x6578;&#x3002;y&#x8EF8;&#x504F;&#x632F;&#x4E5F;&#x662F;&#x4E00;&#x500B;&#x6B63;&#x7D43;&#x6CE2;&#xFF0C;&#x4F46;&#x662F;&#x5176;&#x5176;&#x76F8;&#x5C0D;x&#x8EF8;&#x7684;&#x504F;&#x632F;&#x662F;&#x4E00;&#x500B;0-3&#x7684;&#x96A8;&#x6A5F;&#x503C;&#xFF0C;&#x4F75;&#x4E14;&#x521D;&#x59CB;&#x504F;&#x632F;&#x503C;&#x662F;&#x4E00;&#x500B;&#x96F6;&#x503C;&#xFF0C;&#x4F75;&#x96A8;&#x7740;&#x52D5;&#x7575;&#x7684;&#x6BCF;&#x4E00;&#x5E40;&#x9010;&#x6F38;&#x589E;&#x52A0;&#x3002;&#x5FAA;&#x74B0;&#x6703;&#x4E00;&#x76F4;&#x8DD1;&#x5230;x&#x8EF8;&#x5B8C;&#x6210;&#x4E94;&#x6B21;&#x5B8C;&#x6574;&#x7684;&#x5FAA;&#x74B0;&#x3002;&#x6BCF;&#x4E00;&#x6B65;&#x5B83;&#x90FD;&#x6703;&#x8ABF;&#x7528;SetColorIndex&#x4F86;&#x7232;(x, y)&#x9EDE;&#x4F86;&#x67D3;&#x9ED1;&#x8272;&#x3002;</p>
2015-12-28 08:08:26 +00:00
<p>main&#x51FD;&#x6578;&#x8ABF;&#x7528;&#x4E86;lissajous&#x51FD;&#x6578;&#xFF0C;&#x4F75;&#x4E14;&#x7528;&#x5B83;&#x4F86;&#x5411;&#x6A19;&#x6E96;&#x8F38;&#x51FA;&#x4E2D;&#x6253;&#x5370;&#x4FE1;&#x606F;&#xFF0C;&#x6240;&#x4EE5;&#x4E0B;&#x9762;&#x9019;&#x500B;&#x547D;&#x4EE4;&#x6703;&#x50CF;&#x5716;1.1&#x4E2D;&#x7523;&#x751F;&#x4E00;&#x500B;GIF&#x52D5;&#x7575;&#x3002;</p>
2015-12-24 06:47:06 +00:00
<pre><code>$ go build gopl.io/ch1/lissajous
2015-12-09 07:57:17 +00:00
$ ./lissajous &gt;out.gif
2015-12-24 06:47:06 +00:00
</code></pre><p><strong>&#x7DF4;&#x7FD2; 1.5&#xFF1A;</strong> &#x8129;&#x6539;&#x524D;&#x9762;&#x7684;Lissajous&#x7A0B;&#x5E8F;&#x91CC;&#x7684;&#x8ABF;&#x8272;&#x95C6;&#xFF0C;&#x7531;&#x7DD1;&#x8272;&#x6539;&#x7232;&#x9ED1;&#x8272;&#x3002;&#x6211;&#x5011;&#x53EF;&#x4EE5;&#x7528;color.RGBA{0xRR, 0xGG, 0xBB}&#x4F86;&#x5F97;&#x5230;#RRGGBB&#x9019;&#x500B;&#x8272;&#x503C;&#xFF0C;&#x4E09;&#x500B;&#x5341;&#x516D;&#x9032;&#x88FD;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x5206;&#x522B;&#x4EE3;&#x8868;&#x7D05;&#x3001;&#x7DD1;&#x3001;&#x85CD;&#x50CF;&#x7D20;&#x3002;</p>
<p><strong>&#x7DF4;&#x7FD2; 1.6&#xFF1A;</strong> &#x8129;&#x6539;Lissajous&#x7A0B;&#x5E8F;&#xFF0C;&#x8129;&#x6539;&#x5176;&#x8ABF;&#x8272;&#x95C6;&#x4F86;&#x751F;&#x6210;&#x66F4;&#x8C50;&#x5BCC;&#x7684;&#x9854;&#x8272;&#xFF0C;&#x7136;&#x5F8C;&#x8129;&#x6539;SetColorIndex&#x7684;&#x7B2C;&#x4E09;&#x500B;&#x53C3;&#x6578;&#xFF0C;&#x770B;&#x770B;&#x986F;&#x793A;&#x7D50;&#x679C;&#x5427;&#x3002;</p>
2015-12-09 07:57:17 +00:00
</section>
</div>
</div>
</div>
2015-12-21 04:55:18 +00:00
<a href="../ch1/ch1-03.html" class="navigation navigation-prev " aria-label="Previous page: 査找重複的行"><i class="fa fa-angle-left"></i></a>
2015-12-09 07:57:17 +00:00
2015-12-28 08:08:26 +00:00
<a href="../ch1/ch1-05.html" class="navigation navigation-next " aria-label="Next page: 獲取URL"><i class="fa fa-angle-right"></i></a>
2015-12-09 07:57:17 +00:00
</div>
</div>
<script src="../gitbook/app.js"></script>
<script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
<script>
require(["gitbook"], function(gitbook) {
2015-12-28 08:08:26 +00:00
var config = {"katex":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
2015-12-09 07:57:17 +00:00
gitbook.start(config);
});
</script>
</body>
</html>