-
-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
Daynlight edited this page Dec 20, 2025
·
5 revisions
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.
// Graphite
// Copyright 2025 Daynlight
// Licensed under the Apache License, Version 2.0.
// See LICENSE file for details.
#define BUILDING_SCRIPT_DLL
#include <Graphite/ScriptInterface.h>
#include <math.h>
#define SAMPLES 1000
class Script : ScriptInterface{
Graphite::Math::Plot2D plot;
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);
plot.point_cell[std::to_string(i)] = Graphite::Math::Point({x, y});
};
};
void Update(){
};
void Draw(){
plot.draw();
};
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 using points.
// Graphite
// Copyright 2025 Daynlight
// Licensed under the Apache License, Version 2.0.
// See LICENSE file for details.
#define BUILDING_SCRIPT_DLL
#include <Graphite/ScriptInterface.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::Plot2D plot;
// https://mst.mimuw.edu.pl/lecture.php?lecture=gk1&part=Ch6&mode=xhtml#S1
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(){
plot.point_cell["cp_1"] = control_points[0];
plot.point_cell["cp_2"] = control_points[1];
plot.point_cell["cp_3"] = control_points[2];
for(int i = 0; i < SAMPLES; i++){
auto P = bezier((i * 1.0f) / SAMPLES);
plot.point_cell[std::to_string(i)] = Graphite::Math::Point(P);
};
};
void Update(){
};
void Draw(){
plot.draw();
};
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;
};Plots usage example.
// Graphite
// Copyright 2025 Daynlight
// Licensed under the Apache License, Version 2.0.
// See LICENSE file for details.
#define BUILDING_SCRIPT_DLL
#include <Graphite/ScriptInterface.h>
#include <math.h>
class Script : ScriptInterface{
Graphite::Math::Plot2D plot;
void Init(){
plot.point_cell["1"] = Graphite::Math::Point({0.2f, 0.1f});
plot.point_cell["2"] = Graphite::Math::Point({0.2f, -0.1f});
plot.point_cell["3"] = Graphite::Math::Point({-0.2f, 0.1f});
};
void Update(){
};
void Draw(){
plot.draw();
};
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;
};- Install Graphite
- Place your script in the project directory as
Graphite.cpp. - Run Graphite:
Graphite <flags> <path>
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