
lazy.ttf+network_anomaly.onnx
#include <SDL.h>
#include <SDL_ttf.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <SDL2/SDL.h>
#include <SDL_image.h>
#include <cmath>
#define OKNO_SZEROKOSC 800
#define OKNO_WYSOKOSC 600
#define MAX_FILE_SIZE 1024
typedef struct {
float x, y, z;
uint8_t b;
} Węzeł;
char* run(const char* cmd) {
char *echo = (char*)malloc(MAX_FILE_SIZE);
if (!echo) return NULL;
FILE *fp = popen(cmd, "r");
if (fp == NULL) {
free(echo);
return NULL;
}
size_t len = fread(echo, 1, MAX_FILE_SIZE - 1, fp);
echo[len] = '\0';
pclose(fp);
return echo;
}
int main(int argc, char* args[]) {
if (argc < 2) {
printf("Użycie: %s <plik.onnx>\n", args[0]);
args[1]="network_anomaly.onnx";
}
FILE *plik = fopen(args[1], "rb");
if (!plik) return 1;
fseek(plik, 0, SEEK_END);
long rozmiar = ftell(plik);
rewind(plik);
uint8_t *bufor = (uint8_t*)malloc(rozmiar);
fread(bufor, 1, rozmiar, plik);
fclose(plik);
if (SDL_Init(SDL_INIT_VIDEO) < 0) return -1;
if (TTF_Init() == -1) {
SDL_Quit();
return -1;
}
SDL_Window* window = SDL_CreateWindow("AI Matrix Visualizer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, OKNO_SZEROKOSC, OKNO_WYSOKOSC, SDL_WINDOW_SHOWN);
if (!window) {
TTF_Quit();
SDL_Quit();
return -1;
}
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer) {
SDL_DestroyWindow(window);
TTF_Quit();
SDL_Quit();
return -1;
}
TTF_Font* font = TTF_OpenFont("./lazy.ttf", 20);
if (!font) {
// Fallback lub wyjście
}
SDL_StartTextInput();
char inputText[100] = {0};
std::vector<std::string> outputLines;
bool quit = false;
int liczba_wezlow = 300;
Węzeł *siec = (Węzeł*)malloc(liczba_wezlow * sizeof(Węzeł));
for (int i = 0; i < liczba_wezlow; i++) {
long idx = i * (rozmiar / liczba_wezlow);
float kat_siatki = (float)i * 0.2f;
siec[i].x = cosf(kat_siatki) * 120.0f + ((i % 5) - 2) * 20.0f;
siec[i].y = (float)((i / 15) - 10) * 25.0f;
siec[i].z = sinf(kat_siatki) * 120.0f + ((i / 5) % 5) * 20.0f;
siec[i].b = bufor[idx];
}
float rotacja = 0.0f;
SDL_Event e;
while (!quit) {
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
quit = true;
} else if (e.type == SDL_TEXTINPUT) {
strcat(inputText, e.text.text);
} else if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.sym == SDLK_BACKSPACE && strlen(inputText) > 0) {
inputText[strlen(inputText) - 1] = '\0';
} else if (e.key.keysym.sym == SDLK_RETURN) {
char *result = run(inputText);
if (result != NULL) {
outputLines.clear();
char *line = strtok(result, "\n");
int total_len = 0;
while (line != NULL) {
std::string l_str(line);
outputLines.push_back(l_str);
total_len += l_str.length();
line = strtok(NULL, "\n");
}
// Reakcja kryształu 3D na wyjście AI
for (int i = 0; i < liczba_wezlow; i++) {
float mod = (float)(total_len % 7) * 0.1f;
float kat = (float)i * 0.2f + total_len * 0.005f;
siec[i].x = cosf(kat) * (110.0f + mod * 15.0f) + ((i % 5) - 2) * 18.0f;
siec[i].z = sinf(kat) * (110.0f + mod * 15.0f) + ((i / 5) % 5) * 18.0f;
}
free(result);
} else {
outputLines.push_back("Błąd wykonania polecenia");
}
inputText[0] = '\0';
}
}
}
// Czyszczenie ekranu - czarne tło
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
rotacja += 0.015f;
float c = cosf(rotacja);
float s = sinf(rotacja);
int sx[300], sy[300];
for (int i = 0; i < liczba_wezlow; i++) {
float x1 = siec[i].x * c - siec[i].z * s;
float z1 = siec[i].x * s + siec[i].z * c;
float y1 = siec[i].y;
float z_kamery = z1 + 400.0f;
float skala = 300.0f / z_kamery;
sx[i] = (int)(OKNO_SZEROKOSC / 2 + x1 * skala);
sy[i] = (int)(OKNO_WYSOKOSC / 2 + y1 * skala);
}
// Rysowanie wiązań (ciemnozielone)
SDL_SetRenderDrawColor(renderer, 0, 80, 0, 150);
for (int i = 0; i < liczba_wezlow; i++) {
int n1 = (i + 1) % liczba_wezlow;
int n2 = (i + 15) % liczba_wezlow;
SDL_RenderDrawLine(renderer, sx[i], sy[i], sx[n1], sy[n1]);
if (i % 2 == 0) {
SDL_RenderDrawLine(renderer, sx[i], sy[i], sx[n2], sy[n2]);
}
}
// Rysowanie węzłów (neonowa zieleń)
for (int i = 0; i < liczba_wezlow; i++) {
if (siec[i].b >= 32 && siec[i].b <= 126) {
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
} else {
SDL_SetRenderDrawColor(renderer, 40, 180, 40, 255);
}
SDL_Rect kropka = {sx[i] - 2, sy[i] - 2, 5, 5};
SDL_RenderFillRect(renderer, &kropka);
}
// Renderowanie interfejsu tekstowego (zielone napisy)
if (font) {
SDL_Color textColor = { 0, 255, 0, 255 };
int y = 20;
// Wyświetl ostatnich kilka linii wyjściowych
int start_idx = outputLines.size() > 12 ? outputLines.size() - 12 : 0;
for (size_t i = start_idx; i < outputLines.size(); ++i) {
SDL_Surface* textSurface = TTF_RenderText_Solid(font, outputLines[i].c_str(), textColor);
if (textSurface) {
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
SDL_Rect renderQuad = { 20, y, textSurface->w, textSurface->h };
SDL_RenderCopy(renderer, textTexture, nullptr, &renderQuad);
y += textSurface->h + 4;
SDL_DestroyTexture(textTexture);
SDL_FreeSurface(textSurface);
}
}
// Prompt użytkownika
std::string promptStr = "> " + std::string(inputText);
SDL_Surface* textSurface2 = TTF_RenderText_Solid(font, promptStr.c_str(), textColor);
if (textSurface2) {
SDL_Texture* textTexture2 = SDL_CreateTextureFromSurface(renderer, textSurface2);
SDL_Rect renderQuad2 = { 20, OKNO_WYSOKOSC - 40, textSurface2->w, textSurface2->h };
SDL_RenderCopy(renderer, textTexture2, nullptr, &renderQuad2);
SDL_DestroyTexture(textTexture2);
SDL_FreeSurface(textSurface2);
}
}
SDL_RenderPresent(renderer);
SDL_Delay(16);
}
free(bufor);
free(siec);
SDL_StopTextInput();
if (font) TTF_CloseFont(font);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
TTF_Quit();
SDL_Quit();
return 0;
}
/*/
No comments:
Post a Comment