Strange reoccurring pixel sorting artifacts. Could I get some help?

I have a 2D array of pixels, size is WIDTH × HEIGHT.

Each coordinate will get a random int between 0 and 255.

On each draw loop, I call the move() function, which gets the coordinates of the lowest neighbor (up, down, left, right, if lower than the source coordinates)

For example, in this table, the middle would be swapped with the bottom.

- 181 -
212 127 63
- 41 -

However, in this example, the middle would swap with itself (unchanged) because it itself is the lowest:

- 147 -
32 12 91
- 127 -

Processing doesn't seem to always commit the changes to the 2D array. Running the code as-is seems to leave quite a bit of artifacts in the form of squiggly lines.

Anyone know what's up?

int[][] pix; void setup() { size(600, 600); pix = new int[width][height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { pix[i][j] = floor(random(256)); } } } void draw() { swaps = 0; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { move(i,j); } } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { set(i,j,color(pix[i][j])); } } } void move(int x, int y){ boolean left = false; boolean right = false; boolean up = false; boolean down = false; int first = pix[x][y]; int xTarget = x; int yTarget = y; int min = pix[x][y]; if(x == 0) left = true; if(y == 0) up = true; if(x == width-1) right = true; if(y == height-1) down = true; if(!left){ if(pix[x-1][y] < min){ xTarget = x-1; yTarget = y; min = pix[x-1][y]; } } if(!right){ if(pix[x+1][y] < min){ xTarget = x+1; yTarget = y; min = pix[x+1][y]; } } if(!up){ if(pix[x][y-1] < min){ xTarget = x; yTarget = y-1; min = pix[x][y-1]; } } if(!down){ if(pix[x][y+1] < min){ xTarget = x; yTarget = y+1; min = pix[x][y+1]; } } pix[xTarget][yTarget] = first; pix[x][y] = min; } 
submitted by /u/MrMusAddict
[link] [comments]

Having trouble with SinOsc

My professor wanted us to create the sound of a bell using Processing (Java), but my code refuses to work. Not sure what went wrong honestly...

