-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1052 lines (847 loc) · 26.6 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <SDL.h>
#include <stdio.h>
#include <string>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
using namespace std;
//Constants
const int SCREEN_WIDTH = 1024;
const int SCREEN_HEIGHT = 768;
const int X_SCALE = 1;
const int Y_SCALE = 1;
const int start_x = SCREEN_WIDTH / 2;
const int start_y = SCREEN_HEIGHT - (SCREEN_HEIGHT / 2);
const int x_inc = round(SCREEN_WIDTH / 10);
const int y_inc = round(SCREEN_HEIGHT / 10);
//SDL2 junk
SDL_Texture* loadTexture(string path);
SDL_Window* gWindow = NULL;
SDL_Renderer* gRenderer = NULL;
SDL_Event e;
bool quit = false;
bool first_flag = false;
//Function declarations
void system_halt();
bool init();
void close();
void setup_graphics();
void draw_loop();
void key_states();
void graph_code();
void draw_axis();
void draw_grid();
void draw_graph();
void draw_verticle();
void draw_horizontal();
void draw_sin(float x_scale, float y_scale);
void draw_cos(float x_scale, float y_scale);
void draw_tan(float x_scale, float y_scale);
void draw_x(float x_coefficient, float c);
void draw_x2(float x2_coefficient, float x_coefficient, float c);
//void draw_x3(float x3_coefficient, float x2_coefficient, float x_coefficient, float c);
void system_pause();
void graph_switch();
int main(int argc, char* args[])
{
//Initialize
setup_graphics();
//Play game
draw_loop();
//Free resources
close();
return 0;
}
bool init()
{
//Initialization flag
bool success = true;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
//Create window
gWindow = SDL_CreateWindow("SDL2 Graphing Engine", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if( gWindow == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Create renderer for window
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED );
if( gRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Initialize renderer color
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
}
}
}
return success;
}
void close()
{
//Destroy window
SDL_DestroyRenderer(gRenderer);
SDL_DestroyWindow(gWindow);
gWindow = NULL;
gRenderer = NULL;
//Quit SDL2 subsystems
SDL_Quit();
}
void setup_graphics()
{
//Start up SDL2 and create a window
if(init())
cout << "SDL2 Successfully Initialized!" << endl;
}
void draw_loop()
{
while(!quit)
{
while(SDL_PollEvent(&e) != 0)
{
//User requests quit
if(e.type == SDL_QUIT)
{
quit = true;
}
//Check keys or mouse
//key_states();
}
//Clear last frame
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(gRenderer);
//MAIN LOOP CODE GOES HERE
graph_code();
//Show updated image
SDL_RenderPresent(gRenderer);
}
}
void key_states()
{
//User presses a key
if(e.type == SDL_KEYDOWN)
{
switch(e.key.keysym.sym)
{
case SDLK_ESCAPE:
cout << "Key 'Escape' is pressed." << endl;
break;
case SDLK_F1:
cout << "Key 'F1' is pressed." << endl;
break;
case SDLK_F2:
cout << "Key 'F2' is pressed." << endl;
break;
case SDLK_F3:
cout << "Key 'F3' is pressed." << endl;
break;
case SDLK_F4:
cout << "Key 'F4' is pressed." << endl;
break;
case SDLK_F5:
cout << "Key 'F5' is pressed." << endl;
break;
case SDLK_F6:
cout << "Key 'F6' is pressed." << endl;
break;
case SDLK_F7:
cout << "Key 'F7' is pressed." << endl;
break;
case SDLK_F8:
cout << "Key 'F8' is pressed." << endl;
break;
case SDLK_F9:
cout << "Key 'F9' is pressed." << endl;
break;
case SDLK_F10:
cout << "Key 'F10' is pressed." << endl;
break;
case SDLK_F11:
cout << "Key 'F11' is pressed." << endl;
break;
case SDLK_F12:
cout << "Key 'F12' is pressed." << endl;
break;
case SDLK_INSERT:
cout << "Key 'Insert' is pressed." << endl;
break;
case SDLK_DELETE:
cout << "Key 'Delete' is pressed." << endl;
break;
case SDLK_1:
cout << "Key '1' is pressed." << endl;
break;
case SDLK_2:
cout << "Key '2' is pressed." << endl;
break;
case SDLK_3:
cout << "Key '3' is pressed." << endl;
break;
case SDLK_4:
cout << "Key '4' is pressed." << endl;
break;
case SDLK_5:
cout << "Key '5' is pressed." << endl;
break;
case SDLK_6:
cout << "Key '6' is pressed." << endl;
break;
case SDLK_7:
cout << "Key '7' is pressed." << endl;
break;
case SDLK_8:
cout << "Key '8' is pressed." << endl;
break;
case SDLK_9:
cout << "Key '9' is pressed." << endl;
break;
case SDLK_0:
cout << "Key '0' is pressed." << endl;
break;
case SDLK_MINUS:
cout << "Key '-' is pressed." << endl;
break;
case SDLK_EQUALS:
cout << "Key '=' is pressed." << endl;
break;
case SDLK_BACKSPACE:
cout << "Key 'Backspace' is pressed." << endl;
break;
case SDLK_TAB:
cout << "Key 'Tab' is pressed." << endl;
break;
case SDLK_q:
cout << "Key 'q' is pressed." << endl;
break;
case SDLK_w:
cout << "Key 'w' is pressed." << endl;
break;
case SDLK_e:
cout << "Key 'e' is pressed." << endl;
break;
case SDLK_r:
cout << "Key 'r' is pressed." << endl;
break;
case SDLK_t:
cout << "Key 't' is pressed." << endl;
break;
case SDLK_y:
cout << "Key 'y' is pressed." << endl;
break;
case SDLK_u:
cout << "Key 'u' is pressed." << endl;
break;
case SDLK_i:
cout << "Key 'i' is pressed." << endl;
break;
case SDLK_o:
cout << "Key 'o' is pressed." << endl;
break;
case SDLK_p:
cout << "Key 'p' is pressed." << endl;
break;
case SDLK_LEFTBRACKET:
cout << "Key '[' is pressed." << endl;
break;
case SDLK_RIGHTBRACKET:
cout << "Key ']' is pressed." << endl;
break;
case SDLK_BACKSLASH:
cout << "Key '\\' is pressed." << endl;
break;
case SDLK_a:
cout << "Key 'a' is pressed." << endl;
break;
case SDLK_s:
cout << "Key 's' is pressed." << endl;
break;
case SDLK_d:
cout << "Key 'd' is pressed." << endl;
break;
case SDLK_f:
cout << "Key 'f' is pressed." << endl;
break;
case SDLK_g:
cout << "Key 'g' is pressed." << endl;
break;
case SDLK_h:
cout << "Key 'h' is pressed." << endl;
break;
case SDLK_j:
cout << "Key 'j' is pressed." << endl;
break;
case SDLK_k:
cout << "Key 'k' is pressed." << endl;
break;
case SDLK_l:
cout << "Key 'l' is pressed." << endl;
break;
case SDLK_SEMICOLON:
cout << "Key ';' is pressed." << endl;
break;
case SDLK_QUOTE:
cout << "Key ''' is pressed." << endl;
break;
case SDLK_RETURN:
cout << "Key 'Enter' is pressed." << endl;
break;
case SDLK_LSHIFT:
cout << "Key 'Left Shift' is pressed." << endl;
break;
case SDLK_z:
cout << "Key 'z' is pressed." << endl;
break;
case SDLK_x:
cout << "Key 'x' is pressed." << endl;
break;
case SDLK_c:
cout << "Key 'c' is pressed." << endl;
break;
case SDLK_v:
cout << "Key 'v' is pressed." << endl;
break;
case SDLK_b:
cout << "Key 'b' is pressed." << endl;
break;
case SDLK_n:
cout << "Key 'n' is pressed." << endl;
break;
case SDLK_m:
cout << "Key 'm' is pressed." << endl;
break;
case SDLK_COMMA:
cout << "Key ',' is pressed." << endl;
break;
case SDLK_PERIOD:
cout << "Key '.' is pressed." << endl;
break;
case SDLK_SLASH:
cout << "Key '/' is pressed." << endl;
break;
case SDLK_RSHIFT:
cout << "Key 'Right Shift' is pressed." << endl;
break;
case SDLK_LCTRL:
cout << "Key 'Left Control' is pressed." << endl;
break;
case SDLK_LALT:
cout << "Key 'Left Alt' is pressed." << endl;
break;
case SDLK_SPACE:
cout << "Key 'Space' is pressed." << endl;
break;
case SDLK_RALT:
cout << "Key 'Right Alt' is pressed." << endl;
break;
case SDLK_RCTRL:
cout << "Key 'Right Control' is pressed." << endl;
break;
case SDLK_LEFT:
cout << "Key 'Left' is pressed." << endl;
break;
case SDLK_UP:
cout << "Key 'Up' is pressed." << endl;
break;
case SDLK_DOWN:
cout << "Key 'Down' is pressed." << endl;
break;
case SDLK_RIGHT:
cout << "Key 'Right' is pressed." << endl;
break;
}
}
//User releases a key
else if(e.type == SDL_KEYUP)
{
switch(e.key.keysym.sym)
{
case SDLK_ESCAPE:
cout << "Key 'Escape' is released." << endl;
break;
case SDLK_F1:
cout << "Key 'F1' is released." << endl;
break;
case SDLK_F2:
cout << "Key 'F2' is released." << endl;
break;
case SDLK_F3:
cout << "Key 'F3' is released." << endl;
break;
case SDLK_F4:
cout << "Key 'F4' is released." << endl;
break;
case SDLK_F5:
cout << "Key 'F5' is released." << endl;
break;
case SDLK_F6:
cout << "Key 'F6' is released." << endl;
break;
case SDLK_F7:
cout << "Key 'F7' is released." << endl;
break;
case SDLK_F8:
cout << "Key 'F8' is released." << endl;
break;
case SDLK_F9:
cout << "Key 'F9' is released." << endl;
break;
case SDLK_F10:
cout << "Key 'F10' is released." << endl;
break;
case SDLK_F11:
cout << "Key 'F11' is released." << endl;
break;
case SDLK_F12:
cout << "Key 'F12' is released." << endl;
break;
case SDLK_INSERT:
cout << "Key 'Insert' is released." << endl;
break;
case SDLK_DELETE:
cout << "Key 'Delete' is released." << endl;
break;
case SDLK_1:
cout << "Key '1' is released." << endl;
break;
case SDLK_2:
cout << "Key '2' is released." << endl;
break;
case SDLK_3:
cout << "Key '3' is released." << endl;
break;
case SDLK_4:
cout << "Key '4' is released." << endl;
break;
case SDLK_5:
cout << "Key '5' is released." << endl;
break;
case SDLK_6:
cout << "Key '6' is released." << endl;
break;
case SDLK_7:
cout << "Key '7' is released." << endl;
break;
case SDLK_8:
cout << "Key '8' is released." << endl;
break;
case SDLK_9:
cout << "Key '9' is released." << endl;
break;
case SDLK_0:
cout << "Key '0' is released." << endl;
break;
case SDLK_MINUS:
cout << "Key '-' is released." << endl;
break;
case SDLK_EQUALS:
cout << "Key '=' is released." << endl;
break;
case SDLK_BACKSPACE:
cout << "Key 'Backspace' is released." << endl;
break;
case SDLK_TAB:
cout << "Key 'Tab' is released." << endl;
break;
case SDLK_q:
cout << "Key 'q' is released." << endl;
break;
case SDLK_w:
cout << "Key 'w' is released." << endl;
break;
case SDLK_e:
cout << "Key 'e' is released." << endl;
break;
case SDLK_r:
cout << "Key 'r' is released." << endl;
break;
case SDLK_t:
cout << "Key 't' is released." << endl;
break;
case SDLK_y:
cout << "Key 'y' is released." << endl;
break;
case SDLK_u:
cout << "Key 'u' is released." << endl;
break;
case SDLK_i:
cout << "Key 'i' is released." << endl;
break;
case SDLK_o:
cout << "Key 'o' is released." << endl;
break;
case SDLK_p:
cout << "Key 'p' is released." << endl;
break;
case SDLK_LEFTBRACKET:
cout << "Key '[' is released." << endl;
break;
case SDLK_RIGHTBRACKET:
cout << "Key ']' is released." << endl;
break;
case SDLK_BACKSLASH:
cout << "Key '\\' is released." << endl;
break;
case SDLK_a:
cout << "Key 'a' is released." << endl;
break;
case SDLK_s:
cout << "Key 's' is released." << endl;
break;
case SDLK_d:
cout << "Key 'd' is released." << endl;
break;
case SDLK_f:
cout << "Key 'f' is released." << endl;
break;
case SDLK_g:
cout << "Key 'g' is released." << endl;
break;
case SDLK_h:
cout << "Key 'h' is released." << endl;
break;
case SDLK_j:
cout << "Key 'j' is released." << endl;
break;
case SDLK_k:
cout << "Key 'k' is released." << endl;
break;
case SDLK_l:
cout << "Key 'l' is released." << endl;
break;
case SDLK_SEMICOLON:
cout << "Key ';' is released." << endl;
break;
case SDLK_QUOTE:
cout << "Key ''' is released." << endl;
break;
case SDLK_RETURN:
cout << "Key 'Enter' is released." << endl;
break;
case SDLK_LSHIFT:
cout << "Key 'Left Shift' is released." << endl;
break;
case SDLK_z:
cout << "Key 'z' is released." << endl;
break;
case SDLK_x:
cout << "Key 'x' is released." << endl;
break;
case SDLK_c:
cout << "Key 'c' is released." << endl;
break;
case SDLK_v:
cout << "Key 'v' is released." << endl;
break;
case SDLK_b:
cout << "Key 'b' is released." << endl;
break;
case SDLK_n:
cout << "Key 'n' is released." << endl;
break;
case SDLK_m:
cout << "Key 'm' is released." << endl;
break;
case SDLK_COMMA:
cout << "Key ',' is released." << endl;
break;
case SDLK_PERIOD:
cout << "Key '.' is released." << endl;
break;
case SDLK_SLASH:
cout << "Key '/' is released." << endl;
break;
case SDLK_RSHIFT:
cout << "Key 'Right Shift' is released." << endl;
break;
case SDLK_LCTRL:
cout << "Key 'Left Control' is released." << endl;
break;
case SDLK_LALT:
cout << "Key 'Left Alt' is released." << endl;
break;
case SDLK_SPACE:
cout << "Key 'Space' is released." << endl;
break;
case SDLK_RALT:
cout << "Key 'Right Alt' is released." << endl;
break;
case SDLK_RCTRL:
cout << "Key 'Right Control' is released." << endl;
break;
case SDLK_LEFT:
cout << "Key 'Left' is released." << endl;
break;
case SDLK_UP:
cout << "Key 'Up' is released." << endl;
break;
case SDLK_DOWN:
cout << "Key 'Down' is released." << endl;
break;
case SDLK_RIGHT:
cout << "Key 'Right' is released." << endl;
break;
}
}
//User moves the mouse
else if(e.type == SDL_MOUSEMOTION)
{
cout << "Mouse X: " << e.motion.x << " Mouse Y: " << e.motion.y << endl;
}
//User presses a mouse button
else if(e.type == SDL_MOUSEBUTTONDOWN)
{
switch(e.button.button)
{
case SDL_BUTTON_LEFT:
cout << "Left Mouse Button pressed." << endl;
break;
case SDL_BUTTON_RIGHT:
cout << "Right Mouse Button pressed." << endl;
break;
}
}
//User releases a mouse button
else if(e.type == SDL_MOUSEBUTTONUP)
{
switch(e.button.button)
{
case SDL_BUTTON_LEFT:
cout << "Left Mouse Button released." << endl;
break;
case SDL_BUTTON_RIGHT:
cout << "Right Mouse Button released." << endl;
break;
}
}
}
void graph_code()
{
//Draw verticle and horizontal axis
draw_grid();
draw_axis();
draw_graph();
}
void draw_axis()
{
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0x00, 0x00, 0xFF);
for(int i = 0; i <= SCREEN_HEIGHT; ++i)
{
SDL_RenderDrawPoint(gRenderer, SCREEN_WIDTH / 2, i);
}
for(int i = 0; i <= SCREEN_WIDTH; ++i)
{
SDL_RenderDrawPoint(gRenderer, i, SCREEN_HEIGHT / 2);
}
}
void draw_grid()
{
//Draw grid and left and top borders
SDL_SetRenderDrawColor(gRenderer, 0x00, 0xFF, 0x00, 0x00);
for(int i = 0; i <= SCREEN_HEIGHT; i += (SCREEN_HEIGHT / 20))
{
for(int j = 0; j <= SCREEN_WIDTH; ++j)
{
SDL_RenderDrawPoint(gRenderer, j, i);
}
}
for(int i = 0; i <= SCREEN_WIDTH; i += (SCREEN_WIDTH / 20))
{
for(int j = 0; j <= SCREEN_HEIGHT; ++j)
{
SDL_RenderDrawPoint(gRenderer, i, j);
}
}
//Draw bottom and right borders
for(int i = 0; i <= SCREEN_HEIGHT; ++i)
{
SDL_RenderDrawPoint(gRenderer, SCREEN_WIDTH - 1, i);
}
for(int i = 0; i <= SCREEN_WIDTH; ++i)
{
SDL_RenderDrawPoint(gRenderer, i, SCREEN_HEIGHT - 1);
}
}
void draw_graph()
{
//Each x line is 96 pixels, each y line is 54 pixels
//SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0xFF, 0xFF);
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0x00);
//Draw verticle and horizontal lines
draw_verticle();
draw_horizontal();
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0x00, 0xFF, 0xFF);
//Trig functions
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0x00, 0xFF, 0x00);
draw_sin(1, 1);
SDL_SetRenderDrawColor(gRenderer, 0x00, 0xFF, 0xFF, 0x00);
draw_cos(1, 1);
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0xFF, 0x00);
draw_tan(1, 1);
//Linear function
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0x00);
draw_x(1, 0);
//Quadratic function
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0x00);
draw_x2(1, 0, 0);
//Cubic function
//draw_x3(1, 0, 0, 0);
//if(first_flag == true)
//{
// graph_switch();
//}
//first_flag = true;
}
void draw_verticle()
{
//x = 2
for(int y = SCREEN_HEIGHT; y >= 0; --y)
{
SDL_RenderDrawPoint(gRenderer, start_x + x_inc, y);
}
}
void draw_horizontal()
{
//y = 2
for(int x = 0; x <= SCREEN_WIDTH; ++x)
{
SDL_RenderDrawPoint(gRenderer, x, start_y - y_inc);
}
}
void draw_sin(float x_scale, float y_scale)
{
float current_point = 0;
for(float x = 0; x <= SCREEN_WIDTH; x += 0.01)
{
current_point = start_y - (sin((x - start_x) / (((x_inc / 2) * (2 / 3.14159))) / x_scale) * ((y_inc / 2) * y_scale));
SDL_RenderDrawPoint(gRenderer, round(x), round(current_point));
}
}
void draw_cos(float x_scale, float y_scale)
{
float current_point = 0;
for(float x = 0; x <= SCREEN_WIDTH; x += 0.01)
{
current_point = start_y - (cos((x - start_x) / (((x_inc / 2) * (2 / 3.14159))) / x_scale) * ((y_inc / 2) * y_scale));
SDL_RenderDrawPoint(gRenderer, round(x), round(current_point));
}
}
void draw_tan(float x_scale, float y_scale)
{
float current_point = 0;
for(float x = 0; x <= SCREEN_WIDTH; x += 0.01)
{
current_point = start_y - (tan((x - start_x) / (((x_inc / 2) * (2 / 3.14159))) / x_scale) * ((y_inc / 2) * y_scale));
SDL_RenderDrawPoint(gRenderer, round(x), round(current_point));
}
}
void draw_x(float x_coefficient, float c)
{
float current_point = 0;
for(float x = 0; x <= SCREEN_WIDTH; x += 0.01)
{
current_point = start_y - ((x_coefficient * (x - start_x)) / ((double) x_inc / (double) y_inc)) - ((double) (y_inc / 2) * c);
SDL_RenderDrawPoint(gRenderer, round(x), round(current_point));
}
}
void draw_x2(float x2_coefficient, float x_coefficient, float c)
{
float current_point = 0;
for(float x = 0; x <= SCREEN_WIDTH; x += 0.01)
{
current_point = start_y;
current_point -= ((x2_coefficient * (((x - start_x) / 9.8) * ((x - start_x)) / 9.8) / ((double)x_inc / (double)y_inc)));
current_point -= ((x_coefficient * (x - start_x)) / ((double)x_inc / (double)y_inc));
current_point -= ((double)(y_inc / 2) * c);
SDL_RenderDrawPoint(gRenderer, round(x), round(current_point));
}
}
//void draw_x3(float x3_coefficient, float x2_coefficient, float x_coefficient, float c)
//{
// float current_point = 0;
// for(float x = 0; x <= SCREEN_WIDTH; x += 0.01)
// {
// current_point = start_y;
// current_point -= ((x3_coefficient * (((x - start_x) / 25.0) * ((x - start_x)) / 25.0) * ((x - start_x)) / 25.0) / (192.0 / 108.0));
// current_point -= ((x2_coefficient * (((x - start_x) / 9.8) * ((x - start_x)) / 9.8) / (192.0 / 108.0)));
// current_point -= ((x_coefficient * (x - start_x)) / (192.0 / 108.0));
// current_point -= (54.0 * c);
// SDL_RenderDrawPoint(gRenderer, round(x), round(current_point));
// }
//}
void system_pause()
{
string temp;
cin >> temp;
}
void graph_switch()
{
char choice = 0;