setup: resize window feature
This commit is contained in:
parent
fdc24916cd
commit
c655a31bb8
10 changed files with 64 additions and 65 deletions
|
|
@ -4,13 +4,13 @@
|
|||
#define WIDTH 720
|
||||
#define HEIGHT 420
|
||||
|
||||
int graph(uint32_t *img);
|
||||
int graph2(uint32_t *img);
|
||||
int mountain(uint32_t *img);
|
||||
int cloud(uint32_t *img);
|
||||
int marble(uint32_t *img);
|
||||
int random(uint32_t *img);
|
||||
int wood(uint32_t *img);
|
||||
int test(uint32_t *img);
|
||||
int graph(uint32_t *img, int width, int height);
|
||||
int graph2(uint32_t *img, int width, int height);
|
||||
int mountain(uint32_t *img, int width, int height);
|
||||
int cloud(uint32_t *img, int width, int height);
|
||||
int marble(uint32_t *img, int width, int height);
|
||||
int random(uint32_t *img, int width, int height);
|
||||
int wood(uint32_t *img, int width, int height);
|
||||
int test(uint32_t *img, int width, int height);
|
||||
|
||||
#endif
|
||||
|
|
@ -6,24 +6,25 @@
|
|||
#include <mutex>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "err.h"
|
||||
|
||||
typedef int (*renderFunction)(u_int32_t *img, int width, int height);
|
||||
|
||||
class WindowManager {
|
||||
public:
|
||||
WindowManager(int width, int height, int (*)(u_int32_t *img));
|
||||
WindowManager(int width, int height, renderFunction r);
|
||||
~WindowManager();
|
||||
|
||||
u_int32_t *get_image_addr() { return img; }
|
||||
|
||||
void load_render(int (*)(u_int32_t *img));
|
||||
void load_render(renderFunction r);
|
||||
void loop();
|
||||
private:
|
||||
void update_image(int (*)(u_int32_t *img));
|
||||
void update_image(renderFunction);
|
||||
void display_image();
|
||||
void handle_events(XEvent &GeneralEvent);
|
||||
|
||||
int (*render)(u_int32_t *img);
|
||||
std::vector<int (*)(u_int32_t *img)> renderFunctions;
|
||||
renderFunction render;
|
||||
std::vector<renderFunction> renderFunctions;
|
||||
uint8_t ptrTabIndex;
|
||||
u_int32_t *img;
|
||||
int WindowX;
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@
|
|||
#include "window.hpp"
|
||||
#include "noise/perlin.hpp"
|
||||
|
||||
int cloud(uint32_t *img) {
|
||||
int cloud(uint32_t *img, int width, int height) {
|
||||
static PerlinNoise PerlinNoise;
|
||||
static float time = 0.0;
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
float n = PerlinNoise.noise(x / 100.0 + time, (y / 100.0) + time) * 0.5;
|
||||
n += PerlinNoise.noise(x / 50.0 + time, (y / 50.0) + time) * 0.25;
|
||||
|
||||
int color = static_cast<int>((n + 1) * 127.5);
|
||||
img[y * WIDTH + x] = (color << 16) | (color << 8) | color ;
|
||||
img[y * width + x] = (color << 16) | (color << 8) | color ;
|
||||
}
|
||||
}
|
||||
time += 0.1;
|
||||
|
|
|
|||
|
|
@ -3,16 +3,15 @@
|
|||
#include "window.hpp"
|
||||
#include "noise/perlin.hpp"
|
||||
|
||||
int test(uint32_t *img) {
|
||||
int test(uint32_t *img, int width, int height) {
|
||||
static bool a = true;
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
if (a)
|
||||
img[y * WIDTH + x] = 0x202020;
|
||||
img[y * width + x] = 0x202020;
|
||||
else
|
||||
img[y * WIDTH + x] = 0x0;
|
||||
img[y * width + x] = 0x0;
|
||||
}
|
||||
}
|
||||
a = !a;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -3,38 +3,38 @@
|
|||
#include "window.hpp"
|
||||
#include "noise/perlin.hpp"
|
||||
|
||||
int graph(uint32_t *img) {
|
||||
int graph(uint32_t *img, int width, int height) {
|
||||
static PerlinNoise PerlinNoise;
|
||||
static float time = 0.0;
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
float n = PerlinNoise.noise(x / 100.0 + time, 0.0) * 0.5;
|
||||
|
||||
int y = static_cast<int>((n + 1) * (HEIGHT >> 1));
|
||||
for (int i = 0; i < HEIGHT; ++i) {
|
||||
int y = static_cast<int>((n + 1) * ((int)height >> 1));
|
||||
for (int i = 0; i < height; ++i) {
|
||||
if (i == y)
|
||||
img[i * WIDTH + x] = 0xFFFFFF;
|
||||
img[i * width + x] = 0xFFFFFF;
|
||||
else
|
||||
img[i * WIDTH + x] = 0;
|
||||
img[i * width + x] = 0;
|
||||
}
|
||||
}
|
||||
time += 0.001;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int graph2(uint32_t *img) {
|
||||
int graph2(uint32_t *img, int width, int height) {
|
||||
static PerlinNoise PerlinNoise;
|
||||
static float time = 0.0;
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
float n = PerlinNoise.noise(x / 100.0, time) * 0.5;
|
||||
|
||||
int y = static_cast<int>((n + 1) * (HEIGHT >> 1));
|
||||
for (int i = 0; i < HEIGHT; ++i) {
|
||||
int y = static_cast<int>((n + 1) * (height >> 1));
|
||||
for (int i = 0; i < height; ++i) {
|
||||
if (i - y < 40 && i - y > -40){
|
||||
int co = static_cast<int>(255 * (40 - abs(i - y)) / 40);
|
||||
img[i * WIDTH + x] = 0 << 16| (co << 8) | co;
|
||||
img[i * width + x] = 0 << 16| (co << 8) | co;
|
||||
}
|
||||
else
|
||||
img[i * WIDTH + x] = 0;
|
||||
img[i * width + x] = 0;
|
||||
}
|
||||
}
|
||||
time += 0.001;
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@
|
|||
#include "window.hpp"
|
||||
#include "noise/perlin.hpp"
|
||||
|
||||
int marble(uint32_t *img) {
|
||||
int marble(uint32_t *img, int width, int height) {
|
||||
static PerlinNoise perlinNoise;
|
||||
static float time = 0.0;
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
float n = perlinNoise.noise(x / 100.0 + time, y / 100.0 + time);
|
||||
float marble = sin((x * 0.05 + n * 10.0));
|
||||
int color = static_cast<int>((marble + 1) * 127.5);
|
||||
img[y * WIDTH + x] = (color << 16) | (color << 8) | color;
|
||||
img[y * width + x] = (color << 16) | (color << 8) | color;
|
||||
}
|
||||
}
|
||||
time += 0.01;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "window.hpp"
|
||||
#include "noise/perlin.hpp"
|
||||
|
||||
int mountain(uint32_t *img) {
|
||||
int mountain(uint32_t *img, int width, int height) {
|
||||
static PerlinNoise P(9);
|
||||
static PerlinNoise P2(1000);
|
||||
static PerlinNoise P3(500);
|
||||
|
|
@ -11,24 +11,24 @@ int mountain(uint32_t *img) {
|
|||
|
||||
/*basic color sunsine gradient no noise*/
|
||||
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
float n = P2.noise(x / 10 + (time * 0.5), y / 100.0 + (time * 0.5)) * 0.5 + 0.5;
|
||||
int color = static_cast<int>(n * 255);
|
||||
img[y * WIDTH + x] = (0 << 16) | (color << 8) | color;
|
||||
img[y * width + x] = (0 << 16) | (color << 8) | color;
|
||||
}
|
||||
}
|
||||
/*mountain*/
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
float n = P.noise(x / 100.0 + time, 0) * 0.5;
|
||||
float n2 = P2.noise(x / 1000.0 , 0) + P2.noise(x / 40.0 + (time * 0.5), 0) * 0.5;
|
||||
int y = static_cast<int>((n + 1) * (HEIGHT >> 1));
|
||||
int y2 = static_cast<int>((n2 + 1) * (HEIGHT >> 1) );
|
||||
for (int i = y2; i < HEIGHT; ++i) {
|
||||
img[i * WIDTH + x] = 0xf0f0f0;
|
||||
int y = static_cast<int>((n + 1) * (height >> 1));
|
||||
int y2 = static_cast<int>((n2 + 1) * (height >> 1) );
|
||||
for (int i = y2; i < height; ++i) {
|
||||
img[i * width + x] = 0xf0f0f0;
|
||||
}
|
||||
for (int i = y; i < HEIGHT; ++i) {
|
||||
img[i * WIDTH + x] = 0x151515;
|
||||
for (int i = y; i < height; ++i) {
|
||||
img[i * width + x] = 0x151515;
|
||||
}
|
||||
}
|
||||
time += 0.03;
|
||||
|
|
|
|||
|
|
@ -2,15 +2,14 @@
|
|||
#include "window.hpp"
|
||||
#include "noise/perlin.hpp"
|
||||
|
||||
int random(uint32_t *img) {
|
||||
int random(uint32_t *img, int width, int height) {
|
||||
static PerlinNoise PerlinNoise;
|
||||
static float time = 0.0;
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
float r = (PerlinNoise.noise(x * 0.0001 + time, (y * 00.001) + time)) * 0.5;
|
||||
|
||||
int color = static_cast<int>((r + 1) * 127.5);
|
||||
img[y * WIDTH + x] = (color << 16) >> 1| (color << 8) | 0;
|
||||
img[y * width + x] = (color << 16) >> 1| (color << 8) | 0;
|
||||
}
|
||||
}
|
||||
time += 0.01;
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@
|
|||
#include "window.hpp"
|
||||
#include "noise/perlin.hpp"
|
||||
|
||||
int wood(uint32_t *img) {
|
||||
int wood(uint32_t *img, int width, int height) {
|
||||
static PerlinNoise perlinNoise;
|
||||
static float time = 0.0;
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
float n = perlinNoise.noise(x / 100.0 + time, y / 100.0 + time);
|
||||
float wood = sin((x * 0.1 + n * 5.0));
|
||||
int color = static_cast<int>((wood + 1) * 127.5);
|
||||
img[y * WIDTH + x] = (color << 16) | (color << 8) | color;
|
||||
img[y * width + x] = (color << 16) | (color << 8) | color;
|
||||
}
|
||||
}
|
||||
time += 0.01;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <csignal>
|
||||
|
||||
WindowManager::WindowManager(int width, int height, int (*render)(u_int32_t *img)) :
|
||||
WindowManager::WindowManager(int width, int height, renderFunction render) :
|
||||
render(render),
|
||||
ptrTabIndex(0),
|
||||
WindowX(0), WindowY(0),
|
||||
|
|
@ -108,11 +108,11 @@ void WindowManager::display_image() {
|
|||
XFlush(MainDisplay);
|
||||
}
|
||||
|
||||
void WindowManager::update_image(int (*func)(u_int32_t *img)) {
|
||||
if (func(this->img))
|
||||
void WindowManager::update_image(renderFunction r) {
|
||||
if (r(img, WindowWidth, WindowHeight) != 0)
|
||||
this->isWindowOpen = false;
|
||||
}
|
||||
|
||||
void WindowManager::load_render(int (*func)(u_int32_t *img)) {
|
||||
this->renderFunctions.push_back(func);
|
||||
void WindowManager::load_render(renderFunction r) {
|
||||
this->renderFunctions.push_back(r);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue