# 第 17 章 【加碼單元】文本分析 - 了解文字藝術
https://www.notion.so/CCT-2-d436ce3e0f4c4e69b1b35fb7c3016371
文字藝術
圖像詩
將文字與意象做連結
```javascript=
function draw() {
fill(102, 216, 255)
textSize(random(5, 20))
let raintext = '下雨'
let rainLen = random(10)
for(var i = 0; i<raintext; i++){
raintext += '雨'
}
translate(random(width), random(height))
rotate(PI/4)
text(raintext, 0, 0)
}
```
用 translate rotate 來控制雨從水平變成傾斜
想像真實情境會有什麼東西,比如:雲、太陽,來設計他們之間的互動
## 單元 3 Rita.js
> 助教的話:
目前Rita.js有版本更新,直接引用 RiTa 會失敗,寫法都不同了
請參考新的範例:https://openprocessing.org/sketch/1307510
新的 api 使用方式也可以參考官方文件 https://rednoise.org/rita/index.html#reference
pos 詞性 (part of speech)
```javascript=
let result, words, pos
function setup() {
createCanvas(windowWidth, windowHeight);
result = new RiString(text);
words = result.words()
allPos = result.pos()
print(allPos)
background(0)
}
function draw() {
textSize(50)
fill(255)
let x = 50, y=100
for (var i = 0; i<words.length; i++){
let word = words[i]
let pos = allPos[i]
if(pos == 'nn') {
fill('red')
} else if (pos=='jj'){
fill('green')
} else {
fill('blue')
}
text(word, x, y)
x += textWidth(word)+20
if (x>width-100){
x = 50
y += 100
}
}
}
```
### 隨機文字使用 rita 的辭典 lexicon
```javascript=
word = lexicon.randomWord('nn')
```
可以把文字替換成表情符號
```javascript=
if (word=='fox') {
word = '🦊'
}
```
### 第 4 單元 - 文字合成語音操作
```javascript=
personVoice.speak(words[currentPos])
```
結巴斷詞
https://github.com/pulipulichen/jieba-js