Skip to content

Instantly share code, notes, and snippets.

@albertochiwas
Last active September 23, 2015 00:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save albertochiwas/da3721e3b0b4f17f6d8b to your computer and use it in GitHub Desktop.
Save albertochiwas/da3721e3b0b4f17f6d8b to your computer and use it in GitHub Desktop.
Ver. 0.1 Fracciones
final int SZ = 32;
float num = 1;
float den = int(random(2,4));
float frac = num / den;
String display = "";
String[] keys = {
"7", "8", "9",
"4", "5", "6",
"1", "2", "3",
"-", "0", "="
};
int[] x = {
100, 150, 200,
100, 150, 200,
100, 150, 200,
100, 150, 200
};
int y[] = {
100, 100, 100,
150, 150, 150,
200, 200, 200,
250, 250, 250
};
void setup() {
size(400,400);
}
void tecla( String txt, int x, int y ) {
fill(220, 220, 240);
rect(x, y, SZ, SZ, 8);
fill(0);
textSize(16);
text(txt, x+12, y+20);
}
void teclado() {
for (int i=0; i<12; i++) {
tecla(keys[i],x[i], y[i]);
}
}
void draw() {
background(255);
teclado();
fill(240);
rect(80,10,170,32,8);
fill(0);
textSize(40);
text(""+int(num)+" / "+int(den), 230, 330);
if ( display.length() > 0 ) {
fill(0);
textSize(24);
text(display, 120, 40);
}
}
boolean inside( int x, int y ) {
return mouseX>=x && mouseX<=(x+SZ) && mouseY>=y && mouseY<=(y+SZ);
}
void mouseClicked() {
for (int i=0; i<11; i++) {
if (inside(x[i],y[i])) {
if ( display.length()==0 ) {
display = "0." + keys[i];
} else {
display += keys[i];
}
return;
}
}
if ( inside(x[11],y[11]) ) { // enter
float user = Float.parseFloat(display);
if ( user == frac ) {
display = "Ganaste!!";
} else if ( user < frac ) {
display = "mas grande";
} else {
display ="mas chico";
}
}
}
@Aether919
Copy link

Ya le puse audio, para ver el código y saber como hacerlo funcionar vayan a:

https://gist.github.com/Aether919/cc523d2183442527455c

o den click en donde dice "fork" y ahí aparecerá mi nombre de usuario con el código modificado. Saludos.

@albertochiwas
Copy link
Author

Well done @Aether919

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment