LoginSignup
0
0

More than 3 years have passed since last update.

P5.js 日本語リファレンス(p5.NumberDict)

Last updated at Posted at 2020-05-24

このページでは「P5.js 日本語リファレンス」 の p5.NumberDict クラスを説明します。

p5.NumberDict

説明文

Numbers の単純な Dictionary クラス。p5.TypedDict を継承・拡張します。

構文

new p5.NumberDict()

メソッド

  • add()

    指定されたキーに現在格納されている値に、指定された数値を追加します。結果は以前にディクショナリに保存された値を置き換えます。

  • sub()

    指定されたキーに現在格納されている値から、指定された数値を減算します。結果は差分は以前にディクショナリに格納された値を置き換えます。

  • mult()

    指定されたキーに現在格納されている値に、指定された値を掛けます。結果は以前にディクショナリに保管された値を置き換えます。

  • div()

    指定されたキーに現在格納されている値に、指定された値で割ります。結果は、商は以前にディクショナリに保存された値を置き換えます。

  • minValue()

    辞書に現在格納されている最小の数を返します。

  • maxValue()

    辞書に現在保存されている最大の数を返します。

  • minKey()

    辞書で現在使用されている最も低いキーを返します。

  • maxKey()

    辞書で現在使用されている最も高いキーを返します。

function setup() {

  // キー 100 に 1 を設定して、p5.NumberDict のオブジェクトを生成
  let myDict = createNumberDict(100, 1);

  myDict.add(100, 2);  // キー 100 に 2 を加算
  print(myDict.get(100));  // キー 100 の値をコンソールに表示

  myDict.set(101, 4);  // キー 101 に 4 を保存

  print(myDict.maxValue()); // コンソールに最大値である 4 を表示
}

実行結果

著作権

p5.js was created by Lauren McCarthy and is developed by a community of collaborators, with support from the Processing Foundation and NYU ITP. Identity and graphic design by Jerel Johnson.

ライセンス

Creative Commons(CC BY-NC-SA 4.0) に従います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0