#include "libwasm.h" #include "drawings.h" #include "complex.h" //using namespace std; /*********************************************************************************/ void BackGround::drawings() { const real maxx = getMaxX(), maxy = getMaxY(); fill (Color(0, 0, 0, 0xFF)); const real hx = 0.5 * maxx, margin = 5.0; const Matrix m (hx-2.0*margin, 0.0, 0.0, -(maxy-2*margin), hx, maxy - margin); setMatrix (m); setColor (Color (0x60, 0x60, 0x60)); const real st = 0.1; for (real x=-1.0; x<+1.0; x+=st) { line (FPoint(+x,-1.0), FPoint(+x,+1.0), true); } for (real y=st; y<1.0; y+=st) { line (FPoint(-1.0,+y), FPoint(+1.0,+y), true); } setColor (Color (0x80, 0x80, 0)); line (FPoint(-1.0, 0.0), FPoint(1.0, 0.0)); line (FPoint( 0.0, 0.0), FPoint(0.0, 1.0)); FPoint o (-1.0, 1.0); setColor (Color (0xFF, 0xFF, 0)); for (real x=-1.0; x<+1.0; x+=0.05) { const real y = x * x; FPoint n (x, y); line (o, n); o = n; } } /////////////////////////////////////////////////////////////////////////////////// void ForeGround::drawings() { const real maxx = getMaxX(), maxy = getMaxY(); fill (Color(0xFF, 0xFF, 0xFF, 0)); const real hx = 0.5 * maxx, margin = 5.0, zx = hx - 2.0 * margin, ix = 1.0 / zx; const Matrix m (zx, 0.0, 0.0, -(maxy - 2 * margin), hx, maxy - margin); setMatrix (m); const double w = 6.0; for (real a=-1.0; a<+1.0; a+=ix) { const double x = w * a; const double y = probality (x); const double cz = y * 255.0; int c = 0; if (cz > 255.0) c = 0xFF; else if (cz < 0.0) c = 0; else c = cz; setColor (Color(c, 0xFF -c, 0xFF - c, 0xE0)); line (FPoint (a, 0.0), FPoint (a, y)); } } /** * Výpočty vlnových funkcí viz * https://www.aldebaran.cz/studium/tf.pdf str. 142, * časový vývoj tamtéž str. 182, výraz (2.183) * */ double ForeGround::probality (const double x) const { double H [NumWeight]; // Hermitovy polynomy H [0] = 1.0; H [1] = 2.0 * x; for (unsigned n=2; n y *= fac; // |Ψ> psi += y; // sčítají se komplexní vlnové funkce } return psi.abs(); // vrací se <Ψ*|Ψ> } void ForeGround::normalize() { index = 0; speed = 1u; double fact = 1.0, pow2 = 1.0; const double hp = sqrt (M_PI); for (unsigned n=0; n je pro všechna |n> stejná (mělo by být 1) normals [n] = 1.0 / sqrt (hp * fact * pow2); const double m = n + 1; fact *= m; pow2 *= 2.0; } } void ForeGround::step() { drawings(); phase(); index += speed; } void ForeGround::phase() { complex c, o (-0.8, 0.9); c.exp (index); c *= 0.1; c += o; const FPoint a (o.re, o.im), b (c.re, c.im); setColor (Color(0xFF, 0x80, 0, 0xFF)); line (a, b); }