~rabbits/nasu

1e363263188509964d5ea90789d67a3beb78b471 — Devine Lu Linvega 2 years ago 7c4979e
Implemented colors
2 files changed, 17 insertions(+), 51 deletions(-)

M README.md
M nasu6.c
M README.md => README.md +3 -46
@@ 26,56 26,13 @@ sudo apt-get install libsdl1.2-dev
### Paint

- `mouse1` Paint
- `mouse2` Toggle Erase
- `mouse2` Erase(Color1)

## TODO

- Export png
- Cleanup option[space]
- Brush size[zx]
- Patterns[1234567890]
- Zoom options[~]
- Move canvas[wasd]
- Add canvas size argument
- Add import image argument
- Export
- Display change in titlebar

### Optimization

- Don't update pixels unless something changed.

## Notes

- SDL Keycodes: https://wiki.libsdl.org/SDL_Keycode


```
You can do scaling if you are getting sprites from a texture with SDL_RenderCopy() but i cannot guarantee you antialiasing.

With function SDL_RenderCopy() you pass 4 params:

    a pointer to a renderer (where you are going to renderize).
    a pointer to a texture (where you are going to get the sprite).
    pointer to source rect(the area and position where you get the sprite on the texture).
    and pointer to dest rect(the area and position on the renderer you are going to draw).

You should only modify your dest rect like for example, if you are going to render an image 300 x 300 and you want it scaled, your dest rect should be like 150 x 150 or 72 x 72 or whatever value you wanted to scale.
```

## Noodle's classic halftone

```
(x % 3 == 0 && y % 6 == 0) || (x % 3 == 2 && y % 6 == 3)
```

## Cleanup routine

```
function _jagged (x, y, w, h, pixel, data) {
    const neighs = neighbors(x, y, w, h, data)
    if (abs(pixel) && abs(neighs.n) && abs(neighs.e) && !abs(neighs.ne) && (!abs(neighs.s) || !abs(neighs.w))) { return 'red' }
    if (abs(pixel) && abs(neighs.n) && abs(neighs.w) && !abs(neighs.nw) && (!abs(neighs.s) || !abs(neighs.e))) { return 'red' }
    if (abs(pixel) && abs(neighs.s) && abs(neighs.e) && !abs(neighs.se) && (!abs(neighs.n) || !abs(neighs.w))) { return 'red' }
    if (abs(pixel) && abs(neighs.s) && abs(neighs.w) && !abs(neighs.sw) && (!abs(neighs.n) || !abs(neighs.e))) { return 'red' }
    return abs(pixel) ? 'black' : 'white'
  }
```
\ No newline at end of file

M nasu6.c => nasu6.c +14 -5
@@ 28,11 28,10 @@ typedef struct Brush {
static int SCREEN_WIDTH = 512 + PAD * 2;
static int SCREEN_HEIGHT = 512 + PAD * 2;
static int FPS = 30;
unsigned char tilelt[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};

unsigned char buffer[1024 * 4];
int ZOOM = 4;
int clr = 0xFF0000;
int clr = 0;

uint32_t* pixels;



@@ 132,9 131,19 @@ write(int tx, int ty, int px, int py)
	int pid = px + py * 8;
	int row = id * 16 + py;

	buffer[row] |= tilelt[px];

	printf("#%d [%d:%d](%d,%d) = %d\n", id, tx, ty, px, py, buffer[row]);
	if(clr == 0) {
		buffer[row] &= ~(1UL << (7 - px));
		buffer[row + 8] &= ~(1UL << (7 - px));
	} else if(clr == 2) {
		buffer[row] |= 1UL << (7 - px);
		buffer[row + 8] &= ~(1UL << (7 - px));
	} else if(clr == 1) {
		buffer[row] &= ~(1UL << (7 - px));
		buffer[row + 8] |= 1UL << (7 - px);
	} else if(clr == 3) {
		buffer[row] |= 1UL << (7 - px);
		buffer[row + 8] |= 1UL << (7 - px);
	}

	update();
}