ランダムな楕円が7列にわたって連続して描画されています。しかし、行配列内のどこにでも楕円の数をランダムに描画するのではなく、それらを描画したいので、列1の楕円の1つが列2の楕円の1つに接触する必要があります。最後のビジュアルは、異なるバーの高さでアニメーション化するが、楕円の配列を使用してバーグラフのように見えます。この画像に似ています。 graphランダムにピクセルの特定の場所にアクセスする処理
私の作業コードは以下のとおりです。 rowArray [i]が黒いピクセルの隣にあるかどうかを比較するためのif条件を実行するか、ここで見落としている簡単な方法がありますか?すべての助けに感謝します。ありがとう。
PImage pix = createImage(7, 7, RGB);
int counter = 0;
int counter2 = 0;
int y = 0;
int x = 0;
int rowArray[ ] = {0, 1, 2, 3, 4, 5, 6, 7};
int colArray[ ] = {0, 1, 2, 3, 4, 5, 6, 7};
int frameDelay = 300; //pause 400 ms between frames being sent to the board
float dot = 0;
int count;
void setup() {
background(0);
size(500, 500);
dot = height/7.0;
pix.loadPixels();
for (int i = 0; i < pix.pixels.length; i++) {
pix.pixels[i] = color(0);
}
pix.updatePixels();
noStroke();
ellipseMode(CORNER);
}
void draw() {
//boolean dot = false;
//randomSeed(0);
pix.loadPixels();
if (counter > pix.height) {
counter = 0;
y ++;
}
if (counter2 > pix.width) {
counter2 = 0;
x ++;
//also refesh screen after one round
refresh();
}
//reset-don't go beyond pixel boundaries
if (x > pix.width) {
x = 0;
}
if (y > pix.height) {
y = 0;
}
for (int j = 0; j < pix.width; j++) {
if (j==counter2) {
for (int i = 0; i < pix.height; i++) {
if (i == counter) {
//random height
i = int(random(rowArray.length)); // Same as int(random(i))
y=i;
x=j;
//draw the white circles
stroke(64);
strokeWeight(1);
fill(255);
noStroke();
ellipse(x*dot, y*dot, dot, dot);
}
}
}
}
counter++;
counter2++;
pix.updatePixels();
pix.loadPixels();
delay (frameDelay);
}
void refresh() {
background(0);
}
/EDIT !!!!!/ 私は、いくつかの不要なループがあるので、コードを合理化しました。今、ピクセル[loc]を使用して、白と黒のピクセルの位置を決定し、そこから進みます。
EDITED CODE
PImage pix = createImage(7, 7, RGB);
int counter = 0;
//int randCount=0;
int counter2 = 0;
int y = 0;
int x = 0;
//int randCount[ ] = {0, 1, 2, 3, 4, 5, 6};
int randCount[ ] = new int[7];
//int rowArray[ ] = {0, 1, 2, 3, 4, 5, 6, 7};
int frameDelay = 300; //pause 400 ms between frames being sent to the board
float dotSize = 0;
void setup() {
background(0);
size(500, 500);
dotSize = height/7.0;
//make all dots black on start
pix.loadPixels();
for (int i = 0; i < pix.pixels.length; i++) {
pix.pixels[i] = color(0);
}
pix.updatePixels();
noStroke();
ellipseMode(CORNER);
}
void draw() {
// boolean dot = false;
pix.loadPixels();
//bitshift values from array
int row1 = 0;
int row2 = 0;
int row3 = 0;
int row4 = 0;
int row5 = 0;
int row6 = 0;
int row7 = 0;
//randomise how many dots are displayed in the row
int index = int(random(randCount.length));
counter=index;
if (counter > pix.height) {
counter = 0;
y ++;
}
if (counter2 > pix.width) {
counter2 = 0;
x ++;
}
//reset-don't go beyond pixel boundaries
if (x > pix.width) x = 0;
if (y > pix.height) y = 0;
//sequence dots row by row
for (int i = 0; i < pix.height; i++) {
if (i == counter) {
//y is i
y=i;
//draw the white circles representing flipdots
stroke(64);
strokeWeight(1);
fill(255);
noStroke();
ellipse(x*dotSize, y*dotSize, dotSize, dotSize);
}
}
if (x==7) {
//also refesh screen after one round
refresh();
}
counter++;
counter2++;
detect();
pix.updatePixels();
pix.loadPixels();
delay (frameDelay);
}
//screen refresh
void refresh() {
background(0);
y=0;
x=0;
}
void detect() {
//pixel location
int loc = x + y*pix.height;
// Pixel to the left location and color
int leftLoc = (x - 1) + y*pix.width;
// Pixel to the right location and color
int rightLoc = (x + 1) + y*pix.width;
// Pixel to the left location and color
int downLoc = (x - 1) + y*pix.height;
// Pixel to the right location and color
int upLoc = (x + 1) + y*pix.height;
//is the pixel white?
if ((pix.pixels[loc]==255)&&(pix.pixels[leftLoc]==255)&&(pix.pixels[rightLoc]==255)&&(pix.pixels[downLoc]==255)&&(pix.pixels[upLoc]==255)) {
y++;
// x++;
} else {
y--;
}
}
私は本当にあなたが何を求めているのか分かりません。一般的な「どのようにこれを行うのか」のタイプの質問を手伝うのは本当に難しいです。あなたが特定の質問をした場合、あなたはもっと良い運を得られるでしょう。あなたは[あなたの問題をより小さなものに分割する](http://happycoding.io/tutorials/how-to/program)して、一度に1つずつ取り上げる必要があります。あなたが特定の作品にこだわっている場合は、その作品の[mcve]を投稿することができます。がんばろう。 –
私の質問の表現を改善する良い教訓です。申し訳ありませんが、私が自分でカバーした段階と、ここに投稿されたときにどのように翻訳されるのかは、当然のことです。あなたのアドバイスに基づいて、私は以下の答え(コメント内の限られた文字のため)で私の作業を分解しました。 – user2187427