Need help in exporting svg from animation

Dear All,
I have the code pasted below and I am trying to export SVG file from animation.
Here’s Simplex Noise code I am using: opensimplexnoise.pde · GitHub
I am trying to paste code dedicated by Processing: SVG Export / Libraries / Processing.org
but it don’t work.

I would highly appreciated your help!

OpenSimplexNoise noise;

int result;
float t, c;

float ease(float p) {
return 3pp - 2pp*p;
}

float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2p, g);
else
return 1 - 0.5 * pow(2
(1 - p), g);
}

float mn = .5*sqrt(3), ia = atan(sqrt(.5));

void push() {
pushMatrix();
pushStyle();
}

void pop() {
popStyle();
popMatrix();
}

void draw() {

if (!recording) {
t = mouseX1.0/width;
c = mouseY
1.0/height;
if (mousePressed)
println(c);
draw_();
} else {
for (int i=0; i<width*height; i++)
for (int a=0; a<3; a++)
result[i][a] = 0;

c = 0;
for (int sa=0; sa<samplesPerFrame; sa++) {
  t = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1);
  draw_();
  loadPixels();
  for (int i=0; i<pixels.length; i++) {
    result[i][0] += pixels[i] >> 16 & 0xff;
    result[i][1] += pixels[i] >> 8 & 0xff;
    result[i][2] += pixels[i] & 0xff;
  }
}

loadPixels();
for (int i=0; i<pixels.length; i++)
  pixels[i] = 0xff << 24 | 
    int(result[i][0]*1.0/samplesPerFrame) << 16 | 
    int(result[i][1]*1.0/samplesPerFrame) << 8 | 
    int(result[i][2]*1.0/samplesPerFrame);
updatePixels();

saveFrame("fr###.png");
println(frameCount,"/",numFrames);
if (frameCount==numFrames)
  exit();

}
}

//////////////////////////////////////////////////////////////////////////////

int samplesPerFrame = 1;
int numFrames = 40;
float shutterAngle = .8;

boolean recording = true;

void setup(){
size(800,800);
result = new int[width*height][3];

noise = new OpenSimplexNoise();
}

int N = 70;
float b = 50;
float l = 15;
float scl = 0.01;
float r = 0.2;

void draw_(){
background(208, 209, 199);

stroke(0);
strokeWeight(1);
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
float x = map(i,0,N-1,b,width-b);
float y = map(j,0,N-1,b,height-b);
float theta = 15*(float)noise.eval(sclx,scly,rcos(TWO_PIt),rsin(TWO_PIt));
float vx = lcos(theta);
float vy = l
sin(theta);
float intensity = 0.1+1.5ease(map((float)noise.eval(200+sclx,scly,rcos(TWO_PIt),rsin(TWO_PIt)),-1,1,0,1),3.5);
vx
=intensity;
vy*=intensity;
line(x,y,x+vx,y+vy);
}
}
saveFrame(“output/image####.gif”);

}

I came up with an idea to ask chat got, and it works. The code’s below if anyone need it:
import processing.svg.*;

OpenSimplexNoise noise;

int result;
float t, c;

float ease(float p) {
return 3pp - 2pp*p;
}

float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2p, g);
else
return 1 - 0.5 * pow(2
(1 - p), g);
}

float mn = .5*sqrt(3), ia = atan(sqrt(.5));

void push() {
pushMatrix();
pushStyle();
}

void pop() {
popStyle();
popMatrix();
}

// Flaga do kontrolowania eksportu SVG
boolean exportSVG = true;

void draw() {

if (!recording) {
t = mouseX1.0/width;
c = mouseY
1.0/height;
if (mousePressed)
println(c);
draw_();
} else {
for (int i=0; i<width*height; i++)
for (int a=0; a<3; a++)
result[i][a] = 0;

c = 0;
for (int sa=0; sa<samplesPerFrame; sa++) {
  t = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1);
  draw_();
  loadPixels();
  for (int i=0; i<pixels.length; i++) {
    result[i][0] += pixels[i] >> 16 & 0xff;
    result[i][1] += pixels[i] >> 8 & 0xff;
    result[i][2] += pixels[i] & 0xff;
  }
}

loadPixels();
for (int i=0; i<pixels.length; i++)
  pixels[i] = 0xff << 24 | 
    int(result[i][0]*1.0/samplesPerFrame) << 16 | 
    int(result[i][1]*1.0/samplesPerFrame) << 8 | 
    int(result[i][2]*1.0/samplesPerFrame);
updatePixels();

saveFrame("fr###.png");
println(frameCount,"/",numFrames);
if (frameCount==numFrames)
  exit();

}
}

//////////////////////////////////////////////////////////////////////////////

int samplesPerFrame = 1;
int numFrames = 40;
float shutterAngle = .8;

boolean recording = true;

void setup(){
size(800,800);
result = new int[width*height][3];

noise = new OpenSimplexNoise();

// Rozpoczynamy zapis SVG, jeśli flaga jest ustawiona
if (exportSVG) {
beginRecord(SVG, “output-####.svg”);
}
}

int N = 70;
float b = 50;
float l = 15;
float scl = 0.01;
float r = 0.2;

void draw_(){
background(208, 209, 199);

stroke(0);
strokeWeight(1);
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
float x = map(i,0,N-1,b,width-b);
float y = map(j,0,N-1,b,height-b);
float theta = 15*(float)noise.eval(sclx,scly,rcos(TWO_PIt),rsin(TWO_PIt));
float vx = lcos(theta);
float vy = l
sin(theta);
float intensity = 0.1+1.5ease(map((float)noise.eval(200+sclx,scly,rcos(TWO_PIt),rsin(TWO_PIt)),-1,1,0,1),3.5);
vx
=intensity;
vy*=intensity;
line(x,y,x+vx,y+vy);
}
}

if (exportSVG) {
// Zakończenie zapisu do SVG po zakończeniu rysowania
endRecord();
exportSVG = false; // Wyłączamy eksport SVG po pierwszej klatce
noLoop(); // Zatrzymujemy animację po zapisaniu pierwszej klatki SVG
}

saveFrame(“output/image####.gif”);
}

1 Like

Hello @Heliasz and welcome to the forum! To improve readability, kindly format your code by editing your post, selecting the code, and pressing the </> button. This will make it easier for us to assist you.

ezgif.com-gif-maker (1)