Created
April 12, 2017 10:07
-
-
Save daem-on/b12867af912c1c4ff4b3743f9bc31e16 to your computer and use it in GitHub Desktop.
Simple graphing program with SDL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include "SDL.h" | |
int main(int argc, char **argv) | |
{ | |
SDL_Window *window; | |
SDL_Renderer *renderer; | |
SDL_Init(SDL_INIT_VIDEO); | |
window = SDL_CreateWindow("Graph", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL); | |
renderer = SDL_CreateRenderer(window, -1, 0); | |
SDL_Rect pixel; | |
pixel.h = 1; | |
pixel.w = 1; | |
SDL_SetRenderDrawColor(renderer, 255, 255, 160, 255); | |
SDL_RenderClear(renderer); | |
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); | |
float i, n; | |
for(i= -(640/2); i<(640/2); i+=0.1) { | |
n = 480 - (i*i)/90 + 80; //change this for different graph | |
pixel.x = i + (640/2); | |
pixel.y = n - (480/2); | |
SDL_RenderFillRect(renderer, &pixel); | |
} | |
SDL_RenderPresent(renderer); | |
SDL_Delay(3000); | |
SDL_DestroyRenderer(renderer); | |
SDL_DestroyWindow(window); | |
SDL_QUIT; | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment