Skip to content

Commit

Permalink
Fixed vertical axis label bug, more screenshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroBone committed Mar 2, 2019
1 parent 9b63087 commit fbd7b4d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
17 changes: 14 additions & 3 deletions README.md
@@ -1,6 +1,6 @@
# SdlGrapher
SdlGrapher is a small program to render math functions as Charts built with SDL2 library.
It's goal is also to demonstrate **floating-point precision errors**, that's why i didn't do any border / scaling checks.
The goal is also to demonstrate **floating-point precision errors**, that's why i didn't do any border / scaling checks.

## Features
* Horizontal / vertical scrolling.
Expand All @@ -10,7 +10,18 @@ It's goal is also to demonstrate **floating-point precision errors**, that's why
* Automatically calculate scale and axis position based on interval of the math function.
* Pixel perfect rendering.

## Demo
![Sin demo](/screenshots/sin.png)
## Screenshots
#### f(x) = x ^ 2
![Parabola demo](/screenshots/xx.png)
#### f(x) = 1 / x
![Log demo](/screenshots/1divx.png)
#### f(x) = log(x)
![Log demo](/screenshots/log.png)
#### f(x) = sqrt(x)
![Log demo](/screenshots/sqrt.png)
#### f(x) = sin(x)
![Sin demo](/screenshots/sin.png)
#### f(x) = sqrt(x) * sin(x)
![Sin demo](/screenshots/sqrtsin.png)
#### f(x) = 3 * sin(x / 4) - 2 / sin(2 * x)
![Sin2 demo](/screenshots/sin2.png)
14 changes: 14 additions & 0 deletions main.cpp
Expand Up @@ -9,12 +9,26 @@ double mathF(double x) {

// return 1 / x;

/*if (x < 0.001) {
return std::numeric_limits<double>::quiet_NaN();
}*/

/*if (x < 0.001) {
return std::numeric_limits<double>::quiet_NaN();
}
return log(x);*/

// return x * x;
// return sin(x) / cos(x);
// return sin(x) * cos(x);
// return sin(x) + cos(x);
// return sin(x) - cos(x);
// return 13 * x;
// return sqrt(x);
// return sqrt(x) * sin(x);
// return x*x*sin(x);
// return 1 / x;
// return sin(x);
// return cos(x);

Expand Down
Binary file added screenshots/1divx.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/sqrt.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/sqrtsin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/xx.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/Grapher.c++
Expand Up @@ -80,8 +80,12 @@ void Grapher::renderAxes() {
// vertical line
SDL_RenderDrawLine(renderer, cx, 0, cx, vHeight);

int fromY = (int)floor(screenYToMathY(0));
int toY = (int)floor(screenYToMathY(vHeight));
// int fromY = (int)floor(screenYToMathY(0));
// int toY = (int)ceil(screenYToMathY(vHeight));
int fromY = (int)floor(screenYToMathY(vHeight));
int toY = (int)ceil(screenYToMathY(0));

// std::cout << fromY << " " << toY << std::endl;

while (fromY <= toY) {

Expand Down
2 changes: 1 addition & 1 deletion src/Grapher.h
Expand Up @@ -43,7 +43,7 @@ class Grapher : public App {

double screenYToMathY(int screenY) {

return (screenY - cy) / scale;
return -(screenY - cy) / scale;

}

Expand Down

0 comments on commit fbd7b4d

Please sign in to comment.