Skip to content

Instantly share code, notes, and snippets.

@Artoria2e5
Last active August 29, 2015 14:03
Show Gist options
  • Save Artoria2e5/fb2534d85fd6c5694e63 to your computer and use it in GitHub Desktop.
Save Artoria2e5/fb2534d85fd6c5694e63 to your computer and use it in GitHub Desktop.
sketch-bezier
void draw() {
// Clear
fill(127);
rect(0,250,500,25);
// println("DEBUG: rect-clear");
// Wave
fill(0, 255, 213);
beginShape();
for (int i = wave-150; i<=(wave+width+50); i += 50) {
println("DEBUG: (i % 100) == " + (i % 100));
println("DEBUG: (wave % 100) == " + (wave % 100));
curveVertex(i,(((i % 100) == (wave % 100)) ? 250 : 275));
}
endShape();
fill(255);
// Move
wave=(wave>100) ? 0 : wave+1;
// println("DEBUG: wave == " + wave);
// Be stupid
// Slow down!
if (mousePressed){
try {Thread.sleep(200);} catch (InterruptedException e){}
}
}
// http://forum.processing.org/two/discussion/4849/checkbox/p1
class Checkbox {
// Checkbox, 20-20
int x, y;
boolean b;
Checkbox(int _x, int _y){
x = _x;
y = _y;
b = false;
}
void render(){
stroke(255);
fill(isOver()?128:64);
rect(x, y, 20, 20);
if(b){
line(x, y, x+20, y+20);
line(x, y+20, x+20, y);
}
}
void click(){
if(isOver()){
b=!b;
}
}
boolean isOver(){
return(mouseX>x&&mouseX<x+20&&mouseY>y&&mouseY<y+20);
}
}
Checkbox foo = new Checkbox(40,10);
void setup(){
background(127);
smooth();
}
void draw(){
// This is a hello world
foo.render();
if (mousePressed){
foo.click();
}
}
// Inaccurate clone of http://www.w3schools.com/svg/svg_path.asp
size(450,400);
background(255);
fill(0);
ellipse(100,350,2,2);
ellipse(250,50,2,2);
ellipse(400,350,2,2);
stroke(255,0,0);line(100,350,250,50);line(250,50,400,350);
// stroke(0,255,0);line(175,200,325,200);
noFill();
stroke(0,0,255);
beginShape();
vertex(100,350);
bezierVertex(100,350,250,50,400,350);
endShape();
// Clone of https://www.khanacademy.org/cs/animated-waves/4601853285236736
int wave = 0;
void setup(){
size(500,500);
background(127);
noStroke();
}
void draw() {
// Clear
fill(127);
rect(0,250,500,25);
// println("DEBUG: rect-clear");
// Wave
fill(0, 255, 213);
beginShape();
curveVertex(wave-150,250);
curveVertex(wave-100,275);
curveVertex(wave-50,250);
curveVertex(wave+0,275);
curveVertex(wave+50,250);
curveVertex(wave+100,275);
curveVertex(wave+150,250);
curveVertex(wave+200,275);
curveVertex(wave+250,250);
curveVertex(wave+300,275);
curveVertex(wave+350,250);
curveVertex(wave+400,275);
curveVertex(wave+450,250);
curveVertex(wave+500,275);
curveVertex(wave+550,250);
endShape();
fill(255);
// Move
wave=(wave>100) ? 0 : wave+1;
// println("DEBUG: wave == " + wave);
// Be stupid
// Slow down!
if (mousePressed){
try {Thread.sleep(50);} catch (InterruptedException e){}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment