-
-
Save jkwok91/792f621c22c5e9b22582 to your computer and use it in GitHub Desktop.
sin waves and such
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
sin theta-- test | |
april 14, 2014 | |
*/ | |
float theta, vOff; | |
int r; | |
boolean dots; | |
void setup() { | |
size(300, 300); | |
reset(); | |
r = 20; | |
dots = false; | |
vOff = width/2; | |
text("click to alternate",0,20); | |
} | |
void reset() { | |
background(0); | |
theta = 0; | |
} | |
void draw() { | |
getMethod(); | |
theta = (theta+1)%width; | |
} | |
void getMethod() { | |
if (dots) { | |
drawDots(vOff); | |
} | |
else { | |
drawPx(vOff); | |
} | |
} | |
void drawDots(float vOffset) { | |
background(0); | |
for (int i = 0; i < width; i+=10) { | |
stroke(255); | |
fill(0); | |
ellipse(i, r*sin(0.05*theta+i*10)+vOffset, 10, 10); | |
} | |
} | |
void drawPx(float vOffset) { | |
loadPixels(); | |
float y = r*sin(0.05*theta)+vOffset; //vertical shift, baby! MQ6-- still got it | |
int coor = (int)y*width+(int)theta; | |
pixels[coor] = color(255); | |
updatePixels(); | |
} | |
void mousePressed() { | |
dots = !dots; | |
reset(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
quick sine wave | |
*/ | |
float theta; | |
void setup() { | |
size(300,300); | |
background(0); | |
theta = 0; | |
} | |
void draw() { | |
background(0); | |
stroke(255); | |
for (int i = 0; i < height/20; i++) { | |
for (int j = 0; j < width; j++) { | |
ellipse(j, 10*sin(.05*j-theta+i*(3*PI/16))+(i*25), 1,1); | |
} | |
} | |
theta = (theta+0.5)%TWO_PI; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment