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
...
class vector { double x;double y;double z; public vector(double nx,double ny){x = nx;y = ny;z = 0;} public vector(double nx,double ny,double nz){x = nx;y = ny;z = nz;} } vector p[] = { new vector(1, -1, -1), new vector(1, 1, -1), new vector(1, 1, 1), new vector(1, -1, 1), new vector(-1, -1, -1), new vector(-1, 1, -1), new vector(-1, 1, 1), new vector(-1, -1, 1) }; int l[][] = { {0, 4}, {4, 5}, {0, 0},//{5, 0}, {0, 0},//{4, 3}, {3, 0}, {3, 7}, {7, 4}, {0, 1}, {1, 5}, {1, 2}, {2, 6}, {6, 5}, {2, 3}, {0, 0},//{3, 1}, {6, 7}, {0, 0},//{7, 2}, {0, 0},//{4, 6}, {0, 0}//{1, 6} }; int utp[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }; int ox[] = utp; int perspective[][] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 0}}; int size = 40; double ax = 0; double ay = 0; double az = 0; int lx = 0; int ly = 0; double crt = 0.1; void bresenhamLine(double x1, double y1, double x2, double y2) { int d = 0; //strokeWeight(3); int dx = round(abs(x2 - x1)); int dy = round(abs(y2 - y1)); int dx2 = 2 * dx; int dy2 = 2 * dy; int ix = x1 < x2 ? 1 : -1; int iy = y1 < y2 ? 1 : -1; double x = x1; double y = y1; if (dx >= dy) { while (true) { point(x, y); if (floor(x) == floor(x2)) break; x += ix; d += dy2; if (d > dx) { y += iy; d -= dx2; } } } else { while (true) { point(x, y); if (floor(y) == floor(y2)) break; y += iy; d += dx2; if (d > dy) { x += ix; d -= dy2; } } } } double atan2(double y, double x) { double u = atan(y/x); if( x < 0.0 ) { if( u > 0.0 ) u -= PI; else u += PI; } return u; } vector rotateZ(vector base) { return new vector((base.x*cos(az)) + (base.y*(-sin(az))), (base.x*sin(az)) + (base.y*cos(az)), base.z); } vector rotateY(vector base) { return new vector((base.x*cos(ay))+(base.z*sin(ay)), (base.y), (base.x*(-sin(ay))) + (base.z*cos(ay))); } vector rotateX(vector base) { return new vector((base.x), (base.y*cos(ax)) + (base.z*(-sin(ax))), (base.y*sin(ax)) + (base.z*cos(ax))); } vector rotate(vector bass) { return rotateX(rotateY(rotateZ(bass))); } vector getPoint(vector base) { return new vector((base.x*perspective[0][0]) + (base.y*perspective[0][1]) + (base.z*perspective[0][2]), (base.x*perspective[1][0]) + (base.y*perspective[1][1]) + (base.z*perspective[1][2])); } void main() { animate(draw); } double dist(vector p1, vector p2) { return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2) + pow(p1.z - p2.z, 2)); } vector avg(vector p1, vector p2) { return new vector((p1.x+p2.x)/2, (p1.y+p2.y)/2, (p1.z+p2.z)/2); } double fullDist = dist(new vector(-1, -1, -1), new vector(1, 1, 1)); double factor = 1; double max(double a, double b) { return a>b?a:b; } double min(double a, double b) { return a
= 0; i--) { if (utp[i] > -1) { draw3Dline(l[utp[i]][0], l[utp[i]][1]); } } } int uk = 0; double getDist(int line) { int p1 = l[line][0]; int p2 = l[line][1]; return (dst(p1)+dst(p2))/2; } void orderPoints() { int c; for (int i = 0; i < 17*18; i++) { int i2 = i % 17; int a = utp[i2]; int b = utp[i2+1]; if (getDist(b) > getDist(a)) { utp[i2+1] = a; utp[i2] = b; } } } void draw() { double mx = mouseX; vf = mx/320; background(20); stroke(51, 255, 51); fill(51, 255, 51); utp = ox; strokeWeight(1); text("RX: " + round((ax/PI)*180), 0, 20); text("RY: " + round((ay/PI)*180), 0, 40); text("RZ: " + round((az/PI)*180), 0, 60); draw3Dobject(); //ax += 0.03; //ay += 0.02; //az += 0.01; orderPoints(); if (keyPressed) { if (key == "a") { ax += PI/360; } if (key == "z") { ax -= PI/360; } if (key == "s") { ay += PI/360; } if (key == "x") { ay -= PI/360; } if (key == "d") { az += PI/360; } if (key == "c") { az -= PI/360; } if (key == "up") { size += 7; } if (key == "down") { size -= 7; } size = max(0, size); } stroke(0); for (int y = 0; y < 320; y += 2) { line(0, y, 319, y); } }
Canvas not supported.
Programado por
segfaultdev
2 votos
218 descargas
36 usos