CodingTrain / CodingTrain/Suggestion-Box
slow array
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 570
- Fork
- 85
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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] );
}
}`
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu với ví dụ inline về setup() và draw(), đặc biệt là các mảng mouseposx và mouseposy cùng vòng lặp quanh curve(). Tái hiện sự chậm lại khi vẽ, sau đó xác định thay đổi nào ngăn các mảng hoặc vòng lặp vẽ tăng lên không giới hạn mà vẫn giữ lại nét vẽ của chuột.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- frontend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 20/100