テキストツール@コードを学ぼう3
文字化けを修正するのがたいへんなので、エディタのウィンドウを画像にして添えました。「コードを学ぼう3」では絵文字が多いので掲載しづらいです。
// テキストツール@コードを学ぼう3 let name = "blue mono" let things = ["green star", "black hole", "red giant", "white dwarf"] let colors = [#colorLiteral(red: 0.5843137503, green: 0.8235294223, blue: 0.4196078479, alpha: 1), #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1), #colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: 1), #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)] func addText(touch: Touch) { if touch.previousPlaceDistance < 80 { return } // Get index to a random item in things. let index = randomInt(from: 0, to: things.count - 1) // Create graphic with a string from the things array at index. let graphic = Graphic(text: things[index]) // Change the font name and size. graphic.fontName = .avenirNext graphic.fontSize = 25 // Set to color from the colors array at index. graphic.textColor = colors[index] scene.place(graphic, at: touch.position) }