CodingTrain / CodingTrain/Suggestion-Box

slow array

オープン
#282 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
言語のデータがありません
スター
570
フォーク
85
PR マージ指標
30日以内にマージされた PR はありません

説明

Hey guys,

So I am writing a code that puts the values of the X and Y location of the mouse in array and then uses those values to draw a stroke (curve), but what happens is that after a few moments the program becomes really slow and the values aren't stored properly in the array anymore. I know this is because the array is becoming to big because is said for(...) { draw this curve} but is there anyone who could help me out on how I could solve this?

Thank you in advance, here is the `code;`

`// the two arrays that store the values of the position of the mouse
mouseposx = [];
mouseposy = [];

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

}

function draw() {
background(0);

//make var for array that puts all values in array
for (var i = mouseposx.length ; i >= 0; i--) {

//if the mouse is stopped do not put new values in array
if (mouseX !== pmouseX && mouseY !== pmouseY) {

//put values of the position of the mouse in the array
mouseposx.push(mouseX);
mouseposy.push(mouseY);

}

// draw the curve of where the mouse has been
noFill();
stroke(255);
curve(mouseposx[i], mouseposy[i], mouseposx[i + 1], mouseposy[i + 1], mouseposx[i + 2], mouseposy[i + 2], mouseposx[i + 3], mouseposy[i + 3] );

}

}`

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

inline の setup() と draw() の例から始め、特に mouseposx と mouseposy の配列、および curve() を囲むループを確認します。描画中の遅延を再現し、そのうえで、マウスのストロークを維持しながら配列や描画ループが際限なく増大するのを防ぐ変更を特定します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
frontend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
20/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。