import processing.sound.*; int harmonics = 30; SinOsc[] bell = new SinOsc[harmonics]; void setup() { size(500, 500); float freq = 400; float amp = 1/harmonics; float add = 0.0; float pos = 0; for (int i=0; i<harmonics; i++) { //settaggio dei parametri bell[i] = new SinOsc(this); if (i%2==0) { bell[i].set((i+1)*freq, amp, add, pos); } else { bell[i].set((i+1)*freq + random(-200, 200), amp, add, pos); } } for (int i = 0; i < harmonics; i++) { bell[i].play(); } Env envShort; Env envLong; float attackTime1 = 0.00001; float attackTime2 = 0.000023; float sustainTime1 = 0.0; float sustainTime2 = 0.0; float sustainLevel1 =0.2; float sustainLevel2 = 0.4; float releaseTime1 = 0.3; float releaseTime2 = 1.0; envShort = new Env(this); envLong = new Env(this); for (int i = 0; i < harmonics; i++) { if (i < (harmonics/2)) { envLong.play(bell[i], attackTime2, sustainTime2, sustainLevel2, releaseTime2); } else { envShort.play(bell[i], attackTime1, sustainTime1, sustainLevel1, releaseTime1); } } } void draw() { } 
submitted by /u/alessansia
[link] [comments]

How to make a triangle grow congruently as the mouseX moves. Ex. when the mouseX increases, the triangle grows, and as it decreases, the triangle shrinks. I thought that you could just substitute it in the float values, however, either it jitters, grows exponentially, or remains static. Thanks much.

int pulse = 15; int pulsedim = 1; float x1 = 200; float y1 = 200; float x2 = x1 + 50; float y2 = 200; float x3 = (x1 + x2)/2; float y3 = (50*sqrt(3)/2)+200; float toggle = 1; void setup() { size(1920, 600); background(217, 217, 217); } void draw() { background(219, 219, 219); triangle(x1, y1, x2, y2, x3, y3); 

//subtract 86.6025403784 to first x (200) and divide by 2. //1) //25(sqrt3) = 86.6025403784 //2) //200 + (86.6025403784/2) //3) // = 243.301270189

x1 -= toggle; y1 -= toggle; x2 += toggle; y2 -= toggle; y3 += toggle * sqrt(3)/2; if (x1<177 || x1>223) { toggle *= -1; } int diam = abs(mouseX - width); color bgroundm = (color) (norm(diam, width, 0) * 400); 

//******************************** if (pulse > 60) { //* pulsedim = 0; //* } else if (pulse < 1) { //* Just true/false statements for pulse pulsedim = 1; //* } //* //********************************

//******************************** if (pulsedim == 1) { //* pulse = pulse+1; //* } else if (pulsedim == 0) { //* Just true/false statements for pulse pulse = pulse-1; //* } //* //******************************** }

void mouseMoved() { redraw(); } 
submitted by /u/vickerswt
[link] [comments]

I am working on a project to make a triangle shrink and grow. I thought my if statements were correct, but nothing seems to be working. Thanks for those who help!

int pulse = 15; int pulsedim = 1;

float x1 = 200; float y1 = 200; float x2 = x1 + 50; float y2 = 200; float x3 = (x1 + x2)/2; float y3 = (50*sqrt(3)/2)+200;

void setup(){ size(1920,600); background(217,217,217); }

void draw(){

background(219,219,219); triangle(x1,y1,x2,y2,x3,y3); //subtract 86.6025403784 to first x (200) and divide by 2. //1) //25(sqrt3) = 86.6025403784 //2) //200 + (86.6025403784/2) //3) // = 243.301270189

x1 = x1 - 1; y1 = y1 - 1; x2 = x2 + 1; y2 = y2 - 1; y3 = y3 + 1;

if (x1<177){ x1 = x1 - 1; y1 = y1 - 1; x2 = x2 + 1; y2 = y2 - 1; y3 = y3 + 1; }

else if (x1>223){ x1 = x1 + 1; y1 = y1 + 1; x2 = x2 - 1; y2 = y2 + 1; y3 = y3 - 1; }

int diam = abs(mouseX - width);

color bgroundm = (color) (norm(diam, width, 0) * 400);

//******************************** if (pulse > 60) { //* pulsedim = 0; //* } else if (pulse < 1) { //* Just true/false statements for pulse pulsedim = 1; //* } //* //********************************

//******************************** if (pulsedim == 1) { //* pulse = pulse+1; //* } else if (pulsedim == 0) { //* Just true/false statements for pulse pulse = pulse-1; //* } //* //********************************

}

void mouseMoved(){ redraw(); }

submitted by /u/vickerswt
[link] [comments]

Photography and its ghostly footprints

If you find yourself in Amsterdam these days, don’t miss the fascinating exhibition Back to the Future at FOAM. I actually wish i could go back and visit it a second time.


Taiyo Onorato and Nico Krebs, Light of Other days


Taiyo Onorato and Nico Krebs, Light of Other days

The show draws parallels between the nineteenth century pioneers of photography who experimented with the technological and visual potential of the medium and today’s artists who are following in their footsteps by inventing new ways to use the materiality and processes of photography.

There’s a lot to dig through, learn and applaud in that show but i’m going to be my best lazy blogger today and pick up only one work: Taiyo Onorato and Nico Krebs‘s 2012 series Light of Other days.

Their haunting images were made by placing light-sensitive silver gelatin paper in a large analogue camera, resulting in direct and unique positive images. With exposure times sometimes longer than a minute and the help of electric drills to rattle the scenes, they create enigmatic images swirling whirlpools or produce a bright starry sky in their studio.

The combination of the qualities of the positive photographic paper and the impossibility to fully control the oddly staged happenings evokes 19th century’s attempts to photographically capture paranormal activities.


Taiyo Onorato and Nico Krebs, Light of Other days


Taiyo Onorato and Nico Krebs, Light of Other days


Taiyo Onorato and Nico Krebs, Light of Other days

Back to the Future is at FOAM in Amsterdam until 28 March 2018. The exhibition will travel in an adapted version to C/O Berlin, Germany in September.

What’s up with stroke weight on 2d shapes in 3d?

I want to create a circle that has a thick outline that is rotated in 3d.

I have code for it that seems reasonable. However, my code produces some weird results: when I have a non-one stroke weight, it shows something like a second half circle on top of half of the main circle. I'm not sure how to describe it, but it seems like a bug to me.

Here's my code:

void setup() { size(300, 300, P3D); } void draw() { strokeWeight(10); background(127); translate(150, 150); rotateY(1.0); shape(createShape(ELLIPSE, 0, 0, 200, 200)); } 

(I'm on Processing 3.3.6 on macOS)

submitted by /u/gbear605
[link] [comments]

Programming for Artists