Initial commit

This commit is contained in:
Dimitri Lozeve 2024-09-20 21:38:15 +02:00
commit f15977009e
7 changed files with 134 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.so

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "fenster"]
path = fenster
url = https://github.com/zserge/fenster.git

15
Makefile Normal file
View file

@ -0,0 +1,15 @@
CFLAGS ?= -Wall -Wextra -std=c99 -O2
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LDFLAGS = -framework Cocoa -dynamiclib
else
LDFLAGS = -lX11 -shared
endif
lib.so: lib.c fenster/fenster.h
$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
.PHONY: clean
clean:
rm -f lib.so

18
example.bqn Normal file
View file

@ -0,0 +1,18 @@
f•Import "fenster.bqn"
size500
wf.OpenWindow sizesize"bqn-fenster example"
Rainbow{𝕊xyt:
xyxy÷size
t(100|t)÷100
h(x+y)÷2
f.HSVtoRGB360×h,1,1
}
Rainbow f._render w
•Delay 3
f.CloseWindow w

1
fenster Submodule

@ -0,0 +1 @@
Subproject commit e700581dfb7956dd161aee44fc0cff0663e789a1

69
fenster.bqn Normal file
View file

@ -0,0 +1,69 @@
OpenWindow,
CloseWindow,
_render,
Black,
White,
Gray,
Red,
Green,
Blue,
HSVtoRGB
FensterFFI"lib.so"•FFI
fensterOpenFensterFFI"i8""fenster_open"">*:i8"
fensterLoopFensterFFI"i8""fenster_loop"">*:i8"
fensterCloseFensterFFI"""fenster_close"">*:i8"
fensterSleepFensterFFI"""fenster_sleep"">u32"
fensterTimeFensterFFI"u64""fenster_time"
fensterInitFensterFFI"*:i8""fenster_init""u32""u32""*u8:c8"
fensterGetWidthFensterFFI"u32""fenster_get_width"">*:i8"
fensterGetHeightFensterFFI"u32""fenster_get_height"">*:i8"
fensterGetPixelFensterFFI"u32""fenster_get_pixel""*:i8""u32""u32"
fensterSetPixelFensterFFI"""fenster_set_pixel""*:i8""u32""u32""u32"
OpenWindow{𝕊wht:
fFensterInit wht
FensterOpen f
FensterLoop f
f
}
CloseWindow{𝕊f:
FensterClose f
FensterLoop f
}
_render{Func _𝕣 f:
wFensterGetWidth f
hFensterGetHeight f
tFensterTime
{𝕊xy:
rgbFunc xyt
c+´(2563)×rgb×255
FensterSetPixel fxyc
}¨(w)h
FensterLoop f
f
}
Black000˙
White111˙
Gray{𝕩𝕩𝕩}
Red100˙
Green010˙
Blue001˙
# Convert colors from HSV to RGB.
# 𝕩 is a triple 0 ≤ h‿s‿v ≤ 360‿1‿1
# Output is a triple 0 ≤ r‿g‿b ≤ 1
HSVtoRGB{𝕊h,s,v:
cv×s
xc×1-|1-2|h÷60
mv-c
rgb(h÷60)cx0,xc0,0cx,0xc,x0c,c0x
m+rgb
}

27
lib.c Normal file
View file

@ -0,0 +1,27 @@
#include "fenster/fenster.h"
#include <stdlib.h>
struct fenster *fenster_init(int width, int height, char *title) {
uint32_t *buf = calloc(width * height, sizeof(uint32_t));
struct fenster f_init = {
.title = title,
.width = width,
.height = height,
.buf = buf,
};
struct fenster *f = malloc(sizeof(struct fenster));
memcpy(f, &f_init, sizeof(struct fenster));
return f;
}
int fenster_get_width(struct fenster *f) { return f->width; }
int fenster_get_height(struct fenster *f) { return f->height; }
uint32_t fenster_get_pixel(struct fenster *f, int i, int j) {
return fenster_pixel(f, i, j);
}
void fenster_set_pixel(struct fenster *f, int i, int j, uint32_t color) {
fenster_pixel(f, i, j) = color;
}