Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# raylib-drawing
[简体中文(未完成)](README_ZH.md)

raylib is a simple and easy-to-use game library, yet it lacks 2d drawing functions. raylib-drawing provides the functions that raylib lacks.

Expand Down
175 changes: 175 additions & 0 deletions README_ZH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# raylib-drawing
[English](README.md)

raylib是一个简单易用的游戏库,但它缺乏2D绘图功能。raylib-drawing提供了raylib所缺乏的功能。

raylib-drawing由两个子库组成:
- `rdrawing.h` 2D绘图库
- `rturtle.h` 海龟图形库

## rdrawing.h

`rdrawing.h`提供了许多颜色定义和基本的2D绘图功能:

以下程序可交互式地绘制并填充多边形。
```
#include "../src/rdrawing.h"
#include <time.h>

int main() {
InitWindow(800,600,"test");

Image img=GenImageColor(800,600,WHITE);

SetRandomSeed(time(NULL));
SetTraceLogLevel(LOG_WARNING);
int vx[200];
int vy[200];
int size=sizeof(vx)/sizeof(int);
SetTargetFPS(120);
int num=0;
while (!WindowShouldClose()) {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
if (num<size) {
vx[num]=GetMouseX();
vy[num]=GetMouseY();
if (num>0)
ImageDrawLine(&img,vx[num-1],vy[num-1],vx[num],vy[num],BLACK);
ImageDrawPointEx(&img,vx[num],vy[num],3,BLUE);
num++;
}
}
if (IsKeyPressed(KEY_ENTER)) {
ImageFillPolygonEx(&img,vx,vy,num,LIGHTRED);
ImageDrawPolygonEx(&img,vx,vy,num,3,BLACK);
for (int i=0;i<num;i++) {
ImageDrawPointEx(&img,vx[i],vy[i],5,BLUE);
}
}
if (IsKeyPressed(KEY_C)) {
num = 0;
ImageClearBackground(&img,WHITE);
}
Texture2D texture = LoadTextureFromImage(img);
BeginDrawing();
DrawTexture(texture,0,0,WHITE);

EndDrawing();
UnloadTexture(texture);
}
UnloadImage(img);
return 0;
}
```

| 函数 | 用途 |
|---|---|
| ImageDrawPointEx | 在图像上绘制点 |
| ImageDrawArcEx | 使用提供的线宽和颜色,在图像上绘制椭圆弧 |
| ImageDrawLineEx | 使用提供的线宽和颜色在图像上画一条线 |
| ImageDrawPolylineEx | 使用提供的线宽和颜色在图像上绘制折线。 |
| ImageDrawRectangleEx | 使用提供的线宽和颜色,在图像上绘制矩形轮廓 |
| ImageDrawRoundRectEx | 使用提供的线宽和颜色,在图像上绘制圆角矩形轮廓 |
| ImageDrawCircleEx | Draw a circle's outline to the image, using the provided line width and color |
| ImageDrawEllipseEx | Draw an ellipse's outline to the image, using the provided line width and color |
| ImageDrawPolygonEx | Draw a polygon's outline to the image, using the provided line width and color |
| ImageFillCircleEx | Fill a circle (no outline), using the provided fill color |
| ImageFillEllipseEx | Fill an ellipse (no outline), using the provided fill color |
| ImageFillTriangleEx | Fill a triangle (no outline), using the provided fill color |
| ImageFillRectangleEx | Fill a rectangle (no outline), using the provided fill color |
| ImageFillRoundRectEx | Fill a rounded rectangle (no outline), using the provided fill color |
| ImageFillPolygonEx | Fill a polygon (no outline), using the provided fill color |
| ImageFillSectorEx | Fill a ellipse sector (no outline), using the provided fill color |
| ImageFloodFill | Do a flood fill (stop at the pixels has the border color)|
| ImageDrawCubicBezierEx | Draw a cubic bezier curve to the image, using the provided line width and color |
| ImageSetJoinStyle | Set line join style |
| ImageGetJoinStyle | Get line join style |

## rturtle.h

rturtle.h is an animated [turtle graphics](https://en.wikipedia.org/wiki/Turtle_graphics) library.

```
#include <rturtle.h>

int main() {
int n;
initWorld(800,600);

setSpeed(500);

n=50;
for (int i=0;i<n;i++) {
for (int j=0;j<4;j++) {
fd(200);
lt(90);
}
lt(360.0/n);
}
waitClick();

closeWorld();
return 0;
}
```

It also provided some interactive functions while drawing:
- Press F2 toggle show/hide of auxilary grids.
- Press F3 toggle show/hide of the turtle.
- Press F5 Capture the screen.

| Function | Usage |
|---|---|
| initWorld | Init the turtle world window |
| closeWorld | Destory the turtle world window |
| forword / fd | Move the turtle forward |
| backward / bk | Move the turtle backward |
| leftTurn / lt | Turn the turtle's heading counter-clockwise (left) |
| rightTurn / rt| Turn the turtle's heading clockwise (right) |
| gotoXY | let the turtle move to (x,y) |
| turnTo | turn the turtle's heading to angle |
| faceXY | turn the turtle heading to (x,y) |
| arc | Move the turtle to draw an arc |
| clear | Clear the canvas but don't move the turtle |
| clearScreen / cs | Clear the canvas and set the turtle back to the origin|
| home | Move the turtle back to the origin, and heading to up |
| waitClick | Pause the program, until window closed or mouse left-clicked |
| penDown / pd | set the pen down |
| penUp / pu | set the pen up (turtle's movement won't have tracks)|
| setPenDown | set the pen's donw/up status |
| isPenDown | query if the pen is down |
| hide / show | hide/show the turtle |
| setVisible | set the turtle's visibility |
| isVisible | query if the turtle is visible |
| setPenSize | set the pen's size |
| getPenSize | get the pen's size |
| setPenColor | set the pen's color |
| getPenColor | get the pen's color |
| setSpeed | set the turtle's move speed |
| getSpeed | get the turtle's move speed |
| setRewind | set if the turtle should rewind when hit borders |
| isRewind | query if the turtle should rewind |
| setImmediate | set if the turtle's moves should be animated |
| isImmediate | query if the turtle's moves should be animated |
| setXY | set the turtle's position to (x,y) |
| setHeading | set the turtle's heading |
| getX | get the turtle's position's x-coordination |
| getY | get the turtle's position's y-coordination |
| getAngle / getHeading | get the turtle's heading angle|
| getState | get the turtle's state |
| setState | set the turtle's state |
| setOrigin | set the origin to (x,y) |
| setCaption | set the window's caption |
| setBackgroundImage | set the window's background image |
| setBackgroundImageFile | Load image from the file, and set the window's background image to it |
| setBackgroundColor | set the canvas's background color |
| getBackgroundColor | get the canvas's background color |
| createGrids | create auxilary grids |
| removeGrids | remove auxilary grids |
| beginFill / endFill | fill the polygon generated by turtle's move |
| fill | flood fill (stop at pixels that has different color from the current pixel) |
| fillToBorder | flood fill (stop at pixels that has the border color) |
| drawPoint | draw a point |
| drawLine | draw a line |
| drawEllipse | draw an ellipse's outline |
| fillEllipse | fill an ellipse |