summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-03-21 21:35:15 +0000
committerubq323 <ubq323@ubq323.website>2024-03-21 21:35:15 +0000
commitf09d855593cc5405937d20571526f81583f0cb8b (patch)
tree16519799b2aa0c6baa285d2979d0eb93c3b289fe
the
-rw-r--r--main.ha62
-rw-r--r--main.lua55
-rw-r--r--spec8
3 files changed, 125 insertions, 0 deletions
diff --git a/main.ha b/main.ha
new file mode 100644
index 0000000..42d42cf
--- /dev/null
+++ b/main.ha
@@ -0,0 +1,62 @@
+use fmt;
+use sdl2;
+
+export fn main() void = {
+ sdl2::SDL_Init(sdl2::SDL_INIT_VIDEO)!;
+ defer sdl2::SDL_Quit();
+
+ const win = sdl2::SDL_CreateWindow("hi", sdl2::SDL_WINDOWPOS_UNDEFINED, sdl2::SDL_WINDOWPOS_UNDEFINED, 640, 480, sdl2::SDL_WindowFlags::NONE)!;
+ defer sdl2::SDL_DestroyWindow(win);
+
+ const wsurf = sdl2::SDL_GetWindowSurface(win)!;
+ const format = wsurf.format;
+ assert(format.bytesperpixel == 4, "can only work with u32 pixels");
+ fmt::printfln("got format {}. bytes per pixel {}. r{:x} g{:x} b{:x} a{:x}",
+ format.format, format.bytesperpixel, format.rmask, format.gmask, format.bmask, format.amask)!;
+ fmt::printfln("red: {:x} green {:x} blue {:x}",
+ sdl2::SDL_MapRGB(format, 255, 0, 0),
+ sdl2::SDL_MapRGB(format, 0, 255, 0),
+ sdl2::SDL_MapRGB(format, 0, 0, 255))!;
+ fmt::println(wsurf.w * wsurf.h)!;
+
+ const pixels = (wsurf.pixels as *opaque: *[*]u32)[..wsurf.w * wsurf.h];
+
+
+ let quit = false;
+ let n = 0z;
+ for (!quit) {
+ let ev = sdl2::event { ... };
+ for (sdl2::SDL_PollEvent(&ev)! == 1) switch (ev.event_type) {
+ case sdl2::SDL_EventType::QUIT => quit = true;
+ case sdl2::SDL_EventType::KEYDOWN => {
+ const keysym = ev.key.keysym.sym;
+ if (keysym == sdl2::SDL_Keycode::ESCAPE) quit = true;
+ fmt::println("got key", keysym: int)!;
+ };
+ case => void;
+ };
+
+ for (let i = 0z; i < 100; i+=1) {
+ pixels[n] = sdl2::SDL_MapRGB(format, 0, 255, 0);
+ n += 1;
+ };
+
+
+ sdl2::SDL_UpdateWindowSurface(win)!;
+ sdl2::SDL_Delay(1000 / 60);
+
+ // sdl2::SDL_SetRenderDrawColor(render, 50, 50, 50, 255)!;
+ // sdl2::SDL_RenderClear(render)!;
+
+ // rect.x = (sdl2::SDL_GetTicks(): int)/100;
+ // sdl2::SDL_SetRenderDrawColor(render, 255, 0, 0, 0)!;
+ // sdl2::SDL_RenderFillRect(render, &rect)!;
+
+ // sdl2::SDL_RenderPresent(render);
+ // sdl2::SDL_Delay(1000 / 60);
+ };
+
+
+
+
+};
diff --git a/main.lua b/main.lua
new file mode 100644
index 0000000..b03306a
--- /dev/null
+++ b/main.lua
@@ -0,0 +1,55 @@
+local L = love
+local G = L.graphics
+
+local R = 10
+
+local canv
+function L.load()
+ canv = G.newCanvas()
+ canv:renderTo(function()
+ G.clear(1,1,1)
+ end)
+ G.setLineWidth(R)
+end
+
+local T = 0
+function L.update(dt)
+ T = T + dt
+end
+
+
+local function line_between(x0,y0,x1,y1)
+ canv:renderTo(function()
+ G.line(x0,y0,x1,y1)
+ end)
+end
+local function circle(x,y)
+ canv:renderTo(function()
+ G.circle('fill',x,y,R/2)
+ end)
+end
+
+
+local last = nil
+function L.draw()
+ G.setColor(0,0,0)
+ local x,y = L.mouse.getPosition()
+ if L.mouse.isDown(1) then
+ if last == nil then
+ circle(x,y)
+ last = {x,y}
+ else
+ circle(x,y)
+ line_between(last[1],last[2],x,y)
+ last[1],last[2] = x,y
+ end
+ elseif last ~= nil then
+ circle(x,y)
+ line_between(last[1],last[2],x,y)
+ last=nil
+ end
+
+ G.setColor(1,1,1)
+ G.draw(canv)
+
+end
diff --git a/spec b/spec
new file mode 100644
index 0000000..eef1146
--- /dev/null
+++ b/spec
@@ -0,0 +1,8 @@
+program where you can draw with the mouse
+program where you can draw with the mouse and it draws lines between the points
+program where you can draw with the mouse and it interpolates nicely with beziers
+program where you can do that multiplayerly
+ hard!
+program where you can switch between drawing and moving around
+program where you can do that and also see each other's positions
+