-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ec5771c
Showing
70 changed files
with
10,326 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#ifndef P8G_H | ||
#define P8G_H | ||
|
||
void p8g_apply_matrix(float a, float b, float c, float d, float e, float f); | ||
void p8g_background(float color[4]); | ||
typedef enum { | ||
P8G_COLOR_MODE_RGB, | ||
P8G_COLOR_MODE_HSB, | ||
P8G_COLOR_MODE_HSL, | ||
} p8g_color_mode_t; | ||
void p8g_color_mode(p8g_color_mode_t mode); | ||
void p8g_ellipse(float x, float y, float w, float h); | ||
typedef enum { | ||
P8G_ELLIPSE_MODE_CORNER, | ||
P8G_ELLIPSE_MODE_CORNERS, | ||
P8G_ELLIPSE_MODE_RADIUS, | ||
P8G_ELLIPSE_MODE_CENTER, | ||
} p8g_ellipse_mode_t; | ||
void p8g_ellipse_mode(p8g_ellipse_mode_t mode); | ||
void p8g_fill(float color[4]); | ||
void p8g_line(float x1, float y1, float x2, float y2); | ||
void p8g_no_fill(void); | ||
void p8g_no_smooth(void); | ||
void p8g_no_stroke(void); | ||
void p8g_point(float x, float y); | ||
void p8g_pop(void); | ||
void p8g_push(void); | ||
void p8g_rect(float x, float y, float w, float h); | ||
typedef enum { | ||
P8G_RECT_MODE_CORNER, | ||
P8G_RECT_MODE_CORNERS, | ||
P8G_RECT_MODE_RADIUS, | ||
P8G_RECT_MODE_CENTER, | ||
} p8g_rect_mode_t; | ||
void p8g_rect_mode(p8g_rect_mode_t mode); | ||
void p8g_reset_matrix(void); | ||
void p8g_rotate(float angle); | ||
typedef struct { | ||
int width, height; | ||
char* title; | ||
int full_screen; | ||
void (*draw)(void); | ||
} p8g_sketch_t; | ||
void p8g_run(p8g_sketch_t sketch); | ||
void p8g_scale(float x, float y); | ||
void p8g_smooth(void); | ||
void p8g_stroke(float color[4]); | ||
void p8g_stroke_weight(float weight); | ||
void p8g_translate(float x, float y); | ||
void p8g_triangle(float x1, float y1, float x2, float y2, float x3, float y3); | ||
|
||
#ifdef USING_NAMESPACE_P8G | ||
extern void draw(void); | ||
#define P8G_ARG_2(_1, _2, _3, _4, N, ...) N | ||
#define P8G_ARG_4(_1, _2, _3, _4, N, ...) N | ||
float _buf[4]; | ||
p8g_color_mode_t _color_mode; | ||
float* _color1f(float gray) { | ||
_buf[0] = gray; | ||
_buf[1] = gray; | ||
_buf[2] = gray; | ||
_buf[3] = _color_mode == P8G_COLOR_MODE_RGB ? 255.f : 1.f; | ||
return _buf; | ||
} | ||
#define _color2f(gray, alpha) (float[]) { gray, gray, gray, alpha } | ||
#define _color3f(v1, v2, v3) (float[]) { v1, v2, v3, _color_mode == P8G_COLOR_MODE_RGB ? 255.f : 1.f } | ||
#define _color4f(v1, v2, v3, alpha) (float[]) { v1, v2, v3, alpha } | ||
float* _color4fv(float color[4]) { | ||
return color; | ||
} | ||
#define _colort(t) _Generic((t), float*: _color4fv, default: _color1f)(t) | ||
#define _color(...) P8G_ARG_4(__VA_ARGS__, _color4f, _color3f, _color2f, _colort)(__VA_ARGS__) | ||
#define CORNER 0 | ||
#define CORNERS 1 | ||
#define RADIUS 2 | ||
#define CENTER 3 | ||
#define RGB 0 | ||
#define HSB 1 | ||
#define HSL 2 | ||
#define RADIANS 0 | ||
#define DEGREES 1 | ||
#define applyMatrix(a, b, c, d, e, f) p8g_apply_matrix(a, b, c, d, e, f) | ||
#define background(...) p8g_background(_color((__VA_ARGS__))) | ||
#define colorMode(mode) \ | ||
do { \ | ||
_color_mode = mode; \ | ||
p8g_color_mode(mode); \ | ||
} while (0) | ||
#define ellipse(x, y, w, h) p8g_ellipse(x, y, w, h) | ||
#define ellipseMode(mode) p8g_ellipse_mode(mode) | ||
#define fill(...) p8g_fill(_color((__VA_ARGS__))) | ||
#define line(x1, y1, x2, y2) p8g_line(x1, y1, x2, y2) | ||
#define noFill() p8g_no_fill() | ||
#define noSmooth() p8g_no_smooth() | ||
#define noStroke() p8g_no_stroke() | ||
#define point(x, y) p8g_point(x, y) | ||
#define pop() p8g_pop() | ||
#define push() p8g_push() | ||
#define rect(x, y, w, h) p8g_rect(x, y, w, h) | ||
#define rectMode(mode) p8g_rect_mode(mode) | ||
#define resetMatrix() p8g_reset_matrix() | ||
#define rotate(angle) p8g_rotate(angle) | ||
int width, height; | ||
void _run(p8g_sketch_t sketch) { | ||
width = sketch.width ? sketch.width : 100; | ||
height = sketch.height ? sketch.height : 100; | ||
sketch.draw = sketch.draw ? sketch.draw : draw; | ||
p8g_run(sketch); | ||
} | ||
#define run(...) _run((p8g_sketch_t) { __VA_ARGS__ }) | ||
#define _scale1f(s) p8g_scale(s, s) | ||
#define scale(...) P8G_ARG_2(__VA_ARGS__, p8g_scale, _scale1f)(__VA_ARGS__) | ||
#define smooth() p8g_smooth() | ||
#define stroke(...) p8g_stroke(_color((__VA_ARGS__))) | ||
#define strokeWeight(weight) p8g_stroke_weight(weight) | ||
#define translate(x, y) p8g_translate(x, y) | ||
#define triangle(x1, y1, x2, y2, x3, y3) p8g_triangle(x1, y1, x2, y2, x3, y3) | ||
#endif /* USING_NAMESPACE_P8G */ | ||
|
||
#endif /* P8G_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Dependencies | ||
/node_modules | ||
|
||
# Production | ||
/build | ||
|
||
# Generated files | ||
.docusaurus | ||
.cache-loader | ||
|
||
# Misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Website | ||
|
||
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. | ||
|
||
### Installation | ||
|
||
``` | ||
$ yarn | ||
``` | ||
|
||
### Local Development | ||
|
||
``` | ||
$ yarn start | ||
``` | ||
|
||
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. | ||
|
||
### Build | ||
|
||
``` | ||
$ yarn build | ||
``` | ||
|
||
This command generates static content into the `build` directory and can be served using any static contents hosting service. | ||
|
||
### Deployment | ||
|
||
Using SSH: | ||
|
||
``` | ||
$ USE_SSH=true yarn deploy | ||
``` | ||
|
||
Not using SSH: | ||
|
||
``` | ||
$ GIT_USER=<Your GitHub username> yarn deploy | ||
``` | ||
|
||
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: [require.resolve('@docusaurus/core/lib/babel/preset')], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Get started", | ||
"position": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import ThemedImage from '@theme/ThemedImage'; | ||
import useBaseUrl from '@docusaurus/useBaseUrl'; | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
# C | ||
|
||
> C is an imperative procedural language. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support. Despite its low-level capabilities, the language was designed to encourage cross-platform programming. A standards-compliant C program written with portability in mind can be compiled for a wide variety of computer platforms and operating systems with few changes to its source code. | ||
Source: https://en.wikipedia.org/wiki/C_(programming_language) | ||
|
||
## Hello rectangle! | ||
|
||
```c title=hello_rectangle.c | ||
#define USING_NAMESPACE_P8G | ||
#include "p8g.h" | ||
|
||
void draw(void) { | ||
background(100); | ||
rect(50, 50, 100, 100); | ||
} | ||
|
||
int main(void) { | ||
run(400, 400, "Hello rectangle!"); | ||
return 0; | ||
} | ||
``` | ||
<ThemedImage | ||
alt="Screenshot" | ||
sources={{ | ||
light: useBaseUrl('/img/hello-rectangle-light.png'), | ||
dark: useBaseUrl('/img/hello-rectangle-dark.png'), | ||
}} | ||
/> | ||
## Build and run from the command line | ||
<Tabs groupId="os"> | ||
<TabItem value="windows" label="Windows"> | ||
``` | ||
. | ||
├── glfw.dll | ||
├── hello_rectangle.c | ||
├── p8g.dll | ||
└── p8g.h | ||
``` | ||
``` | ||
gcc hello_rectangle.c -L. -lp8g | ||
.\a.exe | ||
``` | ||
Tested on Windows 10 with https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z extracted to `C:\Program Files` and `C:\Program Files\mingw64\bin` added to `PATH` environment variable. | ||
</TabItem> | ||
<TabItem value="macos" label="macOS"> | ||
``` | ||
. | ||
├── hello_rectangle.c | ||
├── libglfw.3.dylib | ||
├── libp8g.dylib | ||
└── p8g.h | ||
``` | ||
```bash | ||
gcc hello_rectangle.c -L. -lp8g | ||
install_name_tool -add_rpath @executable_path/. a.out | ||
./a.out | ||
``` | ||
|
||
Tested on macOS Mojave 10.14.6 with command line tools installed via `xcode-select --install`. | ||
|
||
</TabItem> | ||
<TabItem value="linux" label="Linux"> | ||
|
||
``` | ||
. | ||
├── hello_rectangle.c | ||
├── libglfw.so | ||
├── libp8g.so | ||
└── p8g.h | ||
``` | ||
|
||
```bash | ||
gcc hello_rectangle.c -L. -lp8g -Wl,-rpath=. | ||
./a.out | ||
``` | ||
|
||
Tested on Ubuntu 20.04.3 LTS with build essentials installed via `sudo apt install build-essential`. | ||
|
||
</TabItem> | ||
</Tabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import GitHubReleaseAssets from '@site/src/components/GitHubReleaseAssets'; | ||
import MyDocCardList from '@site/src/components/MyDocCardList'; | ||
import {useCurrentSidebarCategory} from '@docusaurus/theme-common'; | ||
|
||
# Get started | ||
|
||
## Download p8g | ||
|
||
<GitHubReleaseAssets owner="bernhardfritz" repo="p8g"/> | ||
|
||
## Choose a programming language | ||
|
||
<MyDocCardList items={useCurrentSidebarCategory().items}/> |
Oops, something went wrong.