-
Notifications
You must be signed in to change notification settings - Fork 0
/
acidwarp.cpp
126 lines (97 loc) · 2.85 KB
/
acidwarp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* acidwarp by Noah Spurrier https://noah.org/acidwarp/
* Dear ImGui port by Pavel Vasilyev <[email protected]>, Jun 2023
*/
#include <math.h>
#include "random.h"
#include "acidwarp.h"
#include "imgui_elements.h"
extern "C" {
#include "acidwarp/handy.h"
#include "acidwarp/acidwarp.h"
#include "acidwarp/rolnfade.h"
#include "acidwarp/palinit.h"
}
int RES = 3;
int XMax = 1023, YMax = 767;
int GO = TRUE;
int SKIP = FALSE;
int NP = FALSE; /* flag indicates new palette */
int LOCK = FALSE; /* flag indicates don't change to next image */
std::vector<UCHAR> buf_graf;
UCHAR MainPalArray [256 * 3];
UCHAR TargetPalArray [256 * 3];
#include <stdlib.h>
uint32_t pal_rgb(int i) {
if (i > 256)
printf("%d ", i);
return 0xff000000 |
(MainPalArray[i*3+0]*4) << 0 |
(MainPalArray[i*3+1]*4) << 8 |
(MainPalArray[i*3+2]*4) << 16;
}
bool AcidWarp::render(uint32_t *p) {
++frame;
switch(acid_state) {
case IMAGE:
generate_image(image_func, buf_graf.data(), XMax/2, YMax/2, XMax, YMax, 255);
//pal_num = xoshiro256plus() % NUM_PALETTE_TYPES;
initPalArray(TargetPalArray, pal_num);
acid_state = FADE_IN;
//break;
case FADE_IN:
rolNFadeMainPalAryToTargNLodDAC(MainPalArray, TargetPalArray);
if (frame > frame_max)
frame = 0, acid_state = ROTATE;
break;
case ROTATE:
rollMainPalArrayAndLoadDACRegs(MainPalArray);
if (frame > frame_max)
frame = 0, acid_state = FADE_OUT;
break;
case FADE_OUT:
// FIXME: something wrong with rolFade*, draw a pallete in imgui, see whats going on
if (fade_dir)
rolNFadeBlkMainPalArrayNLoadDAC(MainPalArray);
else
rolNFadeWhtMainPalArrayNLoadDAC(MainPalArray);
if (frame > frame_max)
frame = 0, acid_state = IMAGE;
break;
}
for (int x = 0; x < XMax; ++x)
for(int y = 0; y < YMax; ++y)
{
auto c = pal_rgb(buf_graf.at(x + y*XMax));
//printf("%x ", c);
drawdot(p, x, y, c);
}
return true;
}
bool AcidWarp::render_gui() {
bool up = false, re = false;
re |= ScrollableSliderInt("image func", &image_func, 0, NUM_IMAGE_FUNCTIONS+1, "%d", 1);
re |= ScrollableSliderInt("pal num", &pal_num, 0, NUM_PALETTE_TYPES, "%d", 1);
ScrollableSliderInt("frames each state", &frame_max, 0, 60*300, "%d", 60);
//up |= ScrollableSliderInt("resolution", &RES, 0, 3, "%d", 0);
ImGui::Checkbox("fade_dir", &fade_dir);
if (re) {
frame = 0;
acid_state = IMAGE;
initPalArray(TargetPalArray, pal_num);
}
ImGui::Text("state:%d frame:%d", acid_state, frame);
return up;
}
void AcidWarp::resize(int _w, int _h) {
XMax = _w - 1;
YMax = _h - 1;
//tex_w = XMax+1;
//tex_h = YMax+1;
initPalArray(MainPalArray, pal_num);
initPalArray(TargetPalArray, pal_num);
buf_graf.resize(easel->w * easel->h);
fill0(buf_graf);
//default_resize(width, height);
frame = 0;
acid_state = IMAGE;
}