We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
Haven't done any programming in a while, and i'm trying to create an expanding cloud based on any pixel's proximity to a pixel which is black in a certain radius. The effect is sort of what I'm after, but it drifts backwards and doesn't seem able to test forward from black pixels? It should disperse uniformly in all directions. See image attached. What am I doing wrong?
int pixelCount;
color testTone;
void setup() {
// size(1280,720);
size(800,800);
background(255);
rectMode(CENTER);
fill(255);
stroke(0);
strokeWeight(5);
rect(width/2, height/2, 100, 100);
pixelCount = width*height;
testTone = color(0);
}
void draw() {
loadPixels();
buildPixels();
updatePixels();
rect(width/2, height/2, 100, 100);
// exit();
}
void buildPixels() {
color[] builtPixels = new color[pixelCount];
for(int x=0;x<width;x++) {
for(int y=0;y<height;y++) {
int loc = x+y*width;
if(testPixel(x, y, loc, int(random(5)+1))==true) {
builtPixels[loc] = testTone;
} else {
builtPixels[loc] = color(255);
}
}
}
for(int i=0;i<pixelCount;i++) {
pixels[i] = builtPixels[i];
}
}
boolean testPixel(int x, int y,int loc, int range) {
int testToneDetectionCount = 0;
boolean testToneDetected = false;
//is there a neighbouring filled pixel?
int offset = range/2;
for(int i=0;i<range;i++) {
for(int j=0;j<range;j++) {
int xTest = x + i*offset;
int yTest = y + j*offset;
int testLoc = xTest + yTest*width;
testLoc = constrain(testLoc,0,pixelCount-1);
if(pixels[testLoc]==testTone) {
testToneDetectionCount++;
}
}
}
return boolean(testToneDetectionCount);
}
Answers
Sorry everybody, I'm just stupid and it was a simple thing to fix. Is it possible to delete a post?
Rule of thumb: Never delete a post on a forum. Others might need the information. You never know...
So instead, I know I didn't answer your question in any way, but just mark this post as the answer.
Also, to make a post effective, submit the solution as well.
And to answer your question directly, only the moderators can delete posts, but it's usually because of spam. So no.
Sorry, couldn't resist to try this out. :)