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 maxwalls = 1024; // 1024 walls per map class point2D { double x; double y; point2D(double _x, double _y) { x = _x; y = _y; } point2D add(point2D b) { return new point2D(x + b.x, y + b.y); } } point2D intersect(point2D p1, point2D p2, point2D p3, point2D p4) { double x1 = p1.x; double y1 = p1.y; double x2 = p2.x; double y2 = p2.y; double x3 = p3.x; double y3 = p3.y; double x4 = p4.x; double y4 = p4.y; if ((x1 == x2 && y1 == y2) || (x3 == x4 && y3 == y4)) { return null; } double denominator = ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)); if (denominator == 0.0) { return null; } double ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denominator; double ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denominator; if (ua < 0 || ua > 1 || ub < 0 || ub > 1) { return null; } double x = x1 + ua * (x2 - x1); double y = y1 + ua * (y2 - y1); return new point2D(x, y); } double dist(point2D p1, point2D p2) { return sqrt(pow(p1.x-p2.x, 2) + pow(p1.y-p2.y, 2)); } class wall2D { point2D p1; point2D p2; double height; double zpos; wall2D(point2D _p1, point2D _p2, double _zpos, double _height) { p1 = _p1; p2 = _p2; height = _height; zpos = _zpos; } } wall2D walls[] = new wall2D[maxwalls]; int wallcount = 0; void main() { animate(draw, 10); } // red, yellow, green, cyan, blue, purple final int reds[] = { 255, 255, 255, 127, 0, 0, 0, 0, 0, 127, 255, 255 }; final int greens[] = { 0, 127, 255, 255, 255, 255, 255, 127, 0, 0, 0, 0 }; final int blues[] = { 0, 0, 0, 0, 0, 127, 255, 255, 255, 255, 255, 127 }; double offx = 0; double offy = 0; double scale = 20; boolean pmousePressed = false; double setheight = 1; point2D point1; point2D point2; void draw() { background(0); strokeWeight(6); stroke(255); for (int i = -10; i < 10; i++) { for (int j = -10; j < 10; j++) { point(160 + (i + offx) * scale, 160 + (j + offy) * scale); } } for (int i = 0; i < wallcount; i++) { double height = walls[i].height; stroke(reds[floor(height*4)-1], greens[floor(height*4)-1], blues[floor(height*4)-1]); line(160 + (walls[i].p1.x + offx) * scale, 160 + (walls[i].p1.y + offy) * scale, 160 + (walls[i].p2.x + offx) * scale, 160 + (walls[i].p2.y + offy) * scale); } if (mousePressed && !pmousePressed) { if (keyPressed) { if (key == " ") { println("wall2D walls[] = {"); for (int i = 0; i < wallcount; i++) { print(" new wall2D(new point2D("); print(walls[i].p1.x); print(", "); print(walls[i].p1.y); print("), new point2D("); print(walls[i].p2.x); print(", "); print(walls[i].p2.y); print("), "); print(walls[i].zpos); print(", "); print(walls[i].height); print("\)"); if (i < wallcount - 1) { print(","); } println(); } println("};"); } } else { point1 = new point2D(round((mouseX - 160) / scale - offx), round((mouseY - 160) / scale - offy)); } } if (!mousePressed && pmousePressed) { point2 = new point2D(round((mouseX - 160) / scale - offx), round((mouseY - 160) / scale - offy)); wall2D wall = new wall2D(point1, point2, setheight, setheight); walls[wallcount++] = wall; } strokeWeight(12); stroke(reds[floor(setheight*4)-1], greens[floor(setheight*4)-1], blues[floor(setheight*4)-1]); point(160 + offx * scale, 160 + offy * scale); // Player start point pmousePressed = mousePressed; if (keyPressed) { if (key == "º") { setheight = 0.25; } else if (key == "1") { setheight = 0.50; } else if (key == "2") { setheight = 0.75; } else if (key == "3") { setheight = 1.00; } else if (key == "4") { setheight = 1.25; } else if (key == "5") { setheight = 1.50; } else if (key == "6") { setheight = 1.75; } else if (key == "7") { setheight = 2.00; } else if (key == "8") { setheight = 2.25; } else if (key == "9") { setheight = 2.50; } else if (key == "0") { setheight = 2.75; } else if (key == "'") { setheight = 3.00; } } }
Canvas not supported.
Programado por
segfaultdev
1 votos
141 descargas
30 usos