LoginSignup
0
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-05-20

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

getItem()

説明文

storeItem() を使用してローカルストレージに保存したアイテムの値を取得します。

ローカルストレージとは、ブラウザに保存され、ブラウジングセッションとページの再読み込みの間も保持されているものです。

構文

getItem(key)

パラメタ

  • key
    String:ローカルストレージに保存するために使用した名前

戻り値

Number | Object | String | Boolean | p5.Color | p5.Vector:保存されたアイテムの値

例1

// マウスをクリックすると背景色が変わります
// 色を変更した後、ページをリロードしても色は変わりません
// (変更した背景色はローカルストレージに保存してあるため)
let myColor;

function setup()  {
   createCanvas(100, 100);

   // key "myColor" にはまだ一度も保存していないので NULL を取得
   myColor = getItem('myColor'); 
 }

function draw()  {
   if (myColor !== null) {
     background(myColor);
   }
 }

// マウスをクリックすると呼ばれる
function mousePressed()  {
   myColor = color(random(255), random(255), random(255));

  //  random() で求めた color を key "myColor" に保存
   storeItem('myColor', myColor);
 }

実行結果

著作権

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