-
-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
Daynlight edited this page Dec 8, 2025
·
5 revisions
๐ง Note: More advanced and 3D examples are planned! See Roadmap.md for future updates.
Here are some example scripts and usage patterns for Graphite. You can find these in the Examples folder of the repository.
Visualizes a sine wave using points.
#define BUILDING_SCRIPT_DLL
#include <Graphite/ScriptInterface.h>
#include <Graphite/Math.h>
#include <math.h>
#define SAMPLES 1000
class Script : ScriptInterface {
Graphite::Math::Point points[SAMPLES];
float f(float x) { return (1/2.0f) * sin(x * M_PI * 2); }
void Init() {
for(int i = 0; i < SAMPLES; i++) {
float x = (i/(SAMPLES - 1.0f) * 2) - 1;
float y = f(x);
points[i].setPos({x, y});
}
}
void Update() {}
void Draw() {
for(int i = 0; i < SAMPLES; i++)
points[i].drawPoint();
}
void Destroy() {}
};
extern "C" ScriptInterface* SCRIPT_API GetScript() {
Script* script = new Script();
return (ScriptInterface*)script;
}
extern "C" void SCRIPT_API DeleteScript(ScriptInterface* script) {
Script* temp_script = (Script*)script;
delete temp_script;
}Visualizes a quadratic Bezier curve.
#define BUILDING_SCRIPT_DLL
#include <Graphite/ScriptInterface.h>
#include <Graphite/Math.h>
#include <math.h>
#define SAMPLES 200
class Script : ScriptInterface {
Graphite::Math::Point control_points[3] = {{{-0.7, 0.7}, {0.0, 0.0, 1.0}},
{{0.7, -0.5}, {0.0, 0.0, 1.0}},
{{0.9, 0.4}, {0.0, 0.0, 1.0}}};
Graphite::Math::Point points[SAMPLES];
std::array<float, 2> bezier(float t) {
float u = 1.0f - t;
std::array<float, 2> pos1 = control_points[0].getPos();
std::array<float, 2> pos2 = control_points[1].getPos();
std::array<float, 2> pos3 = control_points[2].getPos();
float x = u*u*pos1[0] + 2*u*t*pos2[0] + t*t*pos3[0];
float y = u*u*pos1[1] + 2*u*t*pos2[1] + t*t*pos3[1];
return {x, y};
}
void Init() {
for(int i = 0; i < SAMPLES; i++) {
auto P = bezier((i * 1.0f) / SAMPLES);
points[i].setPos(P);
}
}
void Update() {}
void Draw() {
for(int i = 0; i < 3; i++)
control_points[i].drawPoint();
for(int i = 0; i < SAMPLES; i++)
points[i].drawPoint();
}
void Destroy() {}
};
extern "C" ScriptInterface* SCRIPT_API GetScript() {
Script* script = new Script();
return (ScriptInterface*)script;
}
extern "C" void SCRIPT_API DeleteScript(ScriptInterface* script) {
Script* temp_script = (Script*)script;
delete temp_script;
}- Place your script in the project directory as
Graphite.cpp. - Build and run Graphite:
Graphite <flags> <path>
- Use flags like
-h,-i,-s,-vfor help, init, sandbox, and verbose modes.
See the repository and Examples folder for more sample scripts.
Graphite Wiki ยฉ 2025 Daynlight & Contributors
Licensed under the Apache License 2.0
- ๐ Home
- ๐ ๏ธ Installation
- ๐งโ๐ป Usage
- ๐ Tutorials
- ๐งโ๐ฌ Examples
- ๐ WritingScripts
- ๐ฆ PackageManager
- ๐งฎ Math
- ๐๏ธ APIReference
- ๐ผ๏ธ RenderingEngine
- ๐๏ธ Architecture
- ๐ Roadmap
- ๐ Versions
- ๐ ChangeLog
- ๐ถ Planning
- ๐ค Community
- ๐ Credits
- ๐ Troubleshooting
- โ FAQ