Last active
November 1, 2020 18:05
-
-
Save katsaii/874ef503cc5a476c73b1a2ac7fc60d3b to your computer and use it in GitHub Desktop.
A function which lets you draw bezier cuves in GameMaker.
This file contains hidden or 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
| /// @desc Draws a bezier curve with 3 control points. | |
| /// @param x1 {Real} The X coordinate of the first control point. | |
| /// @param y1 {Real} The Y coordinate of the first control point. | |
| /// @param x2 {Real} The X coordinate of the second control point. | |
| /// @param y2 {Real} The Y coordinate of the second control point. | |
| /// @param x3 {Real} The X coordinate of the third control point. | |
| /// @param y3 {Real} The Y coordinate of the third control point. | |
| /// @author Kat @katsaii | |
| var x1 = argument0; | |
| var y1 = argument1; | |
| var x2 = argument2; | |
| var y2 = argument3; | |
| var x3 = argument4; | |
| var y3 = argument5; | |
| var step = 0.1; | |
| draw_primitive_begin(pr_linestrip); | |
| draw_vertex(x1, y1); | |
| for (var i = 0; i <= 1; i += step) { | |
| // get intermediate coordinates | |
| var ix = lerp(x1, x2, i); | |
| var iy = lerp(y1, y2, i); | |
| var jx = lerp(x2, x3, i); | |
| var jy = lerp(y2, y3, i); | |
| // get final curve point | |
| var bx = lerp(ix, jx, i); | |
| var by = lerp(iy, jy, i); | |
| draw_vertex(bx, by); | |
| } | |
| draw_vertex(x3, y3); | |
| draw_primitive_end(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For 4 control points: