Compare commits
5 Commits
4163177071
...
ca7597ee8f
Author | SHA1 | Date | |
---|---|---|---|
|
ca7597ee8f | ||
|
1e37fcebd2 | ||
|
be6ef1f1c2 | ||
|
ba8327c161 | ||
|
37f7bf2c11 |
7
articles/oscillators/make
Executable file
7
articles/oscillators/make
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
cd $(dirname "$0")
|
||||
mkdir -p ./.dynamic
|
||||
mkdir -p ./.temp
|
||||
gcc -Wno-unused-result -Wno-incompatible-pointer-types waveforms.c ../../tools/gifenc/gifenc.c -I../../tools -O2 -o ./.temp/waveforms
|
||||
./.temp/waveforms
|
138
articles/oscillators/waveforms.c
Normal file
138
articles/oscillators/waveforms.c
Normal file
@ -0,0 +1,138 @@
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gifenc/gifenc.h"
|
||||
|
||||
#define NOTE 440
|
||||
#define AUDIO_FRAME_RATE 44100
|
||||
#define LENGTH (AUDIO_FRAME_RATE / NOTE)
|
||||
|
||||
#define WIDTH LENGTH * 4
|
||||
#define HEIGHT 128
|
||||
|
||||
#define RED 0
|
||||
#define GREEN 0
|
||||
#define BLUE 0
|
||||
|
||||
static struct sinewave {
|
||||
float f, s, c;
|
||||
} init_sinewave(float frequency, float phase, float amplitude) {
|
||||
struct sinewave r;
|
||||
r.f = 2.f * sinf((float)M_PI * frequency / (float)AUDIO_FRAME_RATE);
|
||||
r.s = amplitude * sinf(phase);
|
||||
r.c = amplitude * cosf(phase);
|
||||
return r;
|
||||
}
|
||||
|
||||
static float pump_sinewave(struct sinewave *wave) {
|
||||
wave->s -= wave->f * wave->c;
|
||||
wave->c += wave->f * wave->s;
|
||||
return wave->s;
|
||||
}
|
||||
|
||||
static struct sqrtwave {
|
||||
struct sinewave w;
|
||||
union {
|
||||
float f;
|
||||
uint32_t u;
|
||||
} v;
|
||||
} init_sqrtwave(float frequency, float phase, float amplitude) {
|
||||
struct sqrtwave r;
|
||||
union {
|
||||
float f;
|
||||
uint32_t u;
|
||||
} v, a;
|
||||
r.w = init_sinewave(frequency, phase, 1.f);
|
||||
v.f = r.w.s;
|
||||
a.f = amplitude;
|
||||
r.v.u = (a.u & 0x7fffffff) | (v.u & 0x80000000);
|
||||
return r;
|
||||
}
|
||||
|
||||
static float pump_sqrtwave(struct sqrtwave *wave) {
|
||||
union {
|
||||
float f;
|
||||
uint32_t u;
|
||||
} v;
|
||||
pump_sinewave(&wave->w);
|
||||
v.f = wave->w.s;
|
||||
wave->v.u = (wave->v.u & 0x7fffffff) | (v.u & 0x80000000);
|
||||
return wave->v.f;
|
||||
}
|
||||
|
||||
static struct sawtwave {
|
||||
float v, a, i;
|
||||
} init_sawtwave(float frequency, float phase, float amplitude) {
|
||||
struct sawtwave r;
|
||||
r.v = sinf(phase) * amplitude;
|
||||
r.a = amplitude;
|
||||
r.i = 2.f * frequency / AUDIO_FRAME_RATE * amplitude;
|
||||
return r;
|
||||
}
|
||||
|
||||
static float pump_sawtwave(struct sawtwave *wave) {
|
||||
wave->v += wave->i;
|
||||
if (wave->v > wave->a)
|
||||
wave->v -= wave->a * 2.f;
|
||||
return wave->v;
|
||||
}
|
||||
|
||||
static int absi(int v) {
|
||||
return v > 0 ? v : -v;
|
||||
}
|
||||
|
||||
static void plot_line(uint8_t *frame, int x, int xt, int y, int yt) {
|
||||
int dx = xt - x;
|
||||
int dy = yt - y;
|
||||
int step = absi(dx) >= absi(dy) ? absi(dx) : absi(dy);
|
||||
dx /= step;
|
||||
dy /= step;
|
||||
int xc = x;
|
||||
int yc = y;
|
||||
int i = 1;
|
||||
while (i <= step) {
|
||||
frame[xc + yc * WIDTH] = 1;
|
||||
xc += dx;
|
||||
yc += dy;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static void generate_wave(char const *filepath, void *generator, float (*pumper)(void *)) {
|
||||
float wave[LENGTH];
|
||||
for (int i = 0; i < LENGTH; ++i) {
|
||||
wave[i] = pumper(generator);
|
||||
}
|
||||
uint8_t palette[6] = { [3] = RED, [4] = GREEN, [5] = BLUE };
|
||||
ge_GIF *g = ge_new_gif(filepath, WIDTH, HEIGHT, palette, 1, 0, 0);
|
||||
assert(g);
|
||||
for (int f = 0; f < LENGTH; ++f) {
|
||||
memset(g->frame, 0, WIDTH * HEIGHT);
|
||||
for (int i = 0; i < WIDTH; ++i) {
|
||||
int l0 = (int)((wave[(f + i) % LENGTH] + 1.0f) * 127.5f) / 2;
|
||||
int l1 = (int)((wave[(f + i + 1) % LENGTH] + 1.0f) * 127.5f) / 2;
|
||||
if (i == WIDTH - 1)
|
||||
g->frame[i + l0 * WIDTH] = 1;
|
||||
else
|
||||
plot_line(g->frame, i, i + 1, l0, l1);
|
||||
}
|
||||
ge_add_frame(g, 1);
|
||||
}
|
||||
ge_close_gif(g);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct sinewave sine = init_sinewave((float)NOTE, 0.0f, 1.0f);
|
||||
generate_wave(".dynamic/sine.gif", &sine, pump_sinewave);
|
||||
|
||||
struct sqrtwave sqrt = init_sqrtwave((float)NOTE, 0.0f, 1.0f);
|
||||
generate_wave(".dynamic/sqrt.gif", &sqrt, pump_sqrtwave);
|
||||
|
||||
struct sawtwave sawt = init_sawtwave((float)NOTE, 0.0f, 1.0f);
|
||||
generate_wave(".dynamic/sawt.gif", &sawt, pump_sawtwave);
|
||||
|
||||
return 0;
|
||||
}
|
11
compile.sh
11
compile.sh
@ -6,9 +6,16 @@ mkdir -p ./html/articles
|
||||
|
||||
./tools/main_page_generator.py ./articles | ./tools/mmd/build/multimarkdown > ./html/index.html
|
||||
|
||||
for d in ./articles/*; do
|
||||
for d in ./articles/*/; do
|
||||
if [ -d "$d" ]; then
|
||||
./tools/article_wrapper.py "$d/page.mmd" | ./tools/mmd/build/multimarkdown > "./html/articles/$(basename -- $d).html"
|
||||
if test -f "$d/make"; then
|
||||
"$d/make"
|
||||
fi
|
||||
if test -d "$d/.dynamic"; then
|
||||
mkdir -p "./html/articles/$(basename -- $d)"
|
||||
cp -r "$d/.dynamic/." "./html/articles/$(basename -- $d)/"
|
||||
fi
|
||||
./tools/article_wrapper.py "$d/page.mmd" https://mjestecko.neocities.org/ | ./tools/mmd/build/multimarkdown > "./html/articles/$(basename -- $d).html"
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
# todo: Show related git history of a file?
|
||||
|
||||
from sys import argv, exit
|
||||
import time
|
||||
import time, urllib.parse, re
|
||||
|
||||
from article_utils import the_line_after_metadata, parse_metadata
|
||||
from page_shares import wrap_page, MONTHS
|
||||
@ -12,6 +12,10 @@ if len(argv) <= 1:
|
||||
print("No file was supplied")
|
||||
exit(-1)
|
||||
|
||||
if len(argv) <= 2:
|
||||
print("No address was supplied")
|
||||
exit(-1)
|
||||
|
||||
with open(argv[1], "r") as f:
|
||||
content = f.readlines()
|
||||
i = the_line_after_metadata(content)
|
||||
@ -42,4 +46,16 @@ if tags:
|
||||
|
||||
article_head += "---\n\n"
|
||||
|
||||
print(''.join(content[:i]) + wrap_page(article_head + ''.join(content[i:])))
|
||||
# todo: Article namespace with related metadata.
|
||||
header = f"""HTML header: <meta property="og:title" content="{title} on mjestečko"></meta>
|
||||
<meta property="og:type" content="article"></meta>
|
||||
<meta property="og:url" content="{argv[2]}/articles/{urllib.parse.quote(title)}.html"></meta>
|
||||
"""
|
||||
if not brief is None:
|
||||
header += f"""<meta property="og:description" content="{brief}"></meta>\n"""
|
||||
|
||||
front_image = re.compile(r"!\[.*\]\((.+?)\)", re.DOTALL).search(''.join(content[i:]))
|
||||
if not front_image is None:
|
||||
header += f"""<meta property="og:image" content="{argv[2]}/{urllib.parse.quote(front_image.group(1))}"></meta>\n"""
|
||||
|
||||
print(header + ''.join(content[:i]) + wrap_page(article_head + ''.join(content[i:])))
|
||||
|
@ -57,6 +57,7 @@ for root, dirs, _ in walk(argv[1]):
|
||||
f""" <link>{address}/articles/{urllib.parse.quote(d)}</link>\n"""
|
||||
" </item>\n"
|
||||
)
|
||||
break
|
||||
|
||||
feed += """ </channel>
|
||||
</rss>"""
|
||||
|
@ -38,6 +38,7 @@ for root, dirs, _ in walk(argv[1]):
|
||||
)
|
||||
if "Tags" in metadata:
|
||||
page += f""">*{','.join(metadata["Tags"])}*\n---\n"""
|
||||
break
|
||||
|
||||
curtime = time.gmtime(int(time.time()))
|
||||
page += f"Last compiled: *{MONTHS[curtime.tm_mon]} {curtime.tm_mday}, {curtime.tm_year} {curtime.tm_hour}:{curtime.tm_min:02d} UTC*\n\n"
|
||||
|
@ -88,6 +88,7 @@ for _, _, files in walk(argv[1]):
|
||||
f""" <div><p style="display: inline;">{f[:-4]}</p><button style="float: right;" onclick="window.loadAndPlayTrack('/tracks/{f}')">play</button></div>\n"""
|
||||
" <hr/>\n"
|
||||
)
|
||||
break
|
||||
|
||||
page += """ </div>
|
||||
</div>
|
||||
|
15
upload.sh
Executable file
15
upload.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
for cur in ./html/{*,**/*}; do
|
||||
if [[ "$cur" == *"/tracks/"* ]]; then
|
||||
continue
|
||||
fi
|
||||
if [ -f "$cur" ]; then
|
||||
d=$(dirname $(realpath --relative-to="./html" "$cur"))
|
||||
if [[ "$d" == "." ]]; then
|
||||
neocities upload $cur
|
||||
else
|
||||
neocities upload -d $(dirname $(realpath --relative-to="./html" "$cur")) $cur
|
||||
fi
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue
Block a user