![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
今回の記事の目的はProcessingの「textAscent()
」を理解し、自分なりに使ってみること。
この記事を書いた人
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-user-profile-illustrationi-light-blue.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-user-profile-illustrationi-light-blue.png)
- クリエイティブコーディングで制作した作品と、上達のためにやったこと・学習過程を発信
- コンセプトは「クリエイティブコーディング1万時間の歩き方」
- 2024年にProcessingの構文のアウトプットを終え、2025年から作品制作開始(クリエイティブコーディングで作成した作品集)
目次
【Processing】textAscent()について
textAscent()について
- textAscentは、「テキストの上昇」という意味
textAscent()
は、文字を表示する時に、その文字の一番上の部分がどれくらいの高さにあるかを計算してくれる- 文字を正しく配置するために役立ちます。例えば、複数の文字を上下に揃えたいときなどに便利
- 【注意点】文字のフォントやサイズによって結果が変わるので、注意が必要です。
【Processing】textAscent()の使い方【画像とコード】
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/11/processing-textascent-how-to-calculate-text-height1.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/11/processing-textascent-how-to-calculate-text-height1.png)
// フォント "Arial" をサイズ 32 で作成し、変数 myFont に保存
PFont myFont = createFont("Arial", 32);
// 作成したフォント myFont を使用するように設定
textFont(myFont);
// 文字の一番上の高さを計算して変数 height に保存
float height = textAscent();
// "Hello" というテキストを、x座標 10, y座標 height の位置に表示
text("Hello", 10, height);
【Processing】textAscent()を使ってみた感想
テキストを使った表現をするときに、textAscent()
の使用を考えます。
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
それでは今日もレッツワクワクコーディング。