Add BoringGrid and Planes as drawing demonstrations.
This commit is contained in:
parent
c3d9698ede
commit
b11e096014
|
@ -4,9 +4,8 @@ import xyz.marsavic.functions.interfaces.A2;
|
||||||
import xyz.marsavic.functions.interfaces.F1;
|
import xyz.marsavic.functions.interfaces.F1;
|
||||||
import xyz.marsavic.gfxlab.*;
|
import xyz.marsavic.gfxlab.*;
|
||||||
import xyz.marsavic.gfxlab.elements.Output;
|
import xyz.marsavic.gfxlab.elements.Output;
|
||||||
import xyz.marsavic.gfxlab.graphics3d.raytracers.RayTracerSimple;
|
|
||||||
import xyz.marsavic.gfxlab.graphics3d.scene.SceneTest1;
|
|
||||||
import xyz.marsavic.gfxlab.gui.UtilsGL;
|
import xyz.marsavic.gfxlab.gui.UtilsGL;
|
||||||
|
import xyz.marsavic.gfxlab.playground.colorfunctions.Planes;
|
||||||
import xyz.marsavic.gfxlab.tonemapping.ColorTransform;
|
import xyz.marsavic.gfxlab.tonemapping.ColorTransform;
|
||||||
import xyz.marsavic.gfxlab.tonemapping.ToneMapping;
|
import xyz.marsavic.gfxlab.tonemapping.ToneMapping;
|
||||||
import xyz.marsavic.gfxlab.tonemapping.colortransforms.Multiply;
|
import xyz.marsavic.gfxlab.tonemapping.colortransforms.Multiply;
|
||||||
|
@ -28,11 +27,11 @@ public class GfxLab {
|
||||||
e(Fs::aFillFrameInt,
|
e(Fs::aFillFrameInt,
|
||||||
e(Fs::aFillFrameColor,
|
e(Fs::aFillFrameColor,
|
||||||
e(Fs::transformedColorFunction,
|
e(Fs::transformedColorFunction,
|
||||||
// e(Blobs::new, val(5), val(0.1), val(0.2)),
|
e(Planes::new),
|
||||||
e(RayTracerSimple::new,
|
/* e(RayTracerSimple::new,
|
||||||
e(SceneTest1::new)
|
e(SceneTest1::new)
|
||||||
),
|
),
|
||||||
e(TransformationsFromSize.toGeometric, eSize)
|
*/ e(TransformationsFromSize.toGeometric, eSize)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
e(Fs::toneMapping,
|
e(Fs::toneMapping,
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xyz.marsavic.gfxlab.playground.colorfunctions;
|
||||||
|
|
||||||
|
import xyz.marsavic.geometry.Vector;
|
||||||
|
import xyz.marsavic.gfxlab.Color;
|
||||||
|
import xyz.marsavic.gfxlab.ColorFunctionT;
|
||||||
|
|
||||||
|
public class BoringGrid implements ColorFunctionT {
|
||||||
|
@Override
|
||||||
|
public Color at(double t, Vector p) {
|
||||||
|
double linew = 0.01;
|
||||||
|
double gridw = 0.2;
|
||||||
|
return Color.gray((p.x() - linew/2)/gridw <= Math.floor((p.x() + linew/2)/gridw) ||
|
||||||
|
(p.y() - linew/2)/gridw <= Math.floor((p.y() + linew/2)/gridw) ?
|
||||||
|
0.9 : 0.05);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package xyz.marsavic.gfxlab.playground.colorfunctions;
|
||||||
|
|
||||||
|
import xyz.marsavic.geometry.Vector;
|
||||||
|
import xyz.marsavic.gfxlab.Color;
|
||||||
|
import xyz.marsavic.gfxlab.ColorFunctionT;
|
||||||
|
import xyz.marsavic.gfxlab.elements.Element;
|
||||||
|
import xyz.marsavic.utils.Defaults;
|
||||||
|
import xyz.marsavic.utils.Numeric;
|
||||||
|
|
||||||
|
|
||||||
|
public class Planes extends Element implements ColorFunctionT {
|
||||||
|
|
||||||
|
double speed = 5;
|
||||||
|
|
||||||
|
private double distance(double t) {
|
||||||
|
return speed * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
double ballSpace = 0.8;
|
||||||
|
FakeBall [] balls;
|
||||||
|
|
||||||
|
public static final Defaults<Planes> $ = Defaults.args();
|
||||||
|
|
||||||
|
private class FakeBall {
|
||||||
|
Color c = Color.rgb(Math.random(), Math.random(), Math.random());
|
||||||
|
double r = Math.random()/4+0.25;
|
||||||
|
double xOffset;
|
||||||
|
|
||||||
|
double maxHeight = Math.random()/2;
|
||||||
|
double minHeight = -Math.random()/2;
|
||||||
|
double phaseOffset = Math.random();
|
||||||
|
|
||||||
|
public FakeBall(int offset) {
|
||||||
|
this.xOffset = offset*ballSpace + Math.random()/5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double currentHeight(double t) {
|
||||||
|
return (Numeric.sinT(distance(t)+phaseOffset)+1)*(maxHeight-minHeight)/2+minHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector center(double t) {
|
||||||
|
return Vector.xy(xOffset+distance(t), currentHeight(t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Planes() {
|
||||||
|
int ballNum = 20;
|
||||||
|
|
||||||
|
balls = new FakeBall[ballNum];
|
||||||
|
for (int i = 0; i < ballNum; i++) {
|
||||||
|
balls[i] = new FakeBall(i-ballNum/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
ColorFunctionT ceil = new Blobs(5, 3.5, 0.2), floor = new BoringGrid();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Color at(double t, Vector p) {
|
||||||
|
for (FakeBall ball : balls) {
|
||||||
|
double distanceFromCenterSq = p.sub(ball.center(t)).length(),
|
||||||
|
rSqr = ball.r * ball.r;
|
||||||
|
if (distanceFromCenterSq < rSqr) {
|
||||||
|
return ball.c.mul((rSqr - distanceFromCenterSq) / rSqr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double infinity = 0.15;
|
||||||
|
if (p.y() > infinity) {
|
||||||
|
return ceil.at(t, Vector.xy(p.x()/(p.y()-infinity)-distance(t),
|
||||||
|
(1-p.y())/(p.y()-infinity)));
|
||||||
|
}
|
||||||
|
if (p.y() < -infinity) {
|
||||||
|
return floor.at(t, Vector.xy(p.x()/(-infinity-p.y())-distance(t),
|
||||||
|
(p.y()-(-1))/(-infinity-p.y())));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Color.BLACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue