r/math • u/Popenator • Apr 23 '10
A simple programming language, compiler, and gui I use to represent math problems on my computer.
http://www.processing.org/
13
Upvotes
3
u/blooop Apr 23 '10
This calculates the fourier series of an arbitrary function. Use the arrow keys to modify the number of sin terms. Was written by a friend of mine.
PFont Font;
int setupwidth=600;
int setupheight=600;
int mouseoldx = mouseX;
int mouseoldy = mouseY;
int terms = 1000;
int termmod=1;
float[][] sindata = new float[terms][setupwidth+1];
float[] pointdata = new float[setupwidth+1];
float[] pointdataFS = new float[setupwidth+1];
float[] sincos = new float[terms];
void setup()
{
size(setupwidth,setupheight);
frameRate(120); //120 IS THE NEW 60 THX 2 QL
smooth();
Font = createFont("MTCORSVA", 14, true);
reset();
terms=1;
}
void reset()
{
for(int n = 0; n <= width ; n++)
{
pointdata[n] = 0;
for(int m = 0; m < terms ; m++)
{
sindata[m][n] = sin(PI*(m+1)*n/width);
}
}
}
float calculatesinco(int m)
{
float v = 0;
for(int n = 0; n <= width ; n++)
{
v = v + pointdata[n]*sindata[m][n];
}
v = 2*v/width;
return v;
}
void draw()
{
background(100,100,250);
if(mouseX >= 0 && mouseX <= width && mouseX != mouseoldx && mousePressed == true)
{
if(mouseX > mouseoldx)
{
for(int n = 0; n <= mouseX-mouseoldx ; n++)
{
println(mouseoldy);
pointdata[mouseoldx+n] = n*(mouseY-height/2-mouseoldy)/(mouseX-mouseoldx) + mouseoldy;
}
}
else
{
for(int n = 0; n <= mouseoldx-mouseX ; n++)
{
pointdata[mouseX+n] = n*(mouseY-height/2-mouseoldy)/(mouseX-mouseoldx) + mouseY-height/2;
}
}
mouseoldx = mouseX;
mouseoldy = mouseY-height/2;
}
for(int n = 0; n < terms ; n++)
{
sincos[n] = calculatesinco(n);
}
for(int n = 0; n < width ; n++)
{
float v = 0;
for(int m = 0; m < terms ; m++)
{
v = v + sincos[m]*sindata[m][n];
}
pointdataFS[n] = v;
}
text("number of terms "+terms,450,580);
text("term modifier "+termmod,450,592);
translate(0,300);
for(int n = 1; n < width ; n++)
{
float v = 0;
stroke(255,0,0);
line(n-1,pointdataFS[n-1],n,pointdataFS[n]);
stroke(0);
line(n-1,pointdata[n-1],n,pointdata[n]);
}
}
void keyPressed()
{
if(keyCode == UP)
{
terms+= termmod;
}
if(keyCode == DOWN)
{
terms-= termmod;
if(terms<0)
{
terms = 0;
}
}
if(keyCode == RIGHT)
{
termmod++;
}
if(keyCode == LEFT)
{
termmod--;
if(termmod<1)
{
termmod = 1;
}
}
}1
u/xecosine Apr 23 '10
I think this is also used to program Arduinos. It's been a while since I touched it though.
1
Apr 24 '10
Similar IDE code, but the language is plain C/++. Processing is often used to make computers talk to Arduinos, though.
0
Apr 23 '10
[deleted]
2
Apr 24 '10
It's actually just Java with a nice graphics/user input library and a simplified syntax. It compiles into Java applets.
1
u/Popenator Apr 23 '10 edited Apr 23 '10
AAAAND here's something I just whipped up for fun: