|
|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
#include <SDL2/SDL.h> |
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
#define PAD 32 |
|
|
|
|
|
|
|
|
|
typedef struct Point { |
|
|
|
|
int x; |
|
|
|
|
int y; |
|
|
|
|
@ -21,8 +23,8 @@ typedef struct Brush {
|
|
|
|
|
Point prev; |
|
|
|
|
} Brush; |
|
|
|
|
|
|
|
|
|
static int SCREEN_WIDTH = 512; |
|
|
|
|
static int SCREEN_HEIGHT = 512; |
|
|
|
|
static int SCREEN_WIDTH = 512 + PAD * 2; |
|
|
|
|
static int SCREEN_HEIGHT = 512 + PAD * 2; |
|
|
|
|
static int FPS = 30; |
|
|
|
|
int ZOOM = 4; |
|
|
|
|
int clr = 0xFF0000; |
|
|
|
|
@ -51,14 +53,30 @@ divpt(Point* p, int v)
|
|
|
|
|
return p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Point* |
|
|
|
|
mulpt(Point* p, int v) |
|
|
|
|
{ |
|
|
|
|
p->x *= v; |
|
|
|
|
p->y *= v; |
|
|
|
|
return p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Point* |
|
|
|
|
addpt(Point* p, int v) |
|
|
|
|
{ |
|
|
|
|
p->x += v; |
|
|
|
|
p->y += v; |
|
|
|
|
return p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* noodle */ |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
pixel(uint32_t* dst, Point p, int c) |
|
|
|
|
{ |
|
|
|
|
int x, y; |
|
|
|
|
p.x *= ZOOM; |
|
|
|
|
p.y *= ZOOM; |
|
|
|
|
mulpt(&p, ZOOM); |
|
|
|
|
addpt(&p, PAD); |
|
|
|
|
for(x = 0; x < ZOOM; ++x) { |
|
|
|
|
for(y = 0; y < ZOOM; ++y) { |
|
|
|
|
dst[(p.y + y) * SCREEN_WIDTH + (p.x + x)] = c; |
|
|
|
|
@ -91,7 +109,7 @@ init_array(void)
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < SCREEN_HEIGHT; i++) |
|
|
|
|
for(j = 0; j < SCREEN_WIDTH; j++) |
|
|
|
|
pixels[i * SCREEN_WIDTH + j] = 0xffffff; |
|
|
|
|
pixels[i * SCREEN_WIDTH + j] = 0x000000; |
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
@ -160,6 +178,7 @@ handle_mouse(SDL_Event* event, Brush* b)
|
|
|
|
|
case SDL_MOUSEMOTION: |
|
|
|
|
if(b->down) { |
|
|
|
|
setpt(&b->pos, event->motion.x, event->motion.y); |
|
|
|
|
addpt(&b->pos, -PAD); |
|
|
|
|
divpt(&b->pos, ZOOM); |
|
|
|
|
pixel(pixels, b->pos, 0xFFFFFF); |
|
|
|
|
setpt(&b->prev, b->pos.x, b->pos.y); |
|
|
|
|
|