7 개의 열에 걸쳐 순차적으로 행에 임의의 타원이 그려져 있습니다. 그러나 행 배열 내의 임의의 위치에 임의로 타원 수를 그리는 대신 열만있는 타원 중 하나가 두 열의 타원 중 하나를 만지도록 위치 만 그리면 위치간에 틈이 없어집니다. 마지막 비주얼은 막대 그래프와 같이 보이지만 다른 막대 높이에서 애니메이션을 만들지 만 타원 배열을 사용하면 그렇게 할 수 있습니다. 이 이미지와 비슷합니다. graph임의의 픽셀의 특정 위치에 액세스하는 처리 Array
내 작업 코드는 다음과 같습니다. 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);
}
/편집 !!!!!/ 일부 불필요한 루프가 있으므로 코드를 간소화했습니다. 이제 픽셀 [loc]을 사용하여 흰색과 검정색 픽셀의 위치를 결정하고 거기에서부터 이동하십시오.
편집을 할 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--;
}
}
정말 당신이 무엇을 요구하는지 모르겠습니다. 일반적인 "어떻게해야합니까?"라는 질문을하는 것이 정말 어렵습니다. 특정 질문을하면 훨씬 더 나은 행운이 생길 것입니다. "X를 시도했는데 Y가 예상되었지만 Z가 대신 입력되었습니다."질문을 입력하십시오. 당신은 [작은 조각으로 당신의 문제를 깰 수] (http://happycoding.io/tutorials/how-to/program)하고 그 조각을 한 번에 하나씩 가져 가야합니다. 그런 다음 특정 곡에 붙어 있다면 그 곡의 [mcve]를 올릴 수 있습니다. 행운을 빕니다. –
제 질문의 표현을 개선하는 데 좋은 교훈입니다. 미안 해요. 제가 혼자서 다뤘던 단계와 여기에 올릴 때 어떻게 번역했는지 당연한 생각이었습니다.귀하의 조언을 바탕으로 나는 아래 답변에서 내 의견을 (제한된 문자로 인해) 세분화했습니다. – user2187427