大宮盆栽デイズ - Omiya Bonsai Days -

パイロットになれなかった人の「それから」。

しゃべるグラフィック@コードを学ぼう3

// しゃべるグラフィック@コードを学ぼう3
// Speak the text of graphic.
func speakText(graphic: Graphic) {
    speak(graphic.text)
}

// With the Fruit tool selected, this function is called each time your finger moves.
func addFruit(touch: Touch) {
    if touch.previousPlaceDistance < 60 { return }
    let fruit = "🍏🍐🍊🍋🍉🍒🍓🍌".componentsByCharacter()
    let graphic = Graphic(text: fruit.randomItem)
    scene.place(graphic, at: touch.position)
    graphic.scale = 1.5
}

// With the Greeting tool selected, this function is called each time your finger moves.
func addGreeting(touch: Touch) {
    if touch.previousPlaceDistance < 60 { return }
    let greetings = ["howdy!", "hello", "hi", "ciao", "yo!", "hey!", "what’s up?"]
    let greeting = greetings.randomItem
    let graphic = Graphic(text: greeting)
    graphic.textColor = #colorLiteral(red: 0.9686274529, green: 0.78039217, blue: 0.3450980484, alpha: 1)
    graphic.fontName = .chalkduster
    scene.place(graphic, at: touch.position)
    graphic.rotation = randomDouble(from: -30, to: 30)
}

// Create and add Fruit tool.
let fruitTool = Tool(name: "Fruit", emojiIcon: "🍒")
fruitTool.onFingerMoved = addFruit(touch:)
scene.tools.append(fruitTool)

// Create and add Greeting tool.
let greetingTool = Tool(name: "Greeting", emojiIcon: "🙏")
greetingTool.onFingerMoved = addGreeting(touch:)
scene.tools.append(greetingTool)

// Create and add Speak tool.

let speakTool = Tool(name: "話す", emojiIcon: "😄")
speakTool.onGraphicTouched = speakText(graphic:)
scene.tools.append(speakTool)