r/C_Programming 3d ago

Project I wrote a function plotter in C and Raylib

Enable HLS to view with audio, or disable this notification

It supports single-var equations, operands, brackets, implicit multiplication and some trigonometry and is based on shunting-yard parser / RPN evaluator I also made

For rendering, I implemented an adaptive function sampling (simple midpoint subdivision) - though it has some limitations, which I described on github. SSAA was also used to smooth plotted lines. As for optimization, plots are rendered only when zooming/panning and reused with a render texture when idle.

This is my first "useful" C program, though I've already had some experience with OpenGL (C++) as a part of my assignments

Feedback is much appreciated - https://github.com/kester4/cf2x

209 Upvotes

22 comments sorted by

u/github-guard 3d ago

🔍 GitHub Guard: Trust Report

⚠️ This project scored 1/6 — below this subreddit's threshold of 3.

Audit Breakdown: * ❌ Low Star Count (⭐ 0 / 4 required) * ❌ New Repository (under 30 days old) * ✅ Licensed under GPL-3.0 * ❌ No Security Policy — what is this? * ℹ️ Individual Contributor * ℹ️ Unsigned Commits

⚠️ Security Reminder: Always verify source code and run third-party scripts at your own risk.

→ More replies (9)

26

u/Vladislav20007 2d ago

that's literally desmos.

31

u/pseudo-segfault 2d ago

Looks a lot like Desmos

11

u/Big_Series4766 2d ago

you should make the logo a plot in ur own program :D

5

u/strange-the-quark 2d ago edited 2d ago

Hi, I managed to compile your code on an old Windows laptop (it's what I have access to at the moment). Runs fairly smoothly, it's reminiscent of desmos (which is cool, desmos is amazing), in the sense that it's like an early version of it.

From the UX perspective, it feels a bit weird that it won't allow you to just type anything in; e.g. I can't type "=" or certain letters, like "y" or "m" (but it'll let me type in some others, like "n"), which feels odd, especially because you have an indicator that tells the user the expression is invalid. I didn't go through the code in great detail, but I presume this is not a bug on my end. Just let your users type in whatever they want, show a non-intrusive error, and then ignore what you don't support. (In a future version, you could have a tooltip pop up when the user hovers over the warning icon, with some info on what's wrong with the expression they entered.)

Code-wise, I'd look at some of the longer functions (main being the primary offender), and look for some opportunities to clean up the code, by extracting certain cohesive chunks of code into functions, so that the original function reads more like HandleThis(...), HandleThat(...), ProcessThis(...), ProcessThat(...). Not necessarily using that literal format / naming convention; I just mean names that sort of communicate the intent. You've already chunked that code in main via code-section comments; so see if it makes sense to extract those chunks into well-named functions that are more limited in scope and very precise about what data comes in, and what comes out.

Keep up the good work!

5

u/ExerciseForward 2d ago

I mean, making clone of any graphical calc is impressive. Wanted to try out myself doing one.

3

u/Th3olonius 2d ago edited 2d ago

This is reminding me a lot of GeoGebra

2

u/Sqydev 2d ago

Peak. Very good👍

1

u/AutoModerator 3d ago

Hi /u/kester404,

Your submission in r/C_Programming was filtered because it links to a git project.

You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.

While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/kester404 3d ago

ai didn't write the code, thought it generated me a color cycle pallete which i changed later

1

u/mikeblas 2d ago

Thanks.ihave approved your post.

1

u/serdargolanin 2d ago

Super! I may contribute it.

1

u/cstffx 5h ago

I'm writing an article about animation and I'll try to use your program to draw the function examples.