Toggle navigation
Explora
(current)
Aprende
Crea
Retos
×
Aspectos básicos
void main() {...}
for ( int i = 0 ; i < N ; i++ ) {...}
while (condición) {...}
do {...} while (condición);
if (condición) {...}
if (condición) {...} else {...}
switch (valor) {...}
Mostrar y pedir datos
print()
println()
readInteger()
readDouble()
readChar()
readString()
Funciones matemáticas
abs(n)
log(n)
sqrt(n)
pow(b,e)
floor(n)
ceil(n)
round(n)
sin(n)
cos(n)
tan(n)
asin(n)
acos(n)
atan(n)
random(n)
Funciones gráficas
point(x,y)
line(x1,y1,x2,y2)
ellipse(x,y,w,h)
rect(x,y,w,h)
triangle(x1,y1,x2,y2,x3,y3)
text(msg,x,y)
textWidth(msg)
textSize(n)
background(r,g,b,a)
strokeWeight(n)
stroke(r,g,b,a)
noStroke()
fill(r,g,b,a)
noFill()
image(url, x,y,w,h)
Nuevo
Ayuda
Probar
...
final int SS = 320; // Screen size const final boolean DEBUG = true; class Color { private double r; private double g; private double b; private double a; private Color(double r, double g, double b, double a) { this.r = r; this.g = g; this.b = b; this.a = a; } public static Color of(double r, double g, double b, double a) { return new Color(r,g,b,a); } public static Color of(double r, double g, double b) { return new Color(r,g,b,0); } public double getR() { return this.r; } public double getB() { return this.b; } public double getG() { return this.g; } public double getA() { return this.a; } } class DrawUtil { public static void Rect(double x, double y, double sizeX, double sizeY, Color color) { fill(color.getR(), color.getG(), color.getB(), color.getA()); rect(x, y, sizeX, sizeY); noFill(); } public static void Rect(double x, double y, double sizeX, double sizeY) { rect(x, y, sizeX, sizeY); } public static void Rect(int x, int y, int sizeX, int sizeY) { rect(x, y, sizeX, sizeY); } public static void Line(double x1, double y1, double x2, double y2, Color color) { stroke(color.getR(), color.getG(), color.getB(), color.getA()); line(x1,y1,x2,y2); noStroke(); } public static void Line(double x1, double y1, double x2, double y2) { line(x1,y1,x2,y2); } public static void Line(int x1, int y1, int x2, int y2) { line(x1,y1,x2,y2); } public static void Ellipse(int x, int y, int w, int h) { ellipse(x,y,w,h); } public static void Ellipse(double x, double y, double w, double h) { ellipse(x,y,w,h); } public static void Ellipse(double x, double y, double w, double h, Color color) { fill(color.getR(), color.getG(), color.getB(), color.getA()); ellipse(x,y,w,h); noFill(); } public static void Text(String msg, int x, int y, int size) { textSize(size); text(msg, x, y); } public static void Text(String msg, double x, double y, int size) { textSize(size); text(msg, x, y); } public static void Text(int msg, int x, int y, int size) { textSize(size); text(msg, x, y); } public static void Text(int msg, double x, double y, int size) { textSize(size); text(msg, x, y); } public static void Text(String msg, double x, double y, int size, Color color) { textSize(size); fill(color.getR(), color.getG(), color.getB(), color.getA()); text(msg, x, y); noFill(); } public static void Text(int msg, double x, double y, int size, Color color) { textSize(size); fill(color.getR(), color.getG(), color.getB(), color.getA()); text(msg, x, y); noFill(); } } class DebugUtil { private static void Log(String message) { println(message); } public static void Log(String level, String message) { switch (level) { case "i": Log("[INFO] " + message); break; case "d": if (DEBUG) Log("[DEBUG] " + message); break; case "w": Log("[WARNING] " + message); break; case "e": Log("[ERROR] " + message); break; case "f": Log("[FATAL] " + message); break; default: break; } } public static void DrawGridLines() { if (DEBUG) { int steps = 16; for (int i = 0; i <= steps; i++) { double pos = SS / steps * i; // x1 y1 x2 y2 DrawUtil.Line(pos, 0, pos, SS, Color.of(145,145,145,0.2)); DrawUtil.Line(0, pos, SS, pos, Color.of(145,145,145,0.2)); DebugUtil.Log("d", "V-Line " + i + " created with pos: (X1:" + pos + ",Y1:" + 0 + ",X2:" + pos + ",Y2" + SS + ")."); DebugUtil.Log("d", "H-Line " + i + " created with pos: (X1:" + 0 + ",Y1:" + pos + ",X2:" + SS + ",Y2" + pos + ")."); } } } } /* * La función random() genera un número al azar en el rango definido por el número que pongamos entre paréntesis. * Ejemplo: * - x=random(100) --> genera un número al azar entre 0 y 100 */ void DrawLinesFromCenter() { final int STARS_N = 20; for (int i = 0; i < STARS_N; i++) { int c = SS/2; Color color; color = Color.of(random(0,255),random(0,255),random(0,255)); DrawUtil.Line(c, c, random(0,SS-1), random(0,SS-1), color); } } void main() { DebugUtil.Log("d", "Debug mode is enabled"); background(0,50,50,0); DrawLinesFromCenter(); DebugUtil.DrawGridLines(); }
Canvas not supported.
Programado por
TheZocki
0 votos
4 descargas
0 usos