├── .gitattributes
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── dictionaries
│ └── Timur_Kuzhagaliyev.xml
├── encodings.xml
├── misc.xml
├── modules.xml
├── scopes
│ └── scope_settings.xml
├── uiDesigner.xml
├── vcs.xml
└── workspace.xml
├── Active Visualiser.iml
├── LICENSE.md
├── README.md
├── out
└── production
│ └── Active Visualiser
│ └── kz
│ └── kuzhagaliyev
│ └── TimboKZ
│ └── ActiveVisualiser
│ ├── Core.class
│ ├── RenderMode.class
│ ├── RenderModes
│ ├── Blur.class
│ ├── Flow.class
│ ├── FlowParticle.class
│ ├── Pulse.class
│ ├── ShaderTest.class
│ ├── Test.class
│ └── Twist.class
│ └── Util.class
├── res
├── ShaderTest_Fragment.glsl
└── ShaderTest_Vertex.glsl
└── src
└── kz
└── kuzhagaliyev
└── TimboKZ
└── ActiveVisualiser
├── Core.java
├── RenderMode.java
├── RenderModes
├── Blur.java
├── Flow.java
├── FlowParticle.java
├── Pulse.java
├── ShaderTest.java
├── Test.java
└── Twist.java
└── Util.java
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Active Visualiser
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/dictionaries/Timur_Kuzhagaliyev.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | framerate
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
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 |
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 | localhost
604 | 5050
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 | 1417798885602
615 |
616 | 1417798885602
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 |
1001 |
1002 |
1003 |
1004 |
1005 |
1006 |
1007 |
1008 |
1009 |
1010 |
1011 |
1012 |
1013 |
1014 |
1015 |
1016 |
1017 |
1018 |
1019 |
1020 |
1021 |
1022 |
1023 |
1024 |
1025 |
1026 |
1027 |
1028 |
1029 |
1030 |
1031 |
1032 |
1033 |
1034 |
1035 |
1036 |
1037 |
1038 |
1039 |
1040 |
1041 |
1042 |
1043 |
1044 |
1045 |
1046 |
1047 |
1048 |
1049 |
1050 |
1051 |
1052 |
1053 |
1054 |
1055 |
1056 |
1057 |
1058 |
1059 |
1060 |
1061 |
1062 |
1063 |
1064 |
1065 |
1066 |
1067 |
1068 |
1069 |
1070 |
1071 |
1072 |
1073 |
1074 |
1075 |
1076 |
1077 |
1078 |
1079 |
1080 |
1081 |
1082 |
1083 |
1084 |
1085 |
1086 |
1087 |
1088 |
1089 |
1090 |
1091 |
1092 |
1093 |
1094 |
1095 |
1096 |
1097 |
1098 |
1099 |
1100 |
1101 |
1102 |
1103 |
1104 |
1105 |
1106 |
1107 |
1108 |
1109 |
1110 |
1111 |
1112 |
1113 |
1114 |
1115 |
1116 |
1117 |
1118 |
1119 |
1120 |
1121 |
1122 |
1123 |
1124 |
1125 |
1126 |
1127 |
1128 |
1129 |
1130 |
1131 |
1132 |
1133 |
1134 | No facets are configured
1135 |
1136 |
1137 |
1138 |
1139 |
1140 |
1141 |
1142 |
1143 |
1144 |
1145 |
1146 | Slick
1147 |
1148 |
1149 |
1150 |
1151 |
1152 |
1153 |
1154 |
1155 |
1156 |
1157 |
1158 | 1.7
1159 |
1160 |
1161 |
1162 |
1163 |
1164 |
1165 |
1166 |
1167 |
1168 |
1169 |
1170 | Active Visualiser
1171 |
1172 |
1173 |
1174 |
1175 |
1176 |
1177 |
1178 |
1179 |
1180 |
1181 |
1182 |
1183 |
1184 |
1185 |
1186 |
1187 |
1188 |
1189 |
1190 |
1191 |
1192 |
1193 |
--------------------------------------------------------------------------------
/Active Visualiser.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Timur Kuzhagaliyev (TimboKZ)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Active Visualiser
2 | =================
3 |
4 | Active Visualiser by Timbo_KZ. [Demo on YouTube](https://www.youtube.com/watch?v=OUPmbOWXMtE).
5 |
6 | Dependencies
7 | ============
8 |
9 | This project uses Java SDK 1.7. You will need [Beads Project](http://www.beadsproject.net/), [LWJGL 2.9.1](http://legacy.lwjgl.org/) and [Slick](http://slick.ninjacave.com/).
10 |
11 | Running and controlling the visualiser
12 | ======================================
13 |
14 | First of all, make sure all dependencies are installed and the `Core` class is the main class.
15 |
16 | For Active Visualiser to run correctly, you must add a path to LWJGL natives, which are usually found in LWJGL archive. This is done by specifying appropriate VM options before running the application. I'm using Windows and path to Windows natices on my system is `D:\Workspaces\Java\Libraries\lwjgl-2.9.1\native\windows`, so my VM options look like this:
17 |
18 | `-Djava.library.path="D:\Workspaces\Java\Libraries\lwjgl-2.9.1\native\windows"`
19 |
20 | At this point in time, if everything was done correctly, you should be able to run the visualiser without any issues. You can test that all default render modes work by pressing buttons `1-5` and `T` to run the test mode. Pressing `F` should display the name of the render mode and the current frame rate. Hover the bottom of the window to reveal the progress bar. Clicking at any point on the progress bar will play the audio from that point.
21 |
22 | Additionally, you can configure the visualiser by specifying program arguments. Table of all possible program arguments can be found below, but keep in mind none of them are required for the app to run.
23 |
24 | |Argument|Parameters|Description|
25 | |--------|----------|------------|
26 | |fullscreen|No parameters|Simply add this word to the program arguments to force th visualiser run in fullscreen mode.|
27 | |width|Window width as an integer|If the visualiser is not in fullscreen mode, this argument will change the width of the visualiser window. Default width is 1280.|
28 | |height|Window height as an integer|If the visualiser is not in fullscreen mode, this argument will change the height of the visualiser window. Default height is 720.|
29 | |framerate|Maximum framerate as an integer|Adding this argument will limit the maximum framerate of the visualiser to the specified value. Default framerate is 60.|
30 | |active|No parameters|Adding this word to the program arguments will attempt to run the visualiser in the active mode, i.e. using the sound from your microphone. This feature is experimental and has only been tested on Windows.|
31 | |audio|Path to an audio file as a string|If this argument is added the visualiser will attempt to load an audio file specified instead of prompting a file chooser dialog.|
32 | |fps|No parameters|Adding this word to the program arguments will display FPS counter and the name of the render mode by default. You can toggle it using `F` key on your keyboard.|
33 |
34 | Examples of different configurations:
35 |
36 | 
37 |
38 | How to add new render modes
39 | ===========================
40 |
41 | 1. Create a class in `RenderModes` package that extends `RenderMode`, example:
42 |
43 | ```java
44 | public class Your_Visualiser extends RenderMode {
45 |
46 | public Your_Visualiser(String name, int key) {
47 | super(name, key);
48 | }
49 |
50 | public void render(float delta) {
51 |
52 | Core.initGL();
53 |
54 | float[] values = Core.getValues(0);
55 | float[] bassValues = Core.getValues(20);
56 |
57 | float mean = 0;
58 | float bassMean = 0;
59 | for (float i = 0.0f; i < 512.0f; i++) {
60 | mean += values[(int) i];
61 | bassMean += bassValues[(int) i];
62 | }
63 | mean /= 512.0f;
64 | bassMean /= 512.0f;
65 |
66 | // Any code for drawing here
67 |
68 | }
69 |
70 | }
71 | ```
72 |
73 | 2. Register your render mode inside `initRenderModes` method in the `Core` class. The method will look something like this:
74 |
75 | ```java
76 |
77 | // ....
78 |
79 | private static void initRenderModes() {
80 | renderModes = new ArrayList();
81 |
82 | // Registering new render modes
83 | renderModes.add(new Pulse("Pulse", Keyboard.KEY_1));
84 | renderModes.add(new ShaderTest("Shader Test", Keyboard.KEY_5));
85 | renderModes.add(new Blur("Blur", Keyboard.KEY_4));
86 | renderModes.add(new Twist("Twist", Keyboard.KEY_3));
87 | renderModes.add(new Flow("Flow", Keyboard.KEY_2));
88 | renderModes.add(new Test("Test", Keyboard.KEY_T));
89 |
90 | if(renderModes.size() == 0) {
91 | System.out.println("No render modes available.");
92 | System.exit(1);
93 | }
94 |
95 | currentRenderMode = renderModes.get(0);
96 | }
97 |
98 | // ....
99 |
100 | ```
101 |
102 | You will need to add an object of your visualiser to the `renderModes` list. The first parameter is the name of the visualiser, the second parameter is the keyboard key assigned to your visualiser. The line you'd add should look something like this:
103 |
104 | ```java
105 | renderModes.add(new Your_Visualiser("Your Visualiser", Keyboard.KEY_6));
106 | ```
107 |
108 | Now you can see your render mode by launching the visualiser and pressing the key you assigned, in this case it's `6`.
109 |
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/Core.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/Core.class
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderMode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderMode.class
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Blur.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Blur.class
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Flow.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Flow.class
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/FlowParticle.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/FlowParticle.class
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Pulse.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Pulse.class
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/ShaderTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/ShaderTest.class
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Test.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Test.class
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Twist.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Twist.class
--------------------------------------------------------------------------------
/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/Util.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TimboKZ/ActiveVisualiser/d02b25bfe29720d89b52e976f418b060b02aada2/out/production/Active Visualiser/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/Util.class
--------------------------------------------------------------------------------
/res/ShaderTest_Fragment.glsl:
--------------------------------------------------------------------------------
1 | varying vec4 vertColor;
2 | varying float mean1;
3 |
4 | uniform float mean;
5 |
6 | void main(){
7 | gl_FragColor = vertColor / 2;
8 | }
--------------------------------------------------------------------------------
/res/ShaderTest_Vertex.glsl:
--------------------------------------------------------------------------------
1 | varying vec4 vertColor;
2 | varying float mean1;
3 |
4 | uniform float mean;
5 |
6 | void main(){
7 | gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
8 | vertColor = abs(gl_Position) * gl_Position;
9 | mean1 = mean;
10 | }
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/Core.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser;
2 |
3 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderModes.*;
4 | import net.beadsproject.beads.core.AudioContext;
5 | import net.beadsproject.beads.core.UGen;
6 | import net.beadsproject.beads.core.io.JavaSoundAudioIO;
7 | import net.beadsproject.beads.data.Sample;
8 | import net.beadsproject.beads.data.SampleManager;
9 | import net.beadsproject.beads.ugens.Gain;
10 | import net.beadsproject.beads.ugens.OnePoleFilter;
11 | import net.beadsproject.beads.ugens.SamplePlayer;
12 | import org.lwjgl.LWJGLException;
13 | import org.lwjgl.Sys;
14 | import org.lwjgl.input.Keyboard;
15 | import org.lwjgl.input.Mouse;
16 | import org.lwjgl.opengl.Display;
17 | import org.lwjgl.opengl.DisplayMode;
18 | import org.newdawn.slick.SlickException;
19 | import org.newdawn.slick.UnicodeFont;
20 | import org.newdawn.slick.font.effects.ColorEffect;
21 |
22 | import javax.swing.*;
23 | import java.io.File;
24 | import java.util.ArrayList;
25 | import java.util.HashMap;
26 |
27 | import static org.lwjgl.opengl.GL11.*;
28 |
29 | /**
30 | * @author Timur Kuzhagaliyev
31 | * @since 05-12-2014
32 | */
33 |
34 | public class Core {
35 |
36 | public static boolean fullscreen = false;
37 | public static int width = 1280;
38 | public static int height = 720;
39 | public static int framerate = 60;
40 | public static boolean active = false;
41 | public static String audio = "";
42 | public static boolean fps = false;
43 |
44 | public static RenderMode currentRenderMode;
45 | public static ArrayList renderModes;
46 |
47 | public static float controlsAdjustment = 0.0f;
48 | public static boolean controlsReady = false;
49 |
50 | private static long lastFrame;
51 |
52 | private static AudioContext audioContext;
53 | private static UGen mainInput;
54 | private static int[] channels = new int[2048];
55 | private static float volumeLimit;
56 | public static Integer[] frequencies;
57 | public static HashMap gainHashMap;
58 | public static HashMap valuesHashMap;
59 | public static HashMap meansHashMap;
60 | public static HashMap absoluteMeansHashMap;
61 |
62 | public static UnicodeFont font;
63 |
64 | public static void main(String[] args) {
65 |
66 | if(args.length > 0) {
67 | for(int i = 0; i < args.length; i++) {
68 | if(args[i].equalsIgnoreCase("fullscreen")) fullscreen = true;
69 | if(args[i].equalsIgnoreCase("width")) width = Integer.parseInt(args[i + 1]);
70 | if(args[i].equalsIgnoreCase("height")) height = Integer.parseInt(args[i + 1]);
71 | if(args[i].equalsIgnoreCase("framerate")) framerate = Integer.parseInt(args[i + 1]);
72 | if(args[i].equalsIgnoreCase("active")) active = true;
73 | if(args[i].equalsIgnoreCase("audio")) audio = args[i + 1];
74 | if(args[i].equalsIgnoreCase("fps")) fps = true;
75 | }
76 | }
77 |
78 | int steps = 5;
79 | int range = 100;
80 | frequencies = new Integer[steps];
81 | for(int i = 0; i < steps; i++) {
82 | frequencies[i] = range / steps * i;
83 | }
84 |
85 | //initAudio();
86 | initAudio();
87 |
88 | lastFrame = getTime();
89 |
90 | initDisplay();
91 | initRenderModes();
92 | initGL();
93 |
94 | loadFonts();
95 |
96 | loop();
97 |
98 | cleanUp();
99 |
100 | }
101 |
102 | private static void loop() {
103 |
104 | int frames = 0;
105 | int currentFramerate = 0;
106 | double frameCounter = 0;
107 | double lastTime = (double)System.nanoTime()/(double)1000000000L;
108 | double unprocessedTime = 0;
109 |
110 | while(!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
111 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
112 | glEnable(GL_BLEND);
113 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
114 | glLoadIdentity();
115 |
116 | float delta = getDelta();
117 | generateData();
118 | currentRenderMode.render(delta);
119 |
120 | initGL();
121 |
122 | for(RenderMode renderMode : renderModes) {
123 | if(Keyboard.isKeyDown(renderMode.getKey())) {
124 | currentRenderMode = renderMode;
125 | }
126 | }
127 |
128 | if(Keyboard.isKeyDown(Keyboard.KEY_F))
129 | fps = !fps;
130 | if(fps) {
131 | initGL();
132 | font.drawString(0, 0, currentFramerate + " " + currentRenderMode.getName());
133 | glDisable(GL_TEXTURE_2D);
134 | }
135 |
136 | if(!active) {
137 | initGL();
138 | drawControls();
139 | }
140 |
141 | Display.update();
142 | Display.sync(framerate);
143 |
144 | double startTime = (double)System.nanoTime()/(double)1000000000L;
145 | double passedTime = startTime - lastTime;
146 | lastTime = startTime;
147 | unprocessedTime += passedTime;
148 | frameCounter += passedTime;
149 | frames++;
150 | while(unprocessedTime > 1.0 / framerate) {
151 | unprocessedTime -= 1.0 / framerate;
152 | if(frameCounter >= 1.0) {
153 | currentFramerate = frames;
154 | frames = 0;
155 | frameCounter = 0;
156 | }
157 | }
158 | }
159 |
160 | }
161 |
162 | private static void drawControls() {
163 |
164 | float indent = 20.0f;
165 | float height = 20.0f;
166 | float displacement = 40.0f;
167 | Sample sample = ((SamplePlayer) mainInput).getSample();
168 | SamplePlayer samplePlayer = (SamplePlayer) mainInput;
169 |
170 | glPushMatrix();
171 | glTranslatef(0, displacement - controlsAdjustment, 0);
172 | Util.drawRect(indent, Display.getHeight() - indent - height, Display.getWidth() - 2 * indent, height, 0.05f);
173 | Util.drawRect(indent, Display.getHeight() - indent - height, (float) ((Display.getWidth() - 2 * indent) * samplePlayer.getPosition() / sample.getLength()), height, 0.2f);
174 | glPopMatrix();
175 |
176 | if(Util.isInRange(Display.getHeight() - (float) Mouse.getY(), Display.getHeight() - indent - height, Display.getHeight()) && Util.isInRange(Mouse.getX(), 0, Display.getWidth())) {
177 | if(controlsReady) {
178 | if (Mouse.isButtonDown(0)
179 | && Util.isInRange(Display.getHeight() - (float) Mouse.getY(), Display.getHeight() - indent - height, Display.getHeight() - indent)
180 | && Util.isInRange(Mouse.getX(), indent, Display.getWidth() - indent)) {
181 | samplePlayer.setPosition((double) (((float) Mouse.getX() - indent) / (Display.getWidth() - 2 * indent)) * sample.getLength());
182 | }
183 | } else {
184 | if(controlsAdjustment <= displacement) {
185 | controlsAdjustment += 2;
186 | } else {
187 | controlsReady = true;
188 | }
189 | }
190 | } else {
191 | controlsReady = false;
192 | if(controlsAdjustment >= 0) {
193 | controlsAdjustment -= 2;
194 | }
195 | }
196 |
197 | }
198 |
199 | private static void generateData() {
200 |
201 | if(valuesHashMap == null)
202 | valuesHashMap = new HashMap();
203 | if(meansHashMap == null)
204 | meansHashMap = new HashMap();
205 | if(absoluteMeansHashMap == null)
206 | absoluteMeansHashMap = new HashMap();
207 |
208 | float cumulativeMean = 0.0f;
209 | float cumulativeAbsoluteMean = 0.0f;
210 |
211 | for(Integer frequency : frequencies) {
212 |
213 | Float[] values = new Float[512];
214 | Float mean = 0.0f;
215 | Float absoluteMean = 0.0f;
216 | Gain gain = gainHashMap.get(frequency);
217 |
218 | for(int i = 0; i < 512; i++) {
219 | Float value = gain.getValue(0, i) / volumeLimit;
220 | values[i] = value;
221 | mean += value;
222 | absoluteMean += Math.abs(value);
223 | }
224 | mean /= 512.0f;
225 | absoluteMean /= 512.0f;
226 |
227 | if(frequency != 0) {
228 | mean -= cumulativeMean;
229 | cumulativeMean += mean;
230 | absoluteMean -= cumulativeAbsoluteMean;
231 | cumulativeAbsoluteMean += absoluteMean;
232 | }
233 |
234 | valuesHashMap.put(frequency, values);
235 | meansHashMap.put(frequency, mean);
236 | absoluteMeansHashMap.put(frequency, absoluteMean);
237 |
238 | }
239 |
240 | }
241 | public static float[] getValues(Integer frequency) {
242 | return Util.parseFloatArray(valuesHashMap.get(Util.parseFrequency(frequencies, frequency)));
243 | }
244 | public static float getMean(Integer frequency) {
245 | return meansHashMap.get(Util.parseFrequency(frequencies, frequency));
246 | }
247 | public static float getAbsoluteMean(Integer frequency) {
248 | return absoluteMeansHashMap.get(Util.parseFrequency(frequencies, frequency));
249 | }
250 |
251 | private static void initDisplay() {
252 |
253 | //Create display
254 | try {
255 | DisplayMode displayMode = null;
256 | DisplayMode[] modes = Display.getAvailableDisplayModes();
257 |
258 | if(fullscreen) {
259 | for (DisplayMode mode : modes) {
260 | if (mode.getWidth() == 1920
261 | && mode.getHeight() == 1080
262 | && mode.isFullscreenCapable()) {
263 | displayMode = mode;
264 | }
265 | }
266 | } else {
267 | displayMode = new DisplayMode(width, height);
268 | }
269 |
270 | Display.setDisplayMode(displayMode);
271 | Display.setFullscreen(true);
272 | Display.setResizable(false);
273 | Display.create();
274 | Display.setTitle("Active Visualiser (" + Display.getWidth() + "x" + Display.getHeight() + ")");
275 | } catch (LWJGLException e) {
276 | e.printStackTrace();
277 | System.exit(1);
278 | }
279 |
280 | Mouse.setCursorPosition(0, Display.getHeight());
281 |
282 | }
283 | private static void initRenderModes() {
284 | renderModes = new ArrayList();
285 |
286 | // Registering new render modes
287 | renderModes.add(new Pulse("Pulse", Keyboard.KEY_1));
288 | renderModes.add(new ShaderTest("Shader Test", Keyboard.KEY_5));
289 | renderModes.add(new Blur("Blur", Keyboard.KEY_4));
290 | renderModes.add(new Twist("Twist", Keyboard.KEY_3));
291 | renderModes.add(new Flow("Flow", Keyboard.KEY_2));
292 | renderModes.add(new Test("Test", Keyboard.KEY_T));
293 |
294 | if(renderModes.size() == 0) {
295 | System.out.println("No render modes available.");
296 | System.exit(1);
297 | }
298 |
299 | currentRenderMode = renderModes.get(0);
300 | }
301 | public static void initGL() {
302 | glViewport(0, 0, Display.getWidth(), Display.getHeight());
303 | glMatrixMode(GL_PROJECTION);
304 | glLoadIdentity();
305 | glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
306 | glMatrixMode(GL_MODELVIEW);
307 | }
308 | private static void initAudio() {
309 |
310 | if(active) {
311 | JavaSoundAudioIO io = new JavaSoundAudioIO();
312 | io.selectMixer(2);
313 | audioContext = new AudioContext(io);
314 | mainInput = audioContext.getAudioInput(channels);
315 | volumeLimit = 1.0f;
316 | } else {
317 | if(audio.equalsIgnoreCase("")) {
318 | JFileChooser fileChooser = new JFileChooser();
319 | fileChooser.setCurrentDirectory(new File("C:/Users/Timur Kuzhagaliyev/Music/Singles/"));
320 | int result = fileChooser.showOpenDialog(new JPanel());
321 | if (result != JFileChooser.APPROVE_OPTION) {
322 | System.exit(0);
323 | }
324 | audio = fileChooser.getSelectedFile().getPath();
325 | }
326 | audioContext = new AudioContext();
327 | mainInput = new SamplePlayer(audioContext, SampleManager.sample(audio));
328 | volumeLimit = 0.2f;
329 | }
330 |
331 | gainHashMap = new HashMap();
332 | for(Integer frequency : frequencies) {
333 |
334 | Gain gain;
335 | if(frequency == 0) {
336 | gain = new Gain(audioContext, 1, volumeLimit);
337 | gain.addInput(mainInput);
338 | } else {
339 | OnePoleFilter filter = new OnePoleFilter(audioContext, (float) frequency);
340 | filter.addInput(mainInput);
341 | gain = new Gain(audioContext, 2, volumeLimit);
342 | gain.addInput(filter);
343 | }
344 | audioContext.out.addInput(gain);
345 | gainHashMap.put(frequency, gain);
346 |
347 | }
348 |
349 | audioContext.start();
350 |
351 | }
352 | private static void loadFonts() {
353 | font = new UnicodeFont(new java.awt.Font("Times New Roman", java.awt.Font.PLAIN, 24));
354 | font.getEffects().add(new ColorEffect(java.awt.Color.white));
355 | font.addAsciiGlyphs();
356 | try { font.loadGlyphs(); }
357 | catch (SlickException e) {
358 | e.printStackTrace();
359 | }
360 | }
361 |
362 | private static void cleanUp() {
363 |
364 | Display.destroy();
365 | if(audioContext != null)
366 | audioContext.stop();
367 |
368 | }
369 |
370 | public static long getTime() {
371 | return (Sys.getTime() * 1000) / Sys.getTimerResolution();
372 | }
373 | public static float getDelta() {
374 | long currentTime = getTime();
375 | float delta = (float) currentTime - (float) lastFrame;
376 | lastFrame = getTime();
377 | return delta;
378 | }
379 |
380 | public static void echo(String string) {
381 | System.out.println(string);
382 | }
383 |
384 | }
385 |
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderMode.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser;
2 |
3 | /**
4 | * @author Timur Kuzhagaliyev
5 | * @since 05-12-2014
6 | */
7 |
8 | public abstract class RenderMode {
9 |
10 | private String name;
11 | private int key;
12 |
13 | public RenderMode(String name, int key) {
14 | this.name = name;
15 | this.key = key;
16 | }
17 |
18 | public abstract void render(float delta);
19 |
20 | public String getName() {
21 | return name;
22 | }
23 | public int getKey() {
24 | return key;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Blur.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderModes;
2 |
3 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.Core;
4 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderMode;
5 | import org.lwjgl.opengl.Display;
6 |
7 | import static org.lwjgl.opengl.GL11.*;
8 |
9 | /**
10 | * @author Timur Kuzhagaliyev
11 | * @since 08-12-2014
12 | */
13 |
14 | public class Blur extends RenderMode {
15 |
16 | private float[] actualValues;
17 | private float actualMean;
18 | private float actualBassMean;
19 |
20 | private float valueSpeed;
21 | private float meanSpeed;
22 |
23 | public Blur(String name, int key) {
24 | super(name, key);
25 | actualValues = new float[512];
26 | actualMean = 0.0f;
27 | actualBassMean = 0.0f;
28 | for(int i = 0; i < actualValues.length; i++)
29 | actualValues[i] = 0.0f;
30 |
31 | valueSpeed = 0.01f;
32 | meanSpeed = 0.01f;
33 | }
34 |
35 | public void render(float delta) {
36 |
37 | Core.initGL();
38 |
39 | float[] values = Core.getValues(0);
40 | float[] bassValues = Core.getValues(20);
41 |
42 | float mean = 0;
43 | float bassMean = 0;
44 | for (float i = 0.0f; i < 512.0f; i++) {
45 | mean += values[(int) i];
46 | bassMean += bassValues[(int) i];
47 | }
48 | mean /= 512.0f;
49 | bassMean /= 512.0f;
50 |
51 | if(Math.abs(mean) >= actualMean)
52 | actualMean += meanSpeed * 2;
53 | else if(actualMean > 0)
54 | actualMean -= meanSpeed;
55 |
56 | float displacementX = Display.getWidth() / 20 * bassMean;
57 | float displacementY = Display.getWidth() / 20 * bassMean;
58 |
59 | float rotationZ = Core.getTime();
60 |
61 | if(Math.abs(actualMean) >= 0.1f && actualValues[0] < 2)
62 | actualValues[0] += valueSpeed * 10;
63 | else if(actualValues[0] > 0)
64 | actualValues[0] -= valueSpeed / 2;
65 | if(Math.abs(actualMean) >= 0.2f && actualValues[1] < 2)
66 | actualValues[1] += valueSpeed * 10;
67 | else if(actualValues[1] > 0)
68 | actualValues[1] -= valueSpeed / 2;
69 | if(Math.abs(actualMean) >= 0.25f && actualValues[2] < 2)
70 | actualValues[2] += valueSpeed * 10;
71 | else if(actualValues[2] > 0)
72 | actualValues[2] -= valueSpeed / 2;
73 |
74 | float colour = 2.0f * mean * (2 - actualValues[0]);
75 |
76 | glClearColor(colour, colour, colour, 0);
77 |
78 | glPushMatrix();
79 | {
80 | glTranslatef(Display.getWidth() / 2, Display.getHeight() / 2, 0);
81 | glRotatef(rotationZ, 0, 0, 1);
82 |
83 |
84 | glPushMatrix();
85 | glRotatef(-rotationZ * 0.99f, 0, 0, 1);
86 | for(int i = 0; i < 32; i++) {
87 | glPushMatrix();
88 | {
89 | glRotatef(i * 11.25f, 0, 0, 1);
90 | drawCircle(0, actualValues[2] * Display.getHeight() / 4 + actualMean * Display.getHeight() / 20 + displacementX * 10 * bassMean, 10, 0, 0, 1);
91 | drawCircle(0, actualValues[2] * Display.getHeight() / 4 + actualMean * Display.getHeight() / 20 + displacementX * 10 * bassMean * bassMean, 10, 1, 0, 0);
92 | drawCircle(0, actualValues[2] * Display.getHeight() / 4 + actualMean * Display.getHeight() / 20, 10, 1, 1, 1);
93 | }
94 | glPopMatrix();
95 | }
96 | glPopMatrix();
97 |
98 | glPushMatrix();
99 | glRotatef(-rotationZ * 1.01f, 0, 0, 1);
100 | for(int i = 0; i < 16; i++) {
101 | glPushMatrix();
102 | {
103 | glRotatef(i * 22.5f, 0, 0, 1);
104 | drawCircle(0, actualValues[1] * Display.getHeight() / 6 + actualMean * Display.getHeight() / 20 + displacementX * 10 * bassMean, 15, 0, 0, 1);
105 | drawCircle(0, actualValues[1] * Display.getHeight() / 6 + actualMean * Display.getHeight() / 20 + displacementX * 10 * bassMean * bassMean, 15, 1, 0, 0);
106 | drawCircle(0, actualValues[1] * Display.getHeight() / 6 + actualMean * Display.getHeight() / 20, 15, 1, 1, 1);
107 | }
108 | glPopMatrix();
109 | }
110 | glPopMatrix();
111 |
112 | glPushMatrix();
113 | glRotatef(-rotationZ * 0.99f, 0, 0, 1);
114 | for(int i = 0; i < 8; i++) {
115 | glPushMatrix();
116 | {
117 | glRotatef(i * 45, 0, 0, 1);
118 | drawCircle(0, actualValues[0] * Display.getHeight() / 10 + actualMean * Display.getHeight() / 20 + displacementX * 10 * bassMean, 20, 0, 0, 1);
119 | drawCircle(0, actualValues[0] * Display.getHeight() / 10 + actualMean * Display.getHeight() / 20 + displacementX * 10 * bassMean * bassMean, 20, 1, 0, 0);
120 | drawCircle(0, actualValues[0] * Display.getHeight() / 10 + actualMean * Display.getHeight() / 20, 20, 1, 1, 1);
121 | }
122 | glPopMatrix();
123 | }
124 | glPopMatrix();
125 |
126 | glPushMatrix();
127 | {
128 | glTranslatef(displacementX, displacementY, 0);
129 | drawCircle(0, 0, Display.getHeight() / 12 * (1 + actualMean), 0, 0, 1);
130 | }
131 | glPopMatrix();
132 | glPushMatrix();
133 | {
134 | glTranslatef(- displacementX, - displacementY, 0);
135 | drawCircle(0, 0, Display.getHeight() / 12 * (1 + actualMean), 1, 0, 0);
136 | }
137 | glPopMatrix();
138 | glPushMatrix();
139 | {
140 | drawCircle(0, 0, Display.getHeight() / 12 * (1 + actualMean), 1f, 1f, 1f);
141 | }
142 | glPopMatrix();
143 | }
144 | glPopMatrix();
145 |
146 | }
147 |
148 | public void drawCircle(float x, float y, float radius, float r, float g, float b) {
149 | glPushMatrix();
150 | {
151 | glColor3f(r, g, b);
152 | glTranslatef(x, y, 0);
153 | glScalef(radius, radius, 0);
154 | glBegin(GL_TRIANGLE_FAN);
155 | {
156 | glVertex2f(0, 0);
157 | for (int i = 0; i <= 80; i++) { //NUM_PIZZA_SLICES decides how round the circle looks.
158 | double angle = Math.PI * 2 * i / 80;
159 | glVertex2f((float) Math.cos(angle), (float) Math.sin(angle));
160 | }
161 | }
162 | glEnd();
163 | }
164 | glPopMatrix();
165 | }
166 |
167 | }
168 |
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Flow.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderModes;
2 |
3 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.Core;
4 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderMode;
5 | import org.lwjgl.opengl.Display;
6 |
7 | import java.util.ArrayList;
8 | import java.util.Random;
9 |
10 | import static org.lwjgl.opengl.GL11.*;
11 |
12 | /**
13 | * @author Timur Kuzhagaliyev
14 | * @since 06-12-2014
15 | */
16 |
17 | public class Flow extends RenderMode {
18 |
19 | private ArrayList flowParticles;
20 |
21 | private float[] savedValues;
22 |
23 | public Flow(String name, int key) {
24 | super(name, key);
25 |
26 | flowParticles = new ArrayList();
27 | savedValues = new float[512];
28 |
29 | for(int i = 0; i < 512; i++)
30 | savedValues[i] = 0.0f;
31 |
32 | }
33 |
34 | public void render(float delta) {
35 |
36 | Core.initGL();
37 |
38 | float[] values = Core.getValues(0);
39 | float[] bassValues = Core.getValues(20);
40 |
41 | float mean = 0;
42 | float bassMean = 0;
43 | for (float i = 0.0f; i < 512.0f; i++) {
44 | mean += values[(int) i];
45 | bassMean += bassValues[(int) i];
46 | }
47 | mean /= 512.0f;
48 | bassMean /= 512.0f;
49 |
50 | Random random = new Random();
51 |
52 | while(flowParticles.size() < 400) {
53 | float randomiser = random.nextFloat();
54 | float randomiser2 = random.nextFloat();
55 | float multiplier = (random.nextFloat() + 1.0f) * 0.5f;
56 | flowParticles.add(new FlowParticle(-20.0f * (1 - multiplier) * 2, Display.getHeight() * randomiser, 20.0f * (1 - multiplier), 20.0f * multiplier, 50.0f * multiplier, 2 * (float) Math.PI * randomiser2, 0.05f));
57 | }
58 |
59 | ArrayList deathRow = new ArrayList();
60 | for(FlowParticle flowParticle : flowParticles) {
61 | if(flowParticle.getPosX() > Display.getWidth() + flowParticle.getRadius() * 2) {
62 | deathRow.add(flowParticle);
63 | }
64 | flowParticle.render(delta, mean, bassMean);
65 | }
66 | for(FlowParticle flowParticle : deathRow)
67 | flowParticles.remove(flowParticle);
68 |
69 | glPushMatrix();
70 | {
71 | glColor3f(1, 1, 1);
72 | float step = Display.getWidth() / 512.0f;
73 | glBegin(GL_LINE_LOOP);
74 | {
75 | glVertex2f(-100, -100);
76 | glVertex2f(-100, Display.getHeight() / 2);
77 |
78 | for(int i = 0; i < 512; i++) {
79 | float actualValue = savedValues[i] + (- savedValues[i] + values[i]) * 0.01f;
80 | savedValues[i] = actualValue;
81 | glVertex2f(step * i + step, - 100 + Display.getHeight() / 2 + Display.getHeight() * actualValue);
82 | }
83 |
84 | glVertex2f(Display.getWidth(), Display.getHeight() / 2);
85 | glVertex2f(Display.getWidth() + 100, -100);
86 | }
87 | glEnd();
88 | glBegin(GL_LINE_LOOP);
89 | {
90 | glVertex2f(-100, -100);
91 | glVertex2f(-100, Display.getHeight() / 2);
92 |
93 | for(int i = 0; i < 512; i++) {
94 | float actualValue = savedValues[i] + (- savedValues[i] + values[i]) * 0.01f;
95 | savedValues[i] = actualValue;
96 | glVertex2f(step * i + step, 100 + Display.getHeight() / 2 - Display.getHeight() * actualValue);
97 | }
98 |
99 | glVertex2f(Display.getWidth(), Display.getHeight() / 2);
100 | glVertex2f(Display.getWidth() + 100, -100);
101 | }
102 | glEnd();
103 | }
104 | glPopMatrix();
105 |
106 |
107 | }
108 |
109 | public static int randInt(int min, int max) {
110 | Random rand = new Random();
111 |
112 | return rand.nextInt((max - min) + 1) + min;
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/FlowParticle.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderModes;
2 |
3 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.Util;
4 |
5 | /**
6 | * @author Timur Kuzhagaliyev
7 | * @since 06-12-2014
8 | */
9 |
10 | public class FlowParticle {
11 |
12 | float posX;
13 | float posY;
14 | float displacementY;
15 | float radius;
16 |
17 | float speed;
18 | float curvature;
19 | float phase;
20 |
21 | float r;
22 | float g;
23 | float b;
24 |
25 | public FlowParticle(float posX, float posY, float radius, float speed, float curvature, float phase, float r, float g, float b) {
26 | this.posX = posX;
27 | this.posY = posY;
28 | this.displacementY = 0;
29 | this.radius = radius;
30 | this.speed = speed;
31 | this.curvature = curvature;
32 | this.phase = phase;
33 | this.r = r;
34 | this.g = g;
35 | this.b = b;
36 | }
37 |
38 | public FlowParticle(float posX, float posY, float radius, float speed, float curvature, float phase, float colour) {
39 | this.posX = posX;
40 | this.posY = posY;
41 | this.radius = radius;
42 | this.speed = speed;
43 | this.curvature = curvature;
44 | this.phase = phase;
45 | this.r = colour;
46 | this.g = colour;
47 | this.b = colour;
48 | }
49 |
50 | public FlowParticle(float posX, float posY, float radius, float speed, float curvature, float phase) {
51 | this.posX = posX;
52 | this.posY = posY;
53 | this.radius = radius;
54 | this.speed = speed;
55 | this.curvature = curvature;
56 | this.phase = phase;
57 | this.r = 1;
58 | this.g = 1;
59 | this.b = 1;
60 | }
61 |
62 | public void render(float delta, float mean, float value) {
63 |
64 | posX += speed * 0.25 + speed * 0.75 * Math.abs(mean) - speed * 5 * Math.abs(value);
65 |
66 | displacementY = (float) Math.sin(posX / 100.0f + phase) * curvature;
67 |
68 | Util.drawCircle(posX, posY + displacementY, radius + radius * 2 * Math.abs(value), r + 0.5f * Math.abs(value), g + 0.5f * Math.abs(value), b + 0.5f * Math.abs(value));
69 |
70 | }
71 |
72 | public float getPosX() {
73 | return posX;
74 | }
75 |
76 | public float getRadius() {
77 | return radius;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Pulse.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderModes;
2 |
3 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.Core;
4 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderMode;
5 | import org.lwjgl.opengl.Display;
6 |
7 | import static org.lwjgl.opengl.GL11.*;
8 |
9 | /**
10 | * @author Timur Kuzhagaliyev
11 | * @since 05-12-2014
12 | */
13 |
14 | public class Pulse extends RenderMode {
15 |
16 | public Pulse(String name, int key) {
17 | super(name, key);
18 | }
19 |
20 | public void render(float delta) {
21 |
22 | Core.initGL();
23 |
24 | float[] values = Core.getValues(0);
25 | float[] bassValues = Core.getValues(20);
26 |
27 | float mean = 0;
28 | float bassMean = 0;
29 | for (float i = 0.0f; i < 512.0f; i++) {
30 | mean += values[(int) i];
31 | bassMean += bassValues[(int) i];
32 | }
33 | mean /= 512.0f;
34 | bassMean /= 512.0f;
35 |
36 | float barHeight = Display.getHeight() / 2 * 0.8f * 0.4f;
37 | float indent = Display.getHeight() / 2 * 0.8f * 0.4f;
38 | float multiplier = Display.getHeight() / 2 * 0.8f * 0.6f;
39 | int barsNum = 8;
40 |
41 | float value = 0;
42 | float bassValue = 0;
43 |
44 | float barWidth = Display.getWidth() / 512.0f;
45 | for (float i = 0.0f; i < 512.0f; i++) {
46 | value += values[(int) i];
47 | bassValue += bassValues[(int) i];
48 | if((i + 1) % (float) barsNum == 0) {
49 | value /= barsNum;
50 | bassValue /= barsNum;
51 | glPushMatrix();
52 | {
53 | glTranslatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);
54 | glRotatef(i * 360.0f / 512.0f + System.nanoTime() / 100000000.0f, 0, 0, 1.0f);
55 | glColor3f(Math.abs(bassMean), Math.abs(bassMean), Math.abs(bassMean));
56 | glBegin(GL_QUADS);
57 | {
58 | glVertex2f(-barWidth, indent + barHeight);
59 | glVertex2f(-barWidth, indent + multiplier * Math.abs(bassMean));
60 | glVertex2f(barWidth, indent + multiplier * Math.abs(bassMean));
61 | glVertex2f(barWidth, indent + barHeight);
62 | }
63 | glEnd();
64 | }
65 | glPopMatrix();
66 | glPushMatrix();
67 | {
68 | glTranslatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);
69 | glRotatef(i * 360.0f / 512.0f - System.nanoTime() / 100000000.0f, 0, 0, 1.0f);
70 | glBegin(GL_QUADS);
71 | {
72 | glColor3f(Math.abs(value), 1 - Math.abs(value), Math.abs(mean));
73 | glVertex2f(-barWidth, indent * 2 + multiplier + multiplier * Math.abs(value) / 2 + multiplier * Math.abs(mean) * Math.abs(value) / 2);
74 | glColor3f(Math.abs(value) * Math.abs(mean), (1 - Math.abs(value)) * Math.abs(mean), Math.abs(mean));
75 | glVertex2f(-barWidth, indent + multiplier);
76 | glVertex2f(barWidth, indent + multiplier);
77 | glColor3f(Math.abs(value), 1 - Math.abs(value), Math.abs(mean));
78 | glVertex2f(barWidth, indent * 2 + multiplier + multiplier * Math.abs(value) / 2 + multiplier * Math.abs(mean) * Math.abs(value) / 2);
79 | }
80 | glEnd();
81 | }
82 | glPopMatrix();
83 | }
84 | }
85 |
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/ShaderTest.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderModes;
2 |
3 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.Core;
4 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderMode;
5 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.Util;
6 | import org.lwjgl.opengl.*;
7 | import org.lwjgl.util.glu.GLU;
8 |
9 | import static org.lwjgl.opengl.GL11.*;
10 |
11 | /**
12 | * @author Timur Kuzhagaliyev
13 | * @since 13-12-2014
14 | */
15 |
16 | public class ShaderTest extends RenderMode {
17 |
18 | int program;
19 | boolean useShader;
20 |
21 | public ShaderTest(String name, int key) {
22 | super(name, key);
23 |
24 | int vertShader = 0, fragShader = 0;
25 |
26 | try {
27 | vertShader = Util.createShader("D:/Workspaces/Java/Workspace/Active Visualiser/res/ShaderTest_Vertex.glsl", ARBVertexShader.GL_VERTEX_SHADER_ARB);
28 | fragShader = Util.createShader("D:/Workspaces/Java/Workspace/Active Visualiser/res/ShaderTest_Fragment.glsl", ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
29 | }
30 | catch(Exception exc) {
31 | exc.printStackTrace();
32 | return;
33 | }
34 | finally {
35 | if(vertShader == 0 || fragShader == 0)
36 | return;
37 | }
38 | program = ARBShaderObjects.glCreateProgramObjectARB();
39 | if(program == 0)
40 | return;
41 | ARBShaderObjects.glAttachObjectARB(program, vertShader);
42 | ARBShaderObjects.glAttachObjectARB(program, fragShader);
43 | ARBShaderObjects.glLinkProgramARB(program);
44 | if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE) {
45 | System.err.println(Util.getLogInfo(program));
46 | return;
47 | }
48 | ARBShaderObjects.glValidateProgramARB(program);
49 | if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB) == GL11.GL_FALSE) {
50 | System.err.println(Util.getLogInfo(program));
51 | return;
52 | }
53 |
54 | useShader = true;
55 |
56 | }
57 |
58 | public void render(float delta) {
59 |
60 | glViewport(0, 0, Display.getWidth(), Display.getHeight());
61 | glMatrixMode(GL_PROJECTION);
62 | glLoadIdentity();
63 | GLU.gluPerspective(45.0f, ((float) Display.getWidth() / (float) Display.getHeight()), 0.1f, 100.0f);
64 | glMatrixMode(GL_MODELVIEW);
65 | glLoadIdentity();
66 | glShadeModel(GL_SMOOTH);
67 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
68 | glClearDepth(1.0f);
69 | glEnable(GL_DEPTH_TEST);
70 | glDepthFunc(GL_LEQUAL);
71 | glHint(GL_PERSPECTIVE_CORRECTION_HINT,
72 | GL_NICEST);
73 |
74 | if(useShader)
75 | ARBShaderObjects.glUseProgramObjectARB(program);
76 |
77 | glLoadIdentity();
78 | glTranslatef(0.0f, 0.0f, -10.0f);
79 | glColor3f(1.0f, 1.0f, 1.0f);//white
80 |
81 | int location = GL20.glGetUniformLocation(program, "mean");
82 | GL20.glUniform1f(location, Math.abs(Core.getMean(0)));
83 |
84 | glPushMatrix();
85 | Util.drawCircle(0, 0,1, 1);
86 | glPopMatrix();
87 |
88 | glPushMatrix();
89 | glTranslatef(-3.0f, 0, 0);
90 | glBegin(GL_QUADS);
91 | glVertex3f(-1.0f, 1.0f + Math.abs(Core.getMean(0)), 0.0f);
92 | glVertex3f(1.0f, 1.0f + Math.abs(Core.getMean(0)), 0.0f);
93 | glVertex3f(1.0f + Math.abs(Core.getMean(0)), -1.0f, 0.0f);
94 | glVertex3f(-1.0f - Math.abs(Core.getMean(0)), -1.0f, 0.0f);
95 | glEnd();
96 | glPopMatrix();
97 |
98 | glPushMatrix();
99 | glTranslatef(3.0f, 0, 0);
100 | glBegin(GL_QUADS);
101 | glVertex3f(-1.0f, 1.0f + Math.abs(Core.getMean(0)), 0.0f);
102 | glVertex3f(1.0f, 1.0f + Math.abs(Core.getMean(0)), 0.0f);
103 | glVertex3f(1.0f + Math.abs(Core.getMean(0)), -1.0f, 0.0f);
104 | glVertex3f(-1.0f - Math.abs(Core.getMean(0)), -1.0f, 0.0f);
105 | glEnd();
106 | glPopMatrix();
107 |
108 | //release the shader
109 | if(useShader)
110 | ARBShaderObjects.glUseProgramObjectARB(0);
111 |
112 | }
113 |
114 | }
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Test.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderModes;
2 |
3 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderMode;
4 | import org.lwjgl.opengl.Display;
5 |
6 | import static org.lwjgl.opengl.GL11.*;
7 |
8 | /**
9 | * @author Timur Kuzhagaliyev
10 | * @since 05-12-2014
11 | */
12 |
13 | public class Test extends RenderMode {
14 |
15 | public Test(String name, int key) {
16 | super(name, key);
17 | }
18 |
19 | public void render(float delta) {
20 |
21 | glPushMatrix();
22 | {
23 | glColor3f(1.0f, 1.0f, 1.0f);
24 | glBegin(GL_QUADS);
25 | {
26 | glVertex2f(0, Display.getHeight() / 2 - 1);
27 | glVertex2f(0, Display.getHeight() / 2 + 1);
28 | glVertex2f(Display.getWidth(), Display.getHeight() / 2 + 1);
29 | glVertex2f(Display.getWidth(), Display.getHeight() / 2 - 1);
30 | }
31 | glEnd();
32 | glBegin(GL_QUADS);
33 | {
34 | glVertex2f(Display.getWidth() / 2 - 1, 0);
35 | glVertex2f(Display.getWidth() / 2 - 1, Display.getHeight());
36 | glVertex2f(Display.getWidth() / 2 + 1, Display.getHeight());
37 | glVertex2f(Display.getWidth() / 2 + 1, 0);
38 | }
39 | glEnd();
40 | }
41 | glPopMatrix();
42 |
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/RenderModes/Twist.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderModes;
2 |
3 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.Core;
4 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.RenderMode;
5 | import kz.kuzhagaliyev.TimboKZ.ActiveVisualiser.Util;
6 | import org.lwjgl.opengl.Display;
7 |
8 | import static org.lwjgl.opengl.GL11.*;
9 |
10 | /**
11 | * @author Timur Kuzhagaliyev
12 | * @since 06-12-2014
13 | */
14 |
15 | public class Twist extends RenderMode {
16 |
17 | private float actualMean = 0.0f;
18 | private float actualBassMean = 0.0f;
19 |
20 | public Twist(String name, int key) {
21 | super(name, key);
22 | }
23 |
24 | public void render(float delta) {
25 |
26 | Core.initGL();
27 |
28 | float[] values = Core.getValues(0);
29 | float[] bassValues = Core.getValues(20);
30 |
31 | float mean = 0;
32 | float bassMean = 0;
33 | for (float i = 0.0f; i < 512.0f; i++) {
34 | mean += values[(int) i];
35 | bassMean += bassValues[(int) i];
36 | }
37 | mean /= 512.0f;
38 | bassMean /= 512.0f;
39 |
40 | mean = values[0];
41 |
42 | actualMean = Util.smooth(actualMean, Math.abs(mean), 0.01f);
43 | actualBassMean = Util.smooth(actualBassMean, Math.abs(bassMean), 0.01f);
44 |
45 | mean = actualMean;
46 | bassMean = actualBassMean;
47 |
48 | float amplitude = 100 + 400 * bassMean;
49 | float sinMultiplier = 0.01f + bassMean * 0.01f;
50 | float indent = 10;
51 | float height = 5;
52 | float width = 10;
53 | int segments = 200;
54 | int turns = 24;
55 | float adjustment = -200 * mean;
56 | float rotation = Core.getTime() * 0.01f;
57 |
58 | glPushMatrix();
59 | {
60 | glTranslatef(Display.getWidth() / 2, Display.getHeight() / 2, 0);
61 | glRotatef(rotation, 0, 0, 1);
62 |
63 | for(int i = 0; i < turns; i++) {
64 |
65 | glPushMatrix();
66 | glRotatef(360.0f / (float) turns * (float) i, 0, 0, 1);
67 | glPushMatrix();
68 | glTranslatef(-width / 2, 0, 0);
69 | for(int k = 0; k < segments; k++) {
70 | float progress = (float) k / (float) segments;
71 | float nextStep = (float) (k + 1) / (float) segments;
72 | glPushMatrix();
73 | {
74 | if(k % 2 == 0) {
75 | glColor3f(bassValues[(int) (512.0f * progress)], bassValues[(int) (512.0f * progress)], bassValues[(int) (512.0f * progress)]);
76 | } else {
77 | glColor3f(0, 0, 0);
78 | }
79 | glTranslatef(0, indent + k * height, 0);
80 | glBegin(GL_QUADS);
81 | {
82 | glVertex2f((float) Math.sin(k * height * sinMultiplier) * amplitude + adjustment * progress * progress, 0);
83 | glVertex2f((float) Math.sin((k + 1) * height * sinMultiplier) * amplitude + adjustment * nextStep * nextStep, height);
84 | glVertex2f((float) Math.sin((k + 1) * height * sinMultiplier) * amplitude + width + adjustment * nextStep * nextStep, height);
85 | glVertex2f((float) Math.sin(k * height * sinMultiplier) * amplitude + width + adjustment * progress * progress, 0);
86 | }
87 | glEnd();
88 | }
89 | glPopMatrix();
90 |
91 | }
92 | glPopMatrix();
93 | glPopMatrix();
94 |
95 | }
96 | }
97 | glPopMatrix();
98 |
99 | }
100 |
101 |
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/kz/kuzhagaliyev/TimboKZ/ActiveVisualiser/Util.java:
--------------------------------------------------------------------------------
1 | package kz.kuzhagaliyev.TimboKZ.ActiveVisualiser;
2 |
3 | import org.lwjgl.opengl.ARBShaderObjects;
4 | import org.lwjgl.opengl.GL11;
5 |
6 | import java.io.BufferedReader;
7 | import java.io.FileInputStream;
8 | import java.io.InputStreamReader;
9 |
10 | import static org.lwjgl.opengl.GL11.*;
11 |
12 | /**
13 | * @author Timur Kuzhagaliyev
14 | * @since 12-12-2014
15 | */
16 |
17 | public class Util {
18 |
19 | public static float smooth(float value, float target, float rate) {
20 |
21 | if(value < target) {
22 | value += rate;
23 | }
24 | if(value > target) {
25 | value -= rate;
26 | }
27 |
28 | return value;
29 |
30 | }
31 |
32 | public static void drawRect(float x, float y, float width, float height, float colour) {
33 |
34 | drawRect(x, y, width, height, colour, colour, colour);
35 |
36 | }
37 |
38 | public static void drawRect(float x, float y, float width, float height, float r, float g, float b) {
39 |
40 | glPushMatrix();
41 | {
42 | glColor3f(r, g, b);
43 | glBegin(GL_QUADS);
44 | {
45 | glVertex2f(x, y);
46 | glVertex2f(x, y + height);
47 | glVertex2f(x + width, y + height);
48 | glVertex2f(x + width, y);
49 | }
50 | glEnd();
51 | }
52 | glPopMatrix();
53 |
54 | }
55 |
56 | public static void drawCircle(float x, float y, float radius, float colour) {
57 |
58 | drawCircle(x, y, radius, colour, colour, colour);
59 |
60 | }
61 |
62 | public static void drawCircle(float x, float y, float radius, float r, float g, float b) {
63 | glPushMatrix();
64 | {
65 | glColor3f(r, g, b);
66 | glTranslatef(x, y, 0);
67 | glScalef(radius, radius, 0);
68 | glBegin(GL_TRIANGLE_FAN);
69 | {
70 | glVertex2f(0, 0);
71 | for (int i = 0; i <= 80; i++) { //NUM_PIZZA_SLICES decides how round the circle looks.
72 | double angle = Math.PI * 2 * i / 80;
73 | glVertex2f((float) Math.cos(angle), (float) Math.sin(angle));
74 | }
75 | }
76 | glEnd();
77 | }
78 | glPopMatrix();
79 | }
80 |
81 | public static Integer parseFrequency(Integer[] values, Integer value) {
82 |
83 |
84 | int difference = Math.abs(values[0] - value);
85 | int counter = 0;
86 |
87 | for(int i = 1; i < values.length; i++) {
88 |
89 | int currentDifference = Math.abs(values[i] - value);
90 |
91 | if(currentDifference < difference) {
92 | difference = currentDifference;
93 | counter = i;
94 | }
95 |
96 | }
97 |
98 | return values[counter];
99 |
100 | }
101 |
102 | public static float[] parseFloatArray(Float[] values) {
103 | float[] newValues = new float[values.length];
104 | for(int i = 0; i < values.length; i++) {
105 | newValues[i] = values[i];
106 | }
107 | return newValues;
108 | }
109 |
110 | public static int createShader(String filename, int shaderType) throws Exception {
111 | int shader = 0;
112 | try {
113 | shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);
114 |
115 | if(shader == 0)
116 | return 0;
117 |
118 | ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
119 | ARBShaderObjects.glCompileShaderARB(shader);
120 |
121 | if (ARBShaderObjects.glGetObjectParameteriARB(shader, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE)
122 | throw new RuntimeException("Error creating shader: " + getLogInfo(shader));
123 |
124 | return shader;
125 | }
126 | catch(Exception exc) {
127 | ARBShaderObjects.glDeleteObjectARB(shader);
128 | throw exc;
129 | }
130 | }
131 |
132 | public static String getLogInfo(int obj) {
133 | return ARBShaderObjects.glGetInfoLogARB(obj, ARBShaderObjects.glGetObjectParameteriARB(obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB));
134 | }
135 |
136 | public static String readFileAsString(String filename) throws Exception {
137 | StringBuilder source = new StringBuilder();
138 |
139 | FileInputStream in = new FileInputStream(filename);
140 |
141 | Exception exception = null;
142 |
143 | BufferedReader reader;
144 | try{
145 | reader = new BufferedReader(new InputStreamReader(in,"UTF-8"));
146 |
147 | Exception innerExc= null;
148 | try {
149 | String line;
150 | while((line = reader.readLine()) != null)
151 | source.append(line).append('\n');
152 | }
153 | catch(Exception exc) {
154 | exception = exc;
155 | }
156 | finally {
157 | try {
158 | reader.close();
159 | }
160 | catch(Exception exc) {
161 | if(innerExc == null)
162 | innerExc = exc;
163 | else
164 | exc.printStackTrace();
165 | }
166 | }
167 |
168 | if(innerExc != null)
169 | throw innerExc;
170 | }
171 | catch(Exception exc) {
172 | exception = exc;
173 | }
174 | finally {
175 | try {
176 | in.close();
177 | }
178 | catch(Exception exc) {
179 | if(exception == null)
180 | exception = exc;
181 | else
182 | exc.printStackTrace();
183 | }
184 |
185 | if(exception != null)
186 | throw exception;
187 | }
188 |
189 | return source.toString();
190 | }
191 |
192 | public static boolean isInRange(float value, float lowerLimit, float upperLimit) {
193 |
194 | return (value >= lowerLimit && value <= upperLimit);
195 |
196 | }
197 |
198 | }
199 |
--------------------------------------------------------------------------------