source: trunk/tools/neercs/term/term.cpp @ 1856

Last change on this file since 1856 was 1856, checked in by sam, 8 years ago

neercs: create new Term and Pty classes that will contain the real stuff.

File size: 4.8 KB
Line 
1//
2// Neercs
3//
4
5#if defined HAVE_CONFIG_H
6#   include "config.h"
7#endif
8
9#include "core.h"
10#include "lolgl.h"
11
12using namespace std;
13using namespace lol;
14
15#include "../neercs.h"
16#include "term.h"
17
18Term::Term(ivec2 size)
19  : m_time(0.f)
20{
21    m_caca = caca_create_canvas(size.x, size.y);
22}
23
24void Term::TickGame(float seconds)
25{
26    Entity::TickGame(seconds);
27
28#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H
29    /* This is the real terminal code */
30    /* XXX: for now we draw fancy shit */
31    m_time += seconds;
32    DrawFancyShit();
33#else
34    /* Unsupported platform - draw some fancy shit instead */
35    m_time += seconds;
36    DrawFancyShit();
37#endif
38}
39
40void Term::TickDraw(float seconds)
41{
42    Entity::TickDraw(seconds);
43}
44
45Term::~Term()
46{
47}
48
49/*
50 * XXX: fancy shit below
51 */
52
53static uint32_t hex_color(float r, float g, float b)
54{
55    return ((uint32_t)(r * 15.99f) << 8) |
56           ((uint32_t)(g * 15.99f) << 4) |
57           (uint32_t)(b * 15.99f);
58}
59
60void Term::DrawFancyShit()
61{
62    /* draw something awesome */
63    int bg_color = 0x222;
64    int w = caca_get_canvas_width(m_caca);
65    int h = caca_get_canvas_height(m_caca);
66
67    caca_set_color_argb(m_caca, 0xfff, bg_color);
68    caca_clear_canvas(m_caca);
69
70    caca_set_color_argb(m_caca, 0xfff, bg_color);
71    for(int i = 0; i < h; i++)
72    {
73        float a = M_PI / 180 * i * 16 + m_time * 4;
74        float b = M_PI / 180 * i * 12;
75        int x = w / 2  - 14 + w / 4 * lol::cos(a) + w / 4 * lol::sin(b);
76        caca_put_str(m_caca, x, i, "LOL WUT! NEERCS SI TEH RULEZ");
77    }
78
79    caca_set_color_argb(m_caca, 0x444, bg_color);
80    for(int i = 0; i < w; i++)
81    {
82        float a = m_time * 1 + M_PI / 180 * i * 8;
83        float b = m_time * -2 + M_PI / 180 * i * 5;
84        int y = h / 2 + h / 4 * lol::cos(a) + h / 4 * lol::sin(b);
85        caca_set_color_argb(m_caca, hex_color(0.25f + 0.5f / w * i - 0.25f / h * y, 0.25f, 0.25f + 0.25f / w * i + 0.25f / h * y), bg_color);
86        caca_draw_line(m_caca, i, y - 1, i, y + 1,'%');
87    }
88
89/* __  _________ ______ ______ ______ ______
90  /  \/  /  __  >  __  >  __  >  ___//  ___/ \x0a9
91 /      /  ____/  ____/  __  <  <____\___  \
92/__/\__/\_______________/  \________________\ */
93
94    int logo_x = (w - 46) / 2;
95    int logo_y = h / 2 - 2;
96
97    caca_set_color_argb(m_caca, 0x8ac, bg_color);
98    //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3               ), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3               )), bg_color);
99    caca_put_str(m_caca, logo_x + 3, logo_y    ,"__  _________ ______ ______ ______ ______");
100    //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 1), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 1)), bg_color);
101    caca_put_str(m_caca, logo_x + 2, logo_y + 1, "/  \\/  /  __  >  __  >  __  >  ___//  ___/ \x0a9");
102    //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 2), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 2)), bg_color);
103    caca_put_str(m_caca, logo_x + 1, logo_y + 2, "/      /  ____/  ____/  __  <  <____\\___  \\");
104    //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 3), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 3)), bg_color);
105    caca_put_str(m_caca, logo_x    , logo_y + 3, "/__/\\__/\\_______________/  \\________________\\");
106    caca_set_color_argb(m_caca, 0xdef, bg_color);
107    caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
108
109    caca_set_color_argb(m_caca, 0x666, bg_color);
110    caca_printf(m_caca, 2, h - 3, "W=%i", w);
111    caca_printf(m_caca, 2, h - 2, "H=%i", h);
112
113    caca_set_color_argb(m_caca, hex_color(0.6f + 0.4f * lol::cos(m_time * 2), 0.2f, 0.2f), bg_color);
114    caca_put_str(m_caca, w - 12, h - 2, "CACA RULEZ");
115
116/*
117  _______
118 /      /|
119/______/ |
120|      | |
121|  :D  | /
122|______|/
123*/
124
125    int lolcube_x = w / 2 - 5 + (w - 10) * lol::cos(m_time / 2);
126    int lolcube_y = h - 5 - abs ((h - 5) * lol::sin(m_time * 4));
127
128    caca_set_color_argb(m_caca, hex_color(0.75f + 0.25f * lol::sin(m_time * 2), 0.75f + 0.25f * lol::cos(m_time * 3), 0.75f + 0.25f * lol::sin(m_time * 5)), bg_color);
129    caca_put_str(m_caca, lolcube_x + 2, lolcube_y    , "_______");
130    caca_put_str(m_caca, lolcube_x + 1, lolcube_y + 1, "/      /|");
131    caca_put_str(m_caca, lolcube_x    , lolcube_y + 2, "/______/ |");
132    caca_put_str(m_caca, lolcube_x    , lolcube_y + 3, "|      | |");
133    caca_put_str(m_caca, lolcube_x    , lolcube_y + 4, "|  :D  | /");
134    caca_put_str(m_caca, lolcube_x    , lolcube_y + 5, "|______|/");
135
136    caca_set_color_argb(m_caca, 0xdef, bg_color);
137    caca_put_str(m_caca, 0, 0, "rez@lol:~/ sudo -s");
138    caca_put_str(m_caca, 0, 1, "[sudo] password for rez:");
139    caca_put_str(m_caca, 0, 2, "root@lol:~/ echo LOL");
140    caca_put_str(m_caca, 0, 3, "LOL");
141    caca_put_str(m_caca, 0, 4, "root@lol:~/");
142}
143
Note: See TracBrowser for help on using the repository browser.