func speakText(graphic: Graphic) {
speak(graphic.text)
}
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
}
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)
}
let fruitTool = Tool(name: "Fruit", emojiIcon: "🍒")
fruitTool.onFingerMoved = addFruit(touch:)
scene.tools.append(fruitTool)
let greetingTool = Tool(name: "Greeting", emojiIcon: "🙏")
greetingTool.onFingerMoved = addGreeting(touch:)
scene.tools.append(greetingTool)
let speakTool = Tool(name: "話す", emojiIcon: "😄")
speakTool.onGraphicTouched = speakText(graphic:)
scene.tools.append(speakTool)