Skip to content

Commit

Permalink
refactored project name canvas->pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Kelly committed Oct 19, 2018
1 parent 28e0edd commit d19cf96
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 92 deletions.
6 changes: 3 additions & 3 deletions 1_pixel.c → examples/1_pixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <unistd.h>
#include "SDL.h"

#include "canvas/canvas.h"
#include "canvas/screen.h"
#include "canvas/draw.h"
#include "pixels/canvas.h"
#include "pixels/screen.h"
#include "pixels/draw.h"


int main(int argc, char *argv[])
Expand Down
6 changes: 3 additions & 3 deletions 2_line.c → examples/2_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <unistd.h>
#include "SDL.h"

#include "canvas/canvas.h"
#include "canvas/screen.h"
#include "canvas/draw.h"
#include "pixels/canvas.h"
#include "pixels/screen.h"
#include "pixels/draw.h"


int main(int argc, char *argv[])
Expand Down
6 changes: 3 additions & 3 deletions 3_box.c → examples/3_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <unistd.h>
#include "SDL.h"

#include "canvas/canvas.h"
#include "canvas/screen.h"
#include "canvas/draw.h"
#include "pixels/canvas.h"
#include "pixels/screen.h"
#include "pixels/draw.h"


int main(int argc, char *argv[])
Expand Down
6 changes: 3 additions & 3 deletions 4_splash.c → examples/4_splash.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <unistd.h>
#include "SDL.h"

#include "canvas/canvas.h"
#include "canvas/screen.h"
#include "canvas/draw.h"
#include "pixels/canvas.h"
#include "pixels/screen.h"
#include "pixels/draw.h"


int main(int argc, char *argv[])
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions 5_rows.c → examples/5_rows.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <unistd.h>
#include "SDL.h"

#include "canvas/canvas.h"
#include "canvas/screen.h"
#include "canvas/draw.h"
#include "pixels/canvas.h"
#include "pixels/screen.h"
#include "pixels/draw.h"


int main(int argc, char *argv[])
Expand Down
18 changes: 11 additions & 7 deletions 6_avalanche.c → examples/6_avalanche.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
#include <time.h>
#include "SDL.h"

#include "canvas/canvas.h"
#include "canvas/screen.h"
#include "canvas/draw.h"
#include "pixels/canvas.h"
#include "pixels/screen.h"
#include "pixels/draw.h"


int main(int argc, char *argv[])
{
int width = 16;
int height = 16;
int width = 128;
int height = 128;

int avalanche[128];
int i;
for (i = 0; i < 128; i++)
avalanche[i] = 0;

int avalanche[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
srand(time(NULL));

canvas_create(width, height);
Expand Down Expand Up @@ -55,7 +59,7 @@ int main(int argc, char *argv[])
}

screen_update();
usleep(41666);
usleep(16777);
}

/* ------------------------------------ */
Expand Down
23 changes: 23 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
program: program.c
gcc -Wall -o program program.c pixels/canvas.c pixels/screen.c pixels/draw.c -I/usr/include/SDL2 -D_REENTRANT -L/usr/lib/arm-linux-gnueabihf -lSDL2

1_pixel: 1_pixel.c
gcc -Wall -o 1_pixel 1_pixel.c pixels/canvas.c pixels/screen.c pixels/draw.c -I/usr/include/SDL2 -D_REENTRANT -L/usr/lib/arm-linux-gnueabihf -lSDL2

2_line: 2_line.c
gcc -Wall -o 2_line 2_line.c pixels/canvas.c pixels/screen.c pixels/draw.c -I/usr/include/SDL2 -D_REENTRANT -L/usr/lib/arm-linux-gnueabihf -lSDL2

3_box: 3_box.c
gcc -Wall -o 3_box 3_box.c pixels/canvas.c pixels/screen.c pixels/draw.c -I/usr/include/SDL2 -D_REENTRANT -L/usr/lib/arm-linux-gnueabihf -lSDL2

4_splash: 4_splash.c
gcc -Wall -o 4_splash 4_splash.c pixels/canvas.c pixels/screen.c pixels/draw.c -I/usr/include/SDL2 -D_REENTRANT -L/usr/lib/arm-linux-gnueabihf -lSDL2

5_rows: 5_rows.c
gcc -Wall -o 5_rows 5_rows.c pixels/canvas.c pixels/screen.c pixels/draw.c -I/usr/include/SDL2 -D_REENTRANT -L/usr/lib/arm-linux-gnueabihf -lSDL2

6_avalanche: 6_avalanche.c
gcc -Wall -o 6_avalanche 6_avalanche.c pixels/canvas.c pixels/screen.c pixels/draw.c -I/usr/include/SDL2 -D_REENTRANT -L/usr/lib/arm-linux-gnueabihf -lSDL2

clean:
rm -f program 1_pixel 2_line 3_box 4_splash 5_rows 6_avalanche
70 changes: 0 additions & 70 deletions main.c

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include "SDL.h"

#include "pixels/canvas.h"
#include "pixels/screen.h"
#include "pixels/draw.h"


int main(int argc, char *argv[])
{
int width = 32;
int height = 32;

canvas_create(width, height);

screen_setup(width, height);

/* ----- Write your program below ----- */

int frame = 0;
bool ascending = true;

bool exit = false;

while (exit == false)
{
if (screen_closebuttonpressed())
break;

int x, y;

for (y = 0; y < height; y++)
for (x = 0; x < width; x++)
{
Uint8 r = 255 - ((255 / height) * y);
Uint8 g = (255 / width) * x;
Uint8 b = frame % 255;

draw_pixel(x, y, r, g, b);
}

if (frame >= 254)
ascending = false;
else if (frame <= 0)
ascending = true;

if (ascending == true)
frame++;
else
frame--;

screen_update();
usleep(16700);
}

/* ------------------------------------ */

screen_cleanup();

return 0;
}

0 comments on commit d19cf96

Please sign in to comment.