{"id":19156961,"url":"https://github.com/bertrandmartel/plot-sdl","last_synced_at":"2025-05-07T07:46:40.057Z","repository":{"id":94808700,"uuid":"44935702","full_name":"bertrandmartel/plot-sdl","owner":"bertrandmartel","description":"plot graphic lib using SDL2","archived":false,"fork":false,"pushed_at":"2017-01-11T12:34:06.000Z","size":325,"stargazers_count":23,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-19T20:17:40.740Z","etag":null,"topics":["c","plot-sdl","sdl","sdl-ttf","sdl2"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bertrandmartel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-25T23:55:14.000Z","updated_at":"2025-01-15T01:42:02.000Z","dependencies_parsed_at":"2023-03-12T01:46:08.774Z","dependency_job_id":null,"html_url":"https://github.com/bertrandmartel/plot-sdl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fplot-sdl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fplot-sdl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fplot-sdl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fplot-sdl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bertrandmartel","download_url":"https://codeload.github.com/bertrandmartel/plot-sdl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252838742,"owners_count":21812082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","plot-sdl","sdl","sdl-ttf","sdl2"],"created_at":"2024-11-09T08:36:44.176Z","updated_at":"2025-05-07T07:46:40.042Z","avatar_url":"https://github.com/bertrandmartel.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# plot-sdl #\n\n\u003ci\u003eLast update 01/11/2015\u003c/i\u003e\n\nSmall library using SDL2 and SDL_TTF used to plot points into a 2D graph\n\nCurrent features available:\n\n* add points(x,y) to graph with a specific caption identified by id\n* add a new caption identified by id,a specified color and a text\n* set x label and y label\n* set font text used for the graph (ttf font text file must be included)\n* set font-size\n* set scale value and max value for X axis and Y axis (graduation are shown on the graph)\n* set window size (width/height)\n\n\u003ci\u003eAll points for a specific caption identifier will be joined by a line\u003c/i\u003e\n\u003ci\u003eFor now, only positive part of x,y axis is shown\u003c/i\u003e\n\nplot-sdl is written in [C](#c) and has some wrappers for other languages/platforms :\n\n* [Python](#python)\n* [Android](#android)\n* [Java](#java)\n\n![screenshot](https://raw.github.com/bertrandmartel/plot-sdl/master/plot.png)\n\n* launch included test project :\n\n```\ncd plot-sdl-lib\nmake\n./release/plot ./plot-sdl-test/opensans.ttf\n```\n\n\u003ci\u003etest program require font text file (ttf) in argument, you can change it at will\u003c/i\u003e\n\n\u003chr/\u003e\n\n## C\n\n* headers :\n\n```\n#include \"plot.h\"\n#include \"llist.h\"\n```\n\n* create a list of caption for all your graph you want to plot : \n\n```\ncaptionlist caption_list = NULL;\n\ncaption_list=push_back_caption(caption_list,\"Download\",0,0x0000FF);\ncaption_list=push_back_caption(caption_list,\"Upload\"  ,1,0xFF0000);\n```\n\n* Function ``push_back_caption(captionlist catopn_list, char * caption_txt,int caption_id,int color) `` description :\n\n| property             | Type              | comment\n|--------------|--------------|------------------------|\n|``caption_list`` | captionlist    | pointer to caption list  |\n|``caption_txt`` | char*    | caption label     |\n|``caption_id`` | int    | caption identifier      |\n|``caption_color`` | int    | caption color (hexa format)      |\n\n\n* create a list of coordinate for all the points to draw :\n\n```\ncoordlist coordinate_list=NULL;\n\ncoordinate_list=push_back_coord(coordinate_list,0,0,0);\ncoordinate_list=push_back_coord(coordinate_list,0,1,90);\ncoordinate_list=push_back_coord(coordinate_list,0,2,84);\ncoordinate_list=push_back_coord(coordinate_list,0,3,98);\ncoordinate_list=push_back_coord(coordinate_list,0,4,94);\ncoordinate_list=push_back_coord(coordinate_list,0,5,85);\n```\n\n* Function ``push_back_coord(coordlist coord_list,int caption_id, float x,float y) `` description :\n\n| property             | Type              | comment\n|--------------|--------------|------------------------|\n|``coord_list`` | coordlist    | pointer to coordinate list  |\n|``caption_id`` | int    | caption identifier      |\n|``x`` | float    | x coordinate      |\n|``y`` | float    | y coordinate      |\n\n\u003ci\u003eOne point is bound to a specific caption with ``caption_id`` property\u003c/i\u003e\n\n* instanciate plot parameter structure to set all your specific parameters :\n\n```\nplot_params params;\n\nparams.screen_width=800;\nparams.screen_heigth=640;\nparams.plot_window_title=\"plot-sdl\";\nparams.font_text_path=argv[1];\nparams.font_text_size=18;\nparams.caption_text_x=\"Temps (s)\";\nparams.caption_text_y=\"Debit (Mbit/s)\";\nparams.caption_list = caption_list;\nparams.coordinate_list = coordinate_list;\nparams.scale_x = 1;\nparams.scale_y = 10;\nparams.max_x = 8.5;\nparams.max_y = 120;\n```\n\n* ``plot_params`` structure definition :\n\n| property             | Type              | comment\n|--------------|--------------|------------------------|\n|``screen_width`` | int    | window screen width  |\n|``screen_heigth`` | int    | window screen heigth      |\n|``plot_window_title`` | char*    | window title      |\n|``font_text_path`` | char*    | ttf font text file path      |\n|``font_text_size`` | int    | font size used      |\n|``caption_text_x`` | char*    | caption label fot axis X     |\n|``caption_text_y`` | char*    | caption label fot axis Y       |\n|``caption_list`` | captionlist    | caption list       |\n|``coordinate_list`` | coordlist    | coordinate list      |\n|``scale_x`` | float    | scale graduation used for axis X      |\n|``scale_y`` | float    | scale graduation used for axis Y      |\n|``max_x`` | float    | max value for axis X      |\n|``max_y`` | float    | max value for axis Y      |\n\n* Plot graph with ``int plot_graph(plot_params *params)`` :\n\n```\nint ret = plot_graph(\u0026params);\n```\n\n* This will display graph in a new window and will block until a ``SDL_QUIT`` event is received.\n\n\u003chr/\u003e\n\n## Python\n\nBuild python wrapper extension :\n\n```\ncd python-wrapper\n\n./build-wrapper.sh\n```\n\n``plot.so`` is localed in python-wrapper/plotsdl directory.\n\n* import :\n\n```\nfrom plotsdl.plot import CaptionList\nfrom plotsdl.plot import CoordinateList\nfrom plotsdl.plot import PlotParams\n```\n\n* create a list of caption for all your graph you want to plot : \n\n```\ncaption = CaptionList()\n\n\ncaption.push_back(\"Download\",0,0x0000FF)\ncaption.push_back(\"Upload\"  ,1,0xFF0000)\n```\n\n* Function ``push_back(char * caption_txt,int caption_id,int color) `` description :\n\n| property             | Type              | comment\n|--------------|--------------|------------------------|\n|``caption_txt`` | char*    | caption label     |\n|``caption_id`` | int    | caption identifier      |\n|``caption_color`` | int    | caption color (hexa format)      |\n\n* create a list of coordinate for all the points to draw :\n\n```\ncoordinate = CoordinateList()\n\ncoordinate.push_back(0,0,0)\ncoordinate.push_back(0,1,90)\ncoordinate.push_back(0,2,84)\ncoordinate.push_back(0,3,98)\ncoordinate.push_back(1,0,0)\ncoordinate.push_back(1,1,92)\ncoordinate.push_back(1,2,90)\n```\n\n* Function ``push_back(int caption_id, float x,float y) `` description :\n\n| property             | Type              | comment\n|--------------|--------------|------------------------|\n|``caption_id`` | int    | caption identifier      |\n|``x`` | float    | x coordinate      |\n|``y`` | float    | y coordinate      |\n\n\n\u003ci\u003eOne point is bound to a specific caption with ``caption_id`` property\u003c/i\u003e\n\n* instanciate plot parameter structure to set all your specific parameters :\n\n```\nplot_params = PlotParams(800,\n\t640,\n\t\"plot-sdl\",\n\t\"../plot-sdl-test/opensans.ttf\",\n\t18,\n\t\"Time (s)\",\n\t\"Speed (Mbit/s)\",\n\tcaption,\n\tcoordinate,\n\t1,\n\t10,\n\t8.5,\n\t120)\n```\n\n* ``PlotParams`` definition :\n\n| property             | Type              | comment\n|--------------|--------------|------------------------|\n|``screen_width`` | int    | window screen width  |\n|``screen_heigth`` | int    | window screen heigth      |\n|``plot_window_title`` | char*    | window title      |\n|``font_text_path`` | char*    | ttf font text file path      |\n|``font_text_size`` | int    | font size used      |\n|``caption_text_x`` | char*    | caption label fot axis X     |\n|``caption_text_y`` | char*    | caption label fot axis Y       |\n|``caption_list`` | CaptionList    | caption list       |\n|``coordinate_list`` | CoordinateList    | coordinate list      |\n|``scale_x`` | float    | scale graduation used for axis X      |\n|``scale_y`` | float    | scale graduation used for axis Y      |\n|``max_x`` | float    | max value for axis X      |\n|``max_y`` | float    | max value for axis Y      |\n\n* Plot graph with ``int plot_graph(plot_params *params)`` :\n\n```\nint ret = plot_params.plot_graph()\n```\n\n\u003cb\u003ePython test\u003c/b\u003e\n\n```\ncd python-wrapper\npython test.py\n\n```\n\n\u003cb\u003eClean python wrapper\u003c/b\u003e\n\n```\n./build-wrapper.sh clean\n```\n\n\u003ci\u003efont file wont be found if launched from a different directory\u003c/i\u003e\n\n\u003chr/\u003e\n\n## Android\n\n\u003cb\u003eSetup\u003c/b\u003e\n\n* Add android-ndk directory to your path before setup\n\n* In android-wrapper directory you'll find init-script.sh which will retrieve SDL and SDL_TTF mercurial repository \n\n```\ncd android-wrapper\n./init-script.sh\n```\n\n* By default, API_ABI is set to ``all`` which takes quite a long time to build SDL and SDL_TTF for all your ndk arch. You can modify ``./app/src/main/jni/Application.mk`` with a specific abi instead of ``APP_ABI := all``\n\n* Then you can build with ``build`` parameter\n\n```\n./init-script.sh build\n```\n\n* When you are done, open Android-studio project located in ``android-wrapper`` directory and run test app or build directly with gradle wrapper : ``./gradlew clean build``\n\n\u003cb\u003eJNI API\u003c/b\u003e\n\nLocated in ``./app/src/main/jni/wrapper``, ``SDL_android_main.c`` contains all JNI api used :\n\n* ``void nativePushCoordinate(int caption_id, int xcoord, int ycoord)`` : push a point with give coordinate (x,y)\n\n* ``void nativePushCaption(String caption_txt, int caption_id, int caption_color)`` : push a caption label identifying a graph\n\n* ``void nativePlotsdlQuit()`` : call SDL quit event to terminate process\n\n* ``void onNativeResize(int x, int y, int format)`` : resize SDL window to x width, y heigth with given pixel format\n\n* ``void nativePushPlotParams(int screen_width, int screen_heigth, String title, String fontFileName, int textSize, String xcaptionText, String ycaptionText, float scale_x, float scale_y, float max_x, float max_y)`` : push plot parameters used to plot points and setup graphs\n\n* ``void nativeInit()`` : initialize SDL and plot graph\n\n\u003cb\u003eClean android wrapper\u003c/b\u003e\n\n* To make an ndk clean :\n\n```\n./init-script.sh clean\n```\n\n* reset android wrapper (this will remove SDL and SDL_TTF repo) :\n\n```\n./init-script.sh distclean\n```\n\n\u003chr/\u003e\n\n## Java\n\nThese are the same api as Android wrapper\n\n* First, build wrapper : \n\n```\ncd java-wrapper\nmake\n```\n\n* Open Eclipse and open-project located in ``java-wrapper/java`` directory\n\n* Build project with ant : ``build.xml``\n\n* in command line : \n\n```\ncd java-wrapper\nWORKING_DIR=`pwd`\njava -Djava.library.path=$WORKING_DIR -jar ./java/release/plotsdl-1.0.jar ../plot-sdl-test/opensans.ttf\n```\n\n\u003chr/\u003e\n\n## External links\n\n* tutorial on SDL : http://www.willusher.io/pages/sdl2/\n* installing cython : https://github.com/cython/cython/wiki/Installing\n* tutorial for cython : http://docs.cython.org/src/tutorial/cython_tutorial.html\n* cython Interfacing with External C Code : http://docs.cython.org/src/userguide/external_C_code.html\n* algorithm for drawing / filling circle : http://content.gpwiki.org/index.php/SDL:Tutorials:Drawing_and_Filling_Circles\n* midpoint circle algorithm : https://en.wikipedia.org/wiki/Midpoint_circle_algorithm\n* JNI : https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html#zz-2.1\n* guide for building SDL for Android : https://wiki.libsdl.org/Android\n* additional explanation for SDL on Android : https://amos.me/blog/2013/android-sdl-and-the-ouya/\n\n\u003chr/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbertrandmartel%2Fplot-sdl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbertrandmartel%2Fplot-sdl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbertrandmartel%2Fplot-sdl/lists"}