Initial commit
This commit is contained in:
commit
f15977009e
7 changed files with 134 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.so
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "fenster"]
|
||||
path = fenster
|
||||
url = https://github.com/zserge/fenster.git
|
15
Makefile
Normal file
15
Makefile
Normal 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
18
example.bqn
Normal file
|
@ -0,0 +1,18 @@
|
|||
f←•Import "fenster.bqn"
|
||||
|
||||
size←500
|
||||
|
||||
w←f.OpenWindow size‿size‿"bqn-fenster example"
|
||||
|
||||
Rainbow←{𝕊x‿y‿t:
|
||||
x‿y↩x‿y÷size
|
||||
t↩(100|t)÷100
|
||||
h←(x+y)÷2
|
||||
f.HSVtoRGB⟨360×h,1,1⟩
|
||||
}
|
||||
|
||||
Rainbow f._render w
|
||||
|
||||
•Delay 3
|
||||
|
||||
f.CloseWindow w
|
1
fenster
Submodule
1
fenster
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit e700581dfb7956dd161aee44fc0cff0663e789a1
|
69
fenster.bqn
Normal file
69
fenster.bqn
Normal file
|
@ -0,0 +1,69 @@
|
|||
⟨
|
||||
OpenWindow,
|
||||
CloseWindow,
|
||||
_render,
|
||||
Black,
|
||||
White,
|
||||
Gray,
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
HSVtoRGB
|
||||
⟩⇐
|
||||
|
||||
FensterFFI←"lib.so"⊸•FFI
|
||||
|
||||
fensterOpen←FensterFFI"i8"‿"fenster_open"‿">*:i8"
|
||||
fensterLoop←FensterFFI"i8"‿"fenster_loop"‿">*:i8"
|
||||
fensterClose←FensterFFI""‿"fenster_close"‿">*:i8"
|
||||
fensterSleep←FensterFFI""‿"fenster_sleep"‿">u32"
|
||||
fensterTime←FensterFFI"u64"‿"fenster_time"
|
||||
|
||||
fensterInit←FensterFFI"*:i8"‿"fenster_init"‿"u32"‿"u32"‿"*u8:c8"
|
||||
fensterGetWidth←FensterFFI"u32"‿"fenster_get_width"‿">*:i8"
|
||||
fensterGetHeight←FensterFFI"u32"‿"fenster_get_height"‿">*:i8"
|
||||
fensterGetPixel←FensterFFI"u32"‿"fenster_get_pixel"‿"*:i8"‿"u32"‿"u32"
|
||||
fensterSetPixel←FensterFFI""‿"fenster_set_pixel"‿"*:i8"‿"u32"‿"u32"‿"u32"
|
||||
|
||||
OpenWindow←{𝕊w‿h‿t:
|
||||
f←FensterInit w‿h‿t
|
||||
FensterOpen f
|
||||
FensterLoop f
|
||||
f
|
||||
}
|
||||
|
||||
CloseWindow←{𝕊f:
|
||||
FensterClose f
|
||||
FensterLoop f
|
||||
}
|
||||
|
||||
_render←{Func _𝕣 f:
|
||||
w←FensterGetWidth f
|
||||
h←FensterGetHeight f
|
||||
t←FensterTime⟨⟩
|
||||
{𝕊x‿y:
|
||||
r‿g‿b←Func x‿y‿t
|
||||
c←+´(⌽256⋆↕3)×⌊r‿g‿b×255
|
||||
FensterSetPixel f‿x‿y‿c
|
||||
}¨⥊(↕w)⋈⌜↕h
|
||||
FensterLoop f
|
||||
f
|
||||
}
|
||||
|
||||
Black←0‿0‿0˙
|
||||
White←1‿1‿1˙
|
||||
Gray←{𝕩‿𝕩‿𝕩}
|
||||
Red←1‿0‿0˙
|
||||
Green←0‿1‿0˙
|
||||
Blue←0‿0‿1˙
|
||||
|
||||
# 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⟩:
|
||||
c←v×s
|
||||
x←c×1-|1-2|h÷60
|
||||
m←v-c
|
||||
r‿g‿b←(⌊h÷60)⊑⟨c‿x‿0,x‿c‿0,0‿c‿x,0‿x‿c,x‿0‿c,c‿0‿x⟩
|
||||
m+r‿g‿b
|
||||
}
|
27
lib.c
Normal file
27
lib.c
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue