闪电生成器

· · 个人记录

静态:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2005;
const int dx[] = {0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0};
const int dy[] = {1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1};

int n, m, x, y;
char a[N][N];
mt19937 gen(time(0));

int main(){
    ios::sync_with_stdio(false), cin.tie(0);
    n = 60, m = 235;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            a[i][j] = ' ';
        }
    }
    int T = 30;
    for(int i = 1; i <= T; i++){
        x = 1, y = 1;
        while(x < n || y < m){
            int l = gen();
            if(i * 3 <= T){
                l %= 11;
                l += 11;
                l %= 11;
            }
            else if(i / 2 * 3 <= T){
                l %= 7;
                l += 7;
                l %= 7;
            }else{
                l %= 4;
                l += 4;
                l %= 4;
            }
            int x2 = x + dx[l], y2 = y + dy[l];
            if(x2 <= n && y2 <= m){
                if(l == 0 || l > 3){
                    a[x2][y2] = '-';
                }
                else if(l == 1 || l == 3){
                    a[x2][y2] = '\\';
                }else{
                    a[x2][y2] = '|';
                }
                x = x2, y = y2;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << a[i][j];
        }
        cout << '\n';
    }
    return 0;
}
/*
60 235

*/

动态:

#include <bits/stdc++.h>
#include <windows.h>

using namespace std;
using ll = long long;

const int N = 2005;
const int dx[] = {0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0};
const int dy[] = {1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1};

int n, m, x, y;
char a[N][N];
mt19937 gen(time(0));

int main(){
    ios::sync_with_stdio(false), cin.tie(0);
    n = 60, m = 235;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            a[i][j] = ' ';
        }
    }
    int T = 30;
    for(int i = 1; i <= T; i++){
        x = 1, y = 1;
        while(x < n || y < m){
            int l = gen();
            if(i * 3 <= T){
                l %= 11;
                l += 11;
                l %= 11;
            }
            else if(i / 2 * 3 <= T){
                l %= 7;
                l += 7;
                l %= 7;
            }else{
                l %= 4;
                l += 4;
                l %= 4;
            }
            int x2 = x + dx[l], y2 = y + dy[l];
            if(x2 <= n && y2 <= m){
                if(l == 0 || l > 3){
                    a[x2][y2] = '-';
                }
                else if(l == 1 || l == 3){
                    a[x2][y2] = '\\';
                }else{
                    a[x2][y2] = '|';
                }
                x = x2, y = y2;
            }
        }
        system("cls");
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                cout << a[i][j];
            }
            cout << '\n';
        }
        Sleep(5);
    }
    return 0;
}
/*
60 235

*/