![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
今回の記事の目的はProcessingの「PVector
」を理解し、自分なりに使ってみること。
この記事を書いた人
![](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】PVectorについて
PVectorについて
- PVectorは「ポイント(位置)やベクトル(方向と速さ)」を意味する
- PVectorは、物体の位置や動きを表すためのツール
- ボールの位置や速度を計算するのに使う
【Processing】PVectorの使い方【画像とコード】
![【Processing】PVectorの使い方【画像とコード】](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/11/using-pvector-in-processing-representing-object-position-and-motion1.gif)
![【Processing】PVectorの使い方【画像とコード】](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/11/using-pvector-in-processing-representing-object-position-and-motion1.gif)
PVector location = new PVector(100, 100); // ボールの初期位置を設定
PVector velocity = new PVector(2, 3); // ボールの初期速度を設定
void setup() {
size(400, 400); // ウィンドウのサイズを設定
}
void draw() {
background(255); // 背景を白に設定
location.add(velocity); // 位置に速度を追加してボールを動かす
if (location.x > width || location.x < 0) { // ボールが画面の左右端に達したら
velocity.x *= -1; // 横方向の速度を反転
}
if (location.y > height || location.y < 0) { // ボールが画面の上下端に達したら
velocity.y *= -1; // 縦方向の速度を反転
}
ellipse(location.x, location.y, 20, 20); // ボールを現在の位置に描く
}
【Processing】PVectorを使ってみた感想
PVectorってかっこいい言葉だなって思いました。
![](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)
それでは今日もレッツワクワクコーディング。