Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(tl) cerr<<#tl<<' '<<tl<<'\n';
- #include <iostream>
- #include <vector>
- #include <stdio.h>
- #include <math.h>
- using namespace std;
- #define all(d) d.begin(), d.end()
- typedef long double ld;
- namespace d2 {
- struct Vec {
- ld x, y;
- Vec(ld c) :x(c), y(c) {};
- Vec(ld _x, ld _y) : x(_x), y(_y) {};
- Vec operator+(const Vec& other) { return Vec(x + other.x, y + other.y); }
- Vec operator-(const Vec& other) { return Vec(x - other.x, y - other.y); }
- Vec operator*(const Vec& other) { return Vec(x * other.x, y * other.y); }
- Vec operator/(const Vec& other) { return Vec(x / other.x, y / other.y); }
- ld len() {
- return sqrtl(x * x + y * y);
- }
- ld len2() {
- return (x * x + y * y);
- }
- Vec norm() {
- ld d = len();
- return Vec(x / d, y / d);
- }
- };
- }
- namespace d3 {
- struct Vec {
- ld x, y, z;
- Vec(ld c) : x(c), y(c), z(c) {};
- Vec(ld _x, d2::Vec const& v) : x(_x), y(v.x), z(v.y) {};
- Vec(ld _x, ld _y, ld _z) : x(_x), y(_y), z(_z) {};
- Vec operator+(Vec const& other) { return Vec(x + other.x, y + other.y, z + other.z); }
- Vec operator-(Vec const& other) { return Vec(x - other.x, y - other.y, z - other.z); }
- Vec operator*(Vec const& other) { return Vec(x * other.x, y * other.y, z * other.z); }
- Vec operator/(Vec const& other) { return Vec(x / other.x, y / other.y, z / other.z); }
- Vec operator-() { return Vec(-x, -y, -z); }
- ld len() {
- return sqrtl(x * x + y * y + z * z);
- }
- ld len2() {
- return (x * x + y * y + z * z);
- }
- Vec norm() {
- ld d = len();
- return Vec(x / d, y / d, z / d);
- }
- };
- }
- ld get(const d3::Vec& a, const d3::Vec& b) {
- return a.x * b.x + a.y * b.y + a.z * b.z;
- }
- d2::Vec intersection_shere(const d3::Vec& ro, const d3::Vec rd, ld r) {
- ld a = get(ro, rd), b = get(ro, ro) - r * r;
- ld c = a * a - b;
- if (c < 0.000)return d2::Vec(-1.0);
- c = sqrtl(c);
- return d2::Vec(-a - c, -a + c);
- }
- signed main() {
- /*
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- */
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int w = 120, h = 30;
- ld k1 = (ld)w / h, k2 = 11.00/24.00;
- char* scr = new char[w * h + 1];
- vector<char> gr = { ' ','.', ':', '!', 'r', 'l','1','Z','4','H','9','W','8','@' };
- scr[w * h] = '\0';
- for (int d = 0; d < 1e5; d++) {
- d3::Vec sun(sin(d * 0.003), cos(d * 0.003), -1.0);
- sun.norm();
- for (int i = 0; i < w; i++) {
- for (int j = 0; j < h; j++) {
- d2::Vec p(i, j), sc(w, h);
- p = p / sc * 2.0 - 1.0;
- p.x *= k1 * k2;
- d3::Vec camera(-2, 0, 0), to(1, p);
- to = to.norm();
- int ind = 0;
- d2::Vec ins = intersection_shere(camera, to, 1);
- if (ins.x > 0) {
- d3::Vec it = camera + to * ins.x;
- it = it.norm();
- ind = (int)(get(it, sun) * 14);
- }
- scr[i + j * w] = gr[max(min(ind, (int)gr.size() - 1), 0)];
- }
- }
- printf(scr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement