We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello again, I'm trying to redraw over this 2D pixel array of this program.
// main setup settings
int dimy = 800; // screen width 1681
int dimx = 850; //screen height 1019
int bailout = 2000; // number of iterations before bail
int plots = 171294; // number of plots to execute per frame (x30 = plots per second) 171294
//zoom/magnification
float magx = 4.0; // default 3.0, smaller means more zoom
float magy = magx*(dimy/float(dimx));
//pan
float panx = 0.3; //default is 0.5
float pany = 0.0; //default is 0.0
//brightness multiplier
float brt = 1.0; // brightness factor
// 2D array to hold exposure values
int[] exposure = new int[dimx*dimy];
// maximum exposure value
int maxexposure;
int time = 0;
int exposures = 0;
float Ex = 2;
float x, y;
float x0, y0;
boolean drawing;
int sgn(float value) { //if signus is needed sgn(x)=x/abs(x) = 1, 0 or -1
if (value < 0) {return -1;}
if (value > 0) {return 1;}
return 0;
}
float cosh(float value1) {
return 0.5*(exp(value1)+exp(-value1));
}
float sinh(float value2) {
return 0.5*(exp(value2)-exp(-value2));
}
float arg(float axis1, float axis2) {
if (axis2==0) {return PI;}
else {return -atan(axis1/axis2)+PI*sgn(axis2)*0.5;}
}
float spharg(float axisa, float axisb, float axisc) {
return acos(axisc/sqrt(sq(axisa)+sq(axisb)+sq(axisc)));
}
void setup() {
// set up drawing area
size(800,850,P3D);
}
void draw() {
plotPlots();
time++;
if (time%1==0) { //every second
findMaxExposure();
// Infinitely Looping, nested boolean iteration(x0,y0,DrawIt)
renderBrot();
}
}
void plotPlots() {
// iterate through some plots
for (int n=0;n<plots;n++) {
// Choose a random point in same range
x = random(-2.0,2.0);
y = random(-2.0,2.0);
x0 = random(-2.0,2.0);
y0 = random(-2.0,2.0);
if (iterate(x,y,false)) {
//Pauses Boolean, (d=pause, D=start)
if (Ex > 1){
iterate(x,y,true);
exposures++;
}
if (Ex < 2){
iterate(x,y,false);
}
}
}
}
void renderBrot() {
colorMode(RGB,1.0);
// draw to screen
for (int i=0;i<dimx;i++) {
for (int j=0;j<dimy;j++) {
float ramp = brt * exposure[i*dimy+j] / maxexposure;
// blow out ultra bright regions
if (ramp > 1) {
ramp = 1;
}
//shading formulae
color c = color(pow(sin(ramp),0.4),pow(ramp,0.75),pow(ramp,2.5)); // sunset
set(j,i,c);
}
}
}
// Iterate the Mandelbrot and return TRUE if the point exits
// Also handle the drawing of the exit points
boolean iterate(float x0, float y0, boolean drawIt) {
float x = 0.0;
float y = 0.0;
//float t = random(0,1);
//float r = random(0,1);
//x0 = 0.0;
//y0 = 0.0;
float xnew, ynew;
int ix,iy;
for (int i=0;i<bailout;i++) {
// Display iterations before false DrawIt boolean
//if (i>0){
//println(i);
// }
//set your costum formula here...
//example:
//default Mandelbrot
xnew = x * x - y * y + x0;
ynew = 2 * x * y + y0;
// Draws pixel to screen -
// Based on if drawIt boolean is true, and iterations[i] > 3
// Defines and Draws Pixels in 2D Exposure Array
// Draws pixel when iteration[i] > 3 within current boolean cycle of xnew, ynew values
if (drawIt && (i > 3)) {
ix = int(dimx*(panx+xnew+magx/2.0)/magx);
iy = int(dimy*(pany+ynew+magy/2.0)/magy);
//Defines points (ix,iy) within screen ranges
if (ix >= 0 && iy >= 0 && ix < dimx && iy < dimy) {
// rotate and expose point
exposure[ix*dimy+iy]++;
}
}
if ((xnew*xnew + ynew*ynew) > 4) {
// escapes
return true;
}
x = xnew;
y = ynew;
}
// does not escape
return false;
}
void findMaxExposure() {
// assume no exposure
maxexposure=0;
// find the largest density value
for (int i=0;i<dimy;i++) {
for (int j=0;j<dimx;j++) {
maxexposure = max(maxexposure,exposure[i*dimx+j]);
}
}
}
void keyPressed(){
//Return Iterate(x0,y0,DrawIt) False in Plot
if (key == 'r') {
Ex = 1;
}
//Return Iterate(x0,y0,DrawIt) True in Plot
if (key == 'R') {
Ex = 2;
}
}
I've studied and tested many pixel array programs recently, but don't understand it enough to figure it out the exact method. I know the pixel array exposure[] is a 2D array within the looping, nested boolean iterate(x0,y0,drawIt) and that the pixel array output is derived from the specific code:
// Draws pixel to screen -
// Based on if drawIt boolean is true, and iterations[i] > 3
// Defines and Draws Pixels in 2D Exposure Array
// Draws pixel when iteration[i] > 3 within current boolean cycle of xnew, ynew values
if (drawIt && (i > 3)) {
ix = int(dimx*(panx+xnew+magx/2.0)/magx);
iy = int(dimy*(pany+ynew+magy/2.0)/magy);
//Defines points (ix,iy) within screen ranges
if (ix >= 0 && iy >= 0 && ix < dimx && iy < dimy) {
// rotate and expose point
exposure[ix*dimy+iy]++;
}
}
It's not a boolean true/false issue as the entire program is written in an infinite loop of nested booleans drawing, iterate(x0,y0,drawIt) and when halted either in the drawing section or the plotPlots() section the pixel array remains intact upon continuation of the program (as demonstrated with Keypressed 'r', 'R'). The program is well threaded into itself with it's booleans and I have no reason to change that fact.
How would I go about updating the entire pixel array in this program to a single color (black) upon key press? Blanking out the canvas and the program continuing it's constant pixel drawing process of exposure points on screen again without the old pixels.
Answers
There is a New forum
Please ask there