├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── headers ├── Complex3D.hpp ├── FractalData.hpp ├── FractalPoint.hpp ├── FractalWidget.hpp ├── GeometryEngine.hpp ├── MainWindow.hpp └── Recorder.hpp ├── main.cpp ├── shaders ├── fshader.glsl ├── shaders.qrc └── vshader.glsl ├── src ├── Complex3D.cpp ├── FractalData.cpp ├── FractalPoint.cpp ├── FractalWidget.cpp ├── GeometryEngine.cpp ├── MainWindow.cpp └── Recorder.cpp └── ui └── mainwindow.ui /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | AccessModifierOffset: -4 3 | AlignAfterOpenBracket: Align 4 | AlignConsecutiveAssignments: false 5 | AlignOperands: true 6 | AllowAllArgumentsOnNextLine: false 7 | AllowAllConstructorInitializersOnNextLine: false 8 | AllowAllParametersOfDeclarationOnNextLine: false 9 | AllowShortBlocksOnASingleLine: Always 10 | AllowShortCaseLabelsOnASingleLine: false 11 | AllowShortFunctionsOnASingleLine: All 12 | AllowShortIfStatementsOnASingleLine: Always 13 | AllowShortLambdasOnASingleLine: All 14 | AllowShortLoopsOnASingleLine: true 15 | AlwaysBreakAfterReturnType: None 16 | AlwaysBreakTemplateDeclarations: Yes 17 | BreakBeforeBraces: Custom 18 | BraceWrapping: 19 | AfterCaseLabel: false 20 | AfterClass: false 21 | AfterControlStatement: Never 22 | AfterEnum: false 23 | AfterFunction: false 24 | AfterNamespace: false 25 | AfterUnion: false 26 | BeforeCatch: false 27 | BeforeElse: false 28 | IndentBraces: false 29 | SplitEmptyFunction: false 30 | SplitEmptyRecord: true 31 | BreakBeforeBinaryOperators: None 32 | BreakBeforeTernaryOperators: true 33 | BreakConstructorInitializers: BeforeColon 34 | BreakInheritanceList: BeforeColon 35 | ColumnLimit: 0 36 | CompactNamespaces: false 37 | ContinuationIndentWidth: 8 38 | IndentCaseLabels: true 39 | IndentPPDirectives: None 40 | IndentWidth: 4 41 | KeepEmptyLinesAtTheStartOfBlocks: true 42 | MaxEmptyLinesToKeep: 2 43 | NamespaceIndentation: All 44 | ObjCSpaceAfterProperty: false 45 | ObjCSpaceBeforeProtocolList: true 46 | PointerAlignment: Right 47 | ReflowComments: false 48 | SpaceAfterCStyleCast: true 49 | SpaceAfterLogicalNot: false 50 | SpaceAfterTemplateKeyword: false 51 | SpaceBeforeAssignmentOperators: true 52 | SpaceBeforeCpp11BracedList: false 53 | SpaceBeforeCtorInitializerColon: true 54 | SpaceBeforeInheritanceColon: true 55 | SpaceBeforeParens: Never 56 | SpaceBeforeRangeBasedForLoopColon: true 57 | SpaceInEmptyParentheses: false 58 | SpacesBeforeTrailingComments: 0 59 | SpacesInAngles: false 60 | SpacesInCStyleCastParentheses: false 61 | SpacesInContainerLiterals: false 62 | SpacesInParentheses: false 63 | SpacesInSquareBrackets: false 64 | TabWidth: 4 65 | UseTab: ForContinuationAndIndentation 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | 3 | cmake-build-debug/ 4 | 5 | # Prerequisites 6 | *.d 7 | 8 | # Compiled Object files 9 | *.slo 10 | *.lo 11 | *.o 12 | *.obj 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Compiled Dynamic libraries 19 | *.so 20 | *.dylib 21 | *.dll 22 | 23 | # Fortran module files 24 | *.mod 25 | *.smod 26 | 27 | # Compiled Static libraries 28 | *.lai 29 | *.la 30 | *.a 31 | *.lib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.19.3) 2 | project(fractals3d LANGUAGES CXX) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | set(CMAKE_CXX_STANDARD_REQUIRED True) 6 | set(CMAKE_AUTOMOC ON) 7 | set(CMAKE_AUTORCC ON) 8 | set(CMAKE_AUTOUIC ON) 9 | #set(DEBUG True) 10 | set(CMAKE_BUILD_TYPE Release) 11 | set(DEBUG False) 12 | 13 | set(CMAKE_INCLUDE_CURRENT_DIR ON) # ? 14 | 15 | set(INSTALL_DIR "./") 16 | 17 | set(QT_VERSION 6) 18 | set(QT_LIB_PREF Qt${QT_VERSION}::) 19 | 20 | set(REQUIRED_LIBS Core Gui Widgets OpenGL OpenGLWidgets) 21 | set(REQUIRED_LIBS_QUALIFIED ${QT_LIB_PREF}Core ${QT_LIB_PREF}Gui ${QT_LIB_PREF}Widgets ${QT_LIB_PREF}OpenGL ${QT_LIB_PREF}OpenGLWidgets) 22 | 23 | add_compile_options(-Wall -Wextra -O3 -ffast-math) 24 | if(UNIX AND DEBUG) 25 | add_compile_options(-fsanitize=address) 26 | add_link_options(-fsanitize=address) 27 | endif(UNIX AND DEBUG) 28 | 29 | include_directories(headers) 30 | 31 | set(CMAKE_AUTOUIC_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/ui") 32 | 33 | add_executable(${PROJECT_NAME} 34 | main.cpp 35 | headers/MainWindow.hpp src/MainWindow.cpp ui/mainwindow.ui 36 | headers/FractalWidget.hpp src/FractalWidget.cpp 37 | headers/FractalData.hpp src/FractalData.cpp 38 | headers/GeometryEngine.hpp src/GeometryEngine.cpp 39 | headers/FractalPoint.hpp src/FractalPoint.cpp 40 | headers/Complex3D.hpp src/Complex3D.cpp 41 | headers/Recorder.hpp src/Recorder.cpp 42 | shaders/shaders.qrc 43 | ) 44 | 45 | find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED) 46 | target_link_libraries(${PROJECT_NAME} PUBLIC ${REQUIRED_LIBS_QUALIFIED}) 47 | 48 | set_target_properties(${PROJECT_NAME} PROPERTIES 49 | WIN32_EXECUTABLE TRUE 50 | MACOSX_BUNDLE TRUE 51 | AUTOMOC TRUE # for color picker 52 | ) 53 | #if (NOT CMAKE_PREFIX_PATH) 54 | # message(WARNING "CMAKE_PREFIX_PATH is not defined, you may need to set it " 55 | # "(-DCMAKE_PREFIX_PATH=\"path/to/Qt/lib/cmake\" or -DCMAKE_PREFIX_PATH=/usr/include/{host}/qt{version}/ on Ubuntu)") 56 | #endif (NOT CMAKE_PREFIX_PATH) 57 | 58 | # Resources 59 | set(shaders_resource_files 60 | "fshader.glsl" 61 | "vshader.glsl" 62 | ) 63 | 64 | #qt_add_resources(fractals3d "shaders" PREFIX "/" FILES ${shaders_resource_files}) 65 | # End resources 66 | 67 | install(TARGETS fractals3d 68 | RUNTIME DESTINATION "${INSTALL_DIR}" 69 | BUNDLE DESTINATION "${INSTALL_DIR}" 70 | LIBRARY DESTINATION "${INSTALL_DIR}" 71 | ) 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fractals 3D 2 | 3 | **Fractals 3D** is a program designed for exploring three-dimensional fractals. Made by the three students of the HSE University Saint Petersburg campus. 4 | 5 | **Authors:** Sergey Zhuravlev, Stepan Konstantinov, Daria Ledneva 6 | 7 | **Mentor:** Anton Sosnin -------------------------------------------------------------------------------- /headers/Complex3D.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Complex3D { 6 | private: 7 | qreal x = 0; 8 | qreal y = 0; 9 | qreal z = 0; 10 | 11 | public: 12 | Complex3D() = default; 13 | 14 | Complex3D(qreal newx, qreal newy, qreal newz); 15 | 16 | [[nodiscard]] qreal theta() const; 17 | 18 | [[nodiscard]] qreal phi() const; 19 | 20 | [[nodiscard]] qreal abs() const; 21 | 22 | friend void operator^(Complex3D &z, int const &n); 23 | 24 | friend Complex3D operator+(Complex3D a, Complex3D b); 25 | }; 26 | -------------------------------------------------------------------------------- /headers/FractalData.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | enum FractalType { 13 | MANDELBROT, 14 | PSYCHOFRACTAL, 15 | ANOTHERFRACTAL, 16 | FLOWERFRACTAL, 17 | NEWFRACTAL, 18 | NEWNEWFRACTAL 19 | }; 20 | 21 | enum ColorType { 22 | FRACTAL, 23 | AMBIENCE 24 | }; 25 | 26 | class FractalData { 27 | public: 28 | static const QVector3D baseCamera; 29 | static constexpr const qreal defaultZoom = -3.0; 30 | static constexpr const qreal defaultSpeed = 0.25; 31 | 32 | qreal a{}, b{}, c{}; 33 | quint8 n = 2; 34 | FractalType type{}; 35 | QColor fractalColor = QColor(55, 255, 55); 36 | QColor ambienceColor = QColor(255, 55, 55); 37 | QVector3D camera = baseCamera; 38 | qreal zoomCoefficient = defaultZoom; 39 | qreal rotateSpeed = defaultSpeed; 40 | qreal absoluteSpeed = defaultSpeed; 41 | bool isRotating = false; 42 | 43 | 44 | FractalData(); 45 | 46 | [[maybe_unused]] FractalData(qreal a, qreal b, qreal c, quint8 n, FractalType type); 47 | 48 | FractalData(qreal a, qreal b, qreal c, quint8 n, FractalType type, const QColor &fractalColor, const QColor &ambienceColor, const QVector3D &camera, qreal zoomCoefficient, bool isRotating); 49 | 50 | void setZoomCoefficient(qreal zoomCoefficient = defaultZoom); 51 | 52 | void setAbsoluteSpeed(qreal absoluteSpeed); 53 | 54 | [[nodiscard]] QJsonObject serialize() const; 55 | 56 | void readFrom(QJsonDocument &in); 57 | 58 | void genRandom(); 59 | }; -------------------------------------------------------------------------------- /headers/FractalPoint.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class FractalPoint { 7 | private: 8 | qreal x, y; 9 | QColor color; 10 | 11 | public: 12 | FractalPoint(qreal newX, qreal newY, QColor newColor); 13 | 14 | [[nodiscard]] QColor getColor() const; 15 | 16 | void setColor(QColor newColor); 17 | 18 | [[nodiscard]] qreal getX() const; 19 | 20 | [[nodiscard]] qreal getY() const; 21 | 22 | void setX(qreal newX) &; 23 | 24 | void setY(qreal newY) &; 25 | }; 26 | -------------------------------------------------------------------------------- /headers/FractalWidget.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "FractalData.hpp" 4 | #include "GeometryEngine.hpp" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | class FractalWidget : public QOpenGLWidget, protected QOpenGLFunctions { 21 | Q_OBJECT 22 | 23 | public: 24 | using QOpenGLWidget::QOpenGLWidget; 25 | 26 | ~FractalWidget(); 27 | 28 | void setFractalData(FractalData *data); 29 | 30 | protected: 31 | void wheelEvent(QWheelEvent *e) override; 32 | 33 | void mousePressEvent(QMouseEvent *e) override; 34 | 35 | void mouseMoveEvent(QMouseEvent *e) override; 36 | 37 | void mouseReleaseEvent(QMouseEvent *) override; 38 | 39 | void initializeGL() override; 40 | 41 | void resizeGL(int w, int h) override; 42 | 43 | void paintGL() override; 44 | 45 | void initShaders(); 46 | 47 | void rotateFractal(QVector2D const &diff); 48 | 49 | void autoRotate(); 50 | 51 | private: 52 | bool mousePressed = false; 53 | QOpenGLShaderProgram program; 54 | FractalData *fractalData; 55 | GeometryEngine *geometries = nullptr; 56 | QElapsedTimer *elapsedTimer = nullptr; 57 | QTimer *timer = nullptr; 58 | 59 | QMatrix4x4 projection; 60 | QVector2D mousePressPosition; 61 | QVector3D pointAxisX = QVector3D(1.0, 0.0, 1.5); 62 | QVector3D pointAxisY = QVector3D(0.0, 1.0, 1.5); 63 | qreal autoRotationPos = 0.0; 64 | }; 65 | -------------------------------------------------------------------------------- /headers/GeometryEngine.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class GeometryEngine : protected QOpenGLFunctions { 8 | public: 9 | GeometryEngine(); 10 | 11 | virtual ~GeometryEngine(); 12 | 13 | void drawGeometry(QOpenGLShaderProgram *program); 14 | 15 | private: 16 | void initGeometry(); 17 | 18 | QOpenGLBuffer arrayBuf; 19 | QOpenGLBuffer indexBuf; 20 | }; 21 | -------------------------------------------------------------------------------- /headers/MainWindow.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "FractalData.hpp" 4 | #include "FractalWidget.hpp" 5 | #include "Recorder.hpp" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | QT_BEGIN_NAMESPACE 24 | namespace Ui { 25 | class MainWindow; 26 | } 27 | QT_END_NAMESPACE 28 | 29 | QT_FORWARD_DECLARE_CLASS(QOpenGLWidget) 30 | 31 | class MainWindow : public QMainWindow { 32 | Q_OBJECT 33 | static const qint64 LIMIT = 180000; 34 | 35 | public: 36 | explicit MainWindow(QWidget *parent = nullptr); 37 | 38 | ~MainWindow() override; 39 | 40 | private: 41 | Ui::MainWindow *ui; 42 | FractalData data{}; 43 | QElapsedTimer *elapsedTimer{}; 44 | QTimer *timer{}; 45 | qint64 time{}, frames{}; 46 | QTemporaryDir *temporaryDir{}; 47 | Recorder *recorder{}; 48 | QSize prevSize{}; 49 | bool isOnRecord = false; 50 | bool isFullScreen = false; 51 | bool isSetting = true; 52 | 53 | void connectBoxBar(); 54 | 55 | void makeMenu(); 56 | 57 | void chooseColor(QColor const &color, ColorType type); 58 | 59 | void askColor(ColorType type); 60 | 61 | void updateButtons(); 62 | 63 | void readAndDraw(); 64 | 65 | void saveToFile(); 66 | 67 | void saveToImage(); 68 | 69 | void loadFromFile(); 70 | 71 | void setValues(); 72 | 73 | void recordVideo(); 74 | 75 | void startRecord(); 76 | 77 | void shot(); 78 | 79 | void stopRecord(); 80 | 81 | void saveVideo(); 82 | 83 | void recordClickAction(); 84 | 85 | void generateRandom(); 86 | 87 | void hideAndShow(); 88 | 89 | void hideBorders(); 90 | 91 | protected: 92 | void keyPressEvent(QKeyEvent *event) override; 93 | }; 94 | -------------------------------------------------------------------------------- /headers/Recorder.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class Recorder { 12 | public: 13 | enum class Mode { 14 | kInstantStop, 15 | kWaitProcessing 16 | }; 17 | 18 | Recorder(Mode mode); 19 | 20 | virtual ~Recorder() noexcept; 21 | 22 | void start(); 23 | 24 | void stop(); 25 | 26 | void push_back(std::pair &&data); 27 | 28 | private: 29 | void run(); 30 | 31 | private: 32 | const bool instantStop; 33 | std::atomic_bool running = false; 34 | std::thread worker; 35 | 36 | std::queue> queue; 37 | std::mutex queueMutex; 38 | std::condition_variable queueCondition; 39 | }; 40 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "MainWindow.hpp" 2 | #include 3 | 4 | int main(int argc, char *argv[]) { 5 | QApplication fractals3DApp(argc, argv); 6 | 7 | QSurfaceFormat format; 8 | format.setDepthBufferSize(24); 9 | QSurfaceFormat::setDefaultFormat(format); 10 | 11 | fractals3DApp.setApplicationName("Fractals 3D"); 12 | fractals3DApp.setApplicationVersion("v1.5"); 13 | fractals3DApp.setOrganizationName("HSE University Saint Petersburg"); 14 | fractals3DApp.setOrganizationDomain("spb.hse.ru"); 15 | 16 | #ifndef QT_NO_OPENGL 17 | MainWindow mainWindow{}; 18 | mainWindow.show(); 19 | #else 20 | QLabel note("OpenGL Support required"); 21 | note.show(); 22 | #endif 23 | 24 | return fractals3DApp.exec(); 25 | } 26 | -------------------------------------------------------------------------------- /shaders/fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 140 2 | 3 | #ifdef GL_ES 4 | // Set default precision to medium 5 | precision highp int; 6 | precision highp float; 7 | #endif 8 | 9 | uniform mat4 mvp_matrix; 10 | uniform vec2 Resolution = vec2(600, 600); 11 | uniform float RADIUS = 2.5; 12 | uniform int POWER = 2; 13 | uniform int TYPE = 0; 14 | uniform float CriticalPointX; 15 | uniform float CriticalPointY; 16 | uniform float CriticalPointZ; 17 | uniform vec3 CameraPosition; 18 | uniform vec3 Ambience = vec3(0.6, 0.8, 0.8); 19 | uniform vec3 ColorFractal = vec3(0.6, 0.5, 0.8); 20 | uniform float ZoomCoefficient = 1.0; 21 | 22 | int MAX_STEPS = 355; 23 | float MAX_DIST = 20.0; 24 | float MIN_DIST = 0.0001; 25 | int OTHER_ITER = 300; 26 | int MANDEL_ITER = 50; 27 | 28 | float sphere(vec3 point, vec3 center, float radius) { 29 | return length(point - center) - radius; 30 | } 31 | 32 | float plane(vec3 point) { 33 | return point.y; 34 | } 35 | 36 | vec4 Add(vec4 z1, vec4 z2) { 37 | return z1 + z2; 38 | } 39 | 40 | vec4 Mul(vec4 z1, vec4 z2) { 41 | return vec4(z1.x * z2.x - dot(z1.yzw, z2.yzw), z2.x * z1.yzw + z1.x * z2.yzw + cross(z1.yzw, z2.yzw)); 42 | } 43 | 44 | vec4 Pow(vec4 z, int n) { 45 | vec4 z0 = vec4(1.0, vec3(0.0)); 46 | for(int i = 0; i < n; i++) 47 | z0 = Mul(z0, z); 48 | return z0; 49 | } 50 | 51 | struct QDual { 52 | vec4 q; 53 | vec4 d; 54 | }; 55 | 56 | QDual qdAdd(QDual qd1, QDual qd2) { 57 | return QDual(Add(qd1.q, qd2.q), Add(qd1.d, qd2.d)); 58 | } 59 | 60 | QDual qdMul(QDual qd1, QDual qd2) { 61 | return QDual(Mul(qd1.q, qd2.q), Add(Mul(qd1.d, qd2.q), Mul(qd1.q, qd2.d))); 62 | } 63 | 64 | QDual qdPow(QDual qd, int n) { 65 | QDual p = QDual(vec4(1.0, vec3(0.0)), vec4(0.0, vec3(0.0))); 66 | for(int i = 0; i < n; i++) 67 | p = qdMul(p, qd); 68 | return p; 69 | } 70 | 71 | float psychoFractal(vec4 point, vec4 CriticalPoint) { 72 | vec4 z = point; 73 | float dr = 1.0; 74 | float r = 0.0; 75 | for(int i = 0; i < OTHER_ITER; ++i) { 76 | r = length(z); 77 | if(r > RADIUS) break; 78 | 79 | dr = pow(r, POWER - 1.0) * POWER * dr + 1.0; 80 | 81 | float zr = pow(r, POWER); 82 | float theta = acos(z.z / r) * POWER; 83 | float phi = atan(z.y, z.x) * POWER; 84 | 85 | z = zr * vec4( 86 | sin(theta) * sin(phi), 87 | sin(phi) * sin(theta), 88 | sin(theta), 89 | 1.0); 90 | z += CriticalPoint; 91 | } 92 | return 0.5 * log(r) * r / dr; 93 | } 94 | 95 | float flowerFractal(vec4 point, vec4 CriticalPoint) { 96 | vec4 z = point; 97 | float dr = 1.0; 98 | float r = 0.0; 99 | for(int i = 0; i < OTHER_ITER; ++i) { 100 | r = length(z); 101 | if(r > RADIUS) break; 102 | 103 | dr = pow(r, POWER - 1.0) * POWER * dr + 1.0; 104 | 105 | float zr = pow(r, POWER); 106 | float theta = acos(z.z / r) * POWER; 107 | float phi = atan(z.y, z.x) * POWER; 108 | 109 | z = zr * vec4( 110 | sin(theta) * cos(phi), 111 | sin(phi) * sin(theta), 112 | cos(theta), 113 | 1.0); 114 | z += CriticalPoint; 115 | } 116 | return 0.5 * log(r) * r / dr; 117 | } 118 | 119 | float anotherFractal(vec4 point, vec4 CriticalPoint) { 120 | vec4 z = point; 121 | float dr = 1.0; 122 | float r = 0.0; 123 | for(int i = 0; i < OTHER_ITER; ++i) { 124 | r = length(z); 125 | if(r > RADIUS) break; 126 | 127 | dr = pow(r, POWER - 1.0) * POWER * dr + 1.0; 128 | 129 | float zr = pow(r, POWER); 130 | float theta = acos(z.z / r) * POWER; 131 | float phi = atan(z.y, z.x) * POWER; 132 | 133 | z = zr * vec4( 134 | cos(theta) * cos(phi), 135 | sin(phi) * sin(theta), 136 | cos(theta), 137 | 1.0); 138 | z += CriticalPoint; 139 | } 140 | return 0.5 * log(r) * r / dr; 141 | } 142 | 143 | 144 | float mandelbrot(vec4 c, vec4 z) { 145 | QDual zd = QDual(z, vec4(0.0, vec3(0.0))); 146 | QDual cd = QDual(c, vec4(1.0, vec3(0.0))); 147 | for(int i = 0; i < MANDEL_ITER; i++) { 148 | zd = qdAdd(qdPow(zd, POWER), cd); 149 | if(length(zd.q) > RADIUS) break; 150 | } 151 | 152 | return 0.5 * length(zd.q) * log(length(zd.q)) / length(zd.d); 153 | } 154 | 155 | float circleFractal(vec4 point, vec4 CriticalPoint) { 156 | vec4 z = point; 157 | float dr = 1.0; 158 | float r = 0.0; 159 | for(int i = 0; i < OTHER_ITER; i++) { 160 | r = length(z); 161 | if(RADIUS < r) 162 | break; 163 | 164 | dr = pow(r, POWER - 1.0) * POWER * dr + 1.0; 165 | 166 | float zr = pow(r, POWER); 167 | float theta; 168 | float phi = atan(z.x, z.y) * POWER; 169 | if((i & 1) == 0) 170 | theta = asin(-z.z / r) * POWER; 171 | else 172 | theta = asin(z.z / r) * POWER; 173 | z = zr * vec4( 174 | cos(theta) * cos(phi), 175 | sin(phi) * cos(theta), 176 | sin(theta), 177 | 0.0); 178 | z += CriticalPoint; 179 | } 180 | return 0.5 * log(r) * r / dr; 181 | } 182 | 183 | float spongeFractal(vec4 point, vec4 CriticalPoint) { 184 | vec4 z = point; 185 | float dr = 1.0; 186 | float r = 0.0; 187 | for(int i = 0; i < OTHER_ITER; ++i) { 188 | r = length(z); 189 | if(r > RADIUS) break; 190 | 191 | dr = pow(r, POWER - 1.0) * POWER * dr + 1.0; 192 | 193 | float zr = pow(r, POWER); 194 | float theta = atan(z.x, z.y) * POWER; 195 | float phi; 196 | if(i % 2 == 0) { 197 | phi = asin(-z.z / r) * POWER; 198 | } else { 199 | phi = asin(z.z / r) * POWER; 200 | } 201 | z = zr * vec4( 202 | cos(theta) * cos(phi), 203 | sin(phi) * cos(theta), 204 | sin(theta), 205 | 0.0); 206 | z += CriticalPoint; 207 | } 208 | return 0.5 * log(r) * r / dr; 209 | } 210 | 211 | float GetDist(vec3 point, vec3 CriticalPoint) { 212 | float fractalDist; 213 | switch(TYPE) { 214 | case 0: 215 | fractalDist = mandelbrot(vec4(point, 0.0), vec4(CriticalPoint, 0.0)); 216 | break; 217 | case 1: 218 | fractalDist = psychoFractal(vec4(point, 0.0), vec4(CriticalPoint, 0.0)); 219 | break; 220 | case 2: 221 | fractalDist = anotherFractal(vec4(point, 0.0), vec4(CriticalPoint, 0.0)); 222 | break; 223 | case 3: 224 | fractalDist = flowerFractal(vec4(point, 0.0), vec4(CriticalPoint, 0.0)); 225 | break; 226 | case 4: 227 | fractalDist = circleFractal(vec4(point, 0.0), vec4(CriticalPoint, 0.0)); 228 | break; 229 | case 5: 230 | fractalDist = spongeFractal(vec4(point, 0.0), vec4(CriticalPoint, 0.0)); 231 | break; 232 | } 233 | return fractalDist; 234 | } 235 | 236 | float RayMarch(vec3 CameraPosition, vec3 RayDirection, vec3 CriticalPoint) { 237 | float dist = 0.0; 238 | for(int i = 0; i < MAX_STEPS; i++) { 239 | vec3 RayPosition = CameraPosition + RayDirection * dist; 240 | float distNear = GetDist(RayPosition, CriticalPoint); 241 | dist += distNear; 242 | if(MAX_DIST < dist || distNear < MIN_DIST) 243 | break; 244 | } 245 | return dist; 246 | } 247 | 248 | vec2 linmap(vec2 point, vec2 leftCorner, vec2 rightCorner, vec2 newLeftCorner, vec2 newRightCorner) { 249 | return (point - leftCorner) / (rightCorner - leftCorner) * (newRightCorner - newLeftCorner) + newLeftCorner; 250 | } 251 | 252 | out vec4 FragColor; 253 | 254 | void main() { 255 | float resolutionMin = min(Resolution.x, Resolution.y); 256 | float resolutionMax = max(Resolution.x, Resolution.y); 257 | if(resolutionMin < 1) { 258 | FragColor = vec4(Ambience, 1.0); 259 | return; 260 | } 261 | 262 | vec2 bounds = vec2(Resolution.y / Resolution.x, 1); 263 | vec2 shift = vec2((resolutionMax - resolutionMin) * 0.5, 0); 264 | if(Resolution.x < Resolution.y) {// vertical 265 | bounds.y = 1 / bounds.x; 266 | bounds.x = 1; 267 | shift.y = shift.x; 268 | shift.x = 0; 269 | } 270 | vec2 FragCoord = linmap(gl_FragCoord.xy - shift, vec2(0), vec2(resolutionMin), -bounds, bounds); 271 | 272 | vec3 CriticalPoint = vec3(CriticalPointX, CriticalPointY, CriticalPointZ); 273 | vec3 RayDirection = normalize((inverse(mvp_matrix) * vec4(FragCoord, 1.0, 1.0)).xyz); 274 | float distance = RayMarch(CameraPosition, RayDirection, CriticalPoint); 275 | if(MAX_DIST * 0.75 < distance) { 276 | FragColor = vec4(Ambience, 1); 277 | return; 278 | } 279 | 280 | if(MAX_DIST * 0.75 < distance) 281 | FragColor = vec4(Ambience, 1.0); 282 | else 283 | FragColor = vec4(ColorFractal * distance * pow(1 + distance, 0.5) / pow(3, 0.5), 1.0); 284 | } -------------------------------------------------------------------------------- /shaders/shaders.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | vshader.glsl 4 | fshader.glsl 5 | 6 | 7 | -------------------------------------------------------------------------------- /shaders/vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 140 2 | 3 | #ifdef GL_ES 4 | // Set default precision to medium 5 | precision mediump int; 6 | precision mediump float; 7 | #endif 8 | 9 | uniform vec2 verts[9] = vec2[]( 10 | vec2(0.0, 0.0), 11 | vec2(0.0, -1.0), 12 | vec2(0.0, 1.0), 13 | vec2(-1.0, 0.0), 14 | vec2(-1.0, 1.0), 15 | vec2(-1.0, -1.0), 16 | vec2(1.0, 1.0), 17 | vec2(1.0, -1.0), 18 | vec2(0.0, 0.0) 19 | ); 20 | 21 | void main() { 22 | gl_Position = vec4(verts[gl_VertexID], 0.0, 1.0); 23 | } -------------------------------------------------------------------------------- /src/Complex3D.cpp: -------------------------------------------------------------------------------- 1 | #include "Complex3D.hpp" 2 | #include "cmath" 3 | 4 | Complex3D::Complex3D(qreal newx, qreal newy, qreal newz) { 5 | x = newx; 6 | y = newy; 7 | z = newz; 8 | } 9 | 10 | Complex3D operator+(Complex3D a, Complex3D b) { 11 | return Complex3D(a.x + b.x, a.y + b.y, a.z + b.z); 12 | } 13 | 14 | qreal Complex3D::abs() const { 15 | return sqrt(x * x + y * y + z * z); 16 | } 17 | 18 | qreal Complex3D::theta() const { 19 | return atan2(sqrt(x * x + y * y), z); 20 | } 21 | 22 | qreal Complex3D::phi() const { 23 | return atan2(y, x); 24 | } 25 | 26 | void operator^(Complex3D &z, int const &n) { 27 | int help = 1; 28 | const int m = n - n % 2; 29 | qreal r_n = z.abs(); 30 | 31 | while(help < m) { 32 | r_n = r_n * r_n; 33 | help *= 2; 34 | } 35 | 36 | if(n % 2 == 1) { 37 | r_n = z.abs() * r_n; 38 | } 39 | 40 | qreal theta_n = z.theta() * n; 41 | qreal phi_n = z.phi() * n; 42 | z.x = r_n * sin(theta_n) * cos(phi_n); 43 | z.y = r_n * sin(theta_n) * sin(phi_n); 44 | z.z = r_n * cos(theta_n); 45 | } 46 | -------------------------------------------------------------------------------- /src/FractalData.cpp: -------------------------------------------------------------------------------- 1 | #include "FractalData.hpp" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | const QVector3D FractalData::baseCamera = QVector3D(0, 0, 1.5);// is more centered, but worse in some way 10 | 11 | namespace { 12 | qreal randomReal() { 13 | std::uniform_real_distribution dist(-0.3, 0.3); 14 | return dist(*QRandomGenerator::global()); 15 | } 16 | 17 | QColor randomColor() { 18 | return QColor(QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255)); 19 | } 20 | 21 | static std::map const &, std::vector const &)>, const qreal>> metrics = { 22 | {"minkowski-normalized", 23 | { 24 | [](std::vector const &u, std::vector const &v) -> qreal { 25 | static const int p = 5; 26 | qreal out = 0; 27 | for(size_t i = 0; i < std::min(u.size(), v.size()); i++) 28 | out += std::pow(std::abs(u[i] - v[i]) / 255., p); 29 | return std::pow(out, 1. / p) / std::pow(3, 1. / p); 30 | }, 31 | 0.25// threshold 32 | }}}; 33 | 34 | bool isSimilar(QColor const &u, QColor const &v, std::pair, std::vector)>, qreal> const &metric) { 35 | static const auto toVector = [](QColor const &color) -> std::vector { 36 | return {color.red(), color.green(), color.blue()}; 37 | }; 38 | return metric.first(toVector(u), toVector(v)) < metric.second; 39 | }; 40 | 41 | bool isBlack(QColor const &color) { 42 | return color.value() < 150; 43 | } 44 | 45 | }// namespace 46 | 47 | [[maybe_unused]] FractalData::FractalData(qreal a, qreal b, qreal c, quint8 n, FractalType type) : a(a), b(b), c(c), n(n), type(type) {} 48 | 49 | QJsonObject FractalData::serialize() const { 50 | QJsonObject serialized; 51 | serialized.insert("a", a); 52 | serialized.insert("b", b); 53 | serialized.insert("c", c); 54 | serialized.insert("n", n); 55 | serialized.insert("type", type); 56 | serialized.insert("Fractal color", fractalColor.name()); 57 | serialized.insert("Ambience color", ambienceColor.name()); 58 | serialized.insert("zoomCoefficient", zoomCoefficient); 59 | QJsonArray cameraPosition; 60 | cameraPosition.insert(0, camera.x()); 61 | cameraPosition.insert(1, camera.y()); 62 | cameraPosition.insert(2, camera.z()); 63 | serialized.insert("camera", cameraPosition); 64 | return serialized; 65 | } 66 | 67 | void FractalData::readFrom(QJsonDocument &in) { 68 | genRandom(); 69 | QJsonObject fractalData; 70 | try { 71 | fractalData = in.object().value("Fractal").toObject(); 72 | } catch(...) { 73 | return; 74 | } 75 | if(fractalData.contains("camera")) { 76 | // QJsonArray cameraPosition = fractalData.value("camera").toArray(); 77 | // camera = QVector3D(cameraPosition[0].toDouble(), cameraPosition[1].toDouble(), cameraPosition[2].toDouble()); 78 | } else 79 | camera = baseCamera; 80 | for(auto &[name, reference] : QVector>{{"a", a}, {"b", b}, {"c", c}}) 81 | if(fractalData.contains(name)) 82 | reference = fractalData.value(name).toDouble(); 83 | if(fractalData.contains("n")) 84 | n = fractalData.value("n").toInt(); 85 | if(fractalData.contains("type")) 86 | type = static_cast(fractalData.value("type").toInt()); 87 | if(fractalData.contains("Fractal color")) 88 | fractalColor = QColor(fractalData.value("Fractal color").toString()); 89 | if(fractalData.contains("Ambience color")) 90 | ambienceColor = QColor(fractalData.value("Ambience color").toString()); 91 | if(fractalData.contains("zoomCoefficient")) 92 | zoomCoefficient = fractalData.value("zoomCoefficient").toDouble(); 93 | } 94 | 95 | void FractalData::genRandom() { 96 | a = randomReal(); 97 | b = randomReal(); 98 | c = randomReal(); 99 | n = 2 * (QRandomGenerator::global()->bounded(4) + 2); 100 | type = FractalType(QRandomGenerator::global()->bounded(5)); 101 | auto genColors = [this]() { 102 | fractalColor = randomColor(); 103 | ambienceColor = randomColor(); 104 | }; 105 | do { 106 | genColors(); 107 | ; 108 | } while(isSimilar(fractalColor, ambienceColor, metrics["minkowski-normalized"]) || isBlack(fractalColor)); 109 | zoomCoefficient = defaultZoom; 110 | } 111 | 112 | FractalData::FractalData() { 113 | genRandom(); 114 | } 115 | 116 | FractalData::FractalData(qreal a, qreal b, qreal c, quint8 n, FractalType type, const QColor &fractalColor, const QColor &ambienceColor, const QVector3D &camera, qreal zoomCoefficient, bool isRotating) : a(a), b(b), c(c), n(n), type(type), fractalColor(fractalColor), ambienceColor(ambienceColor), camera(camera), zoomCoefficient(zoomCoefficient), isRotating(isRotating) {} 117 | 118 | void FractalData::setZoomCoefficient(qreal zoomCoefficient) { 119 | FractalData::zoomCoefficient = zoomCoefficient; 120 | } 121 | 122 | void FractalData::setAbsoluteSpeed(qreal absoluteSpeed) { 123 | FractalData::absoluteSpeed = absoluteSpeed; 124 | } 125 | -------------------------------------------------------------------------------- /src/FractalPoint.cpp: -------------------------------------------------------------------------------- 1 | #include "FractalPoint.hpp" 2 | 3 | FractalPoint::FractalPoint(qreal newX, qreal newY, QColor newColor) { 4 | x = newX; 5 | y = newY; 6 | color = newColor; 7 | } 8 | 9 | QColor FractalPoint::getColor() const { 10 | return color; 11 | } 12 | 13 | void FractalPoint::setColor(QColor newColor) { 14 | color = newColor; 15 | } 16 | 17 | qreal FractalPoint::getX() const { 18 | return x; 19 | } 20 | 21 | qreal FractalPoint::getY() const { 22 | return y; 23 | } 24 | 25 | void FractalPoint::setX(qreal newX) & { 26 | x = newX; 27 | } 28 | 29 | void FractalPoint::setY(qreal newY) & { 30 | y = newY; 31 | } 32 | -------------------------------------------------------------------------------- /src/FractalWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "FractalWidget.hpp" 2 | 3 | 4 | namespace { 5 | QVector3D transformColor(const QColor &color) { 6 | return QVector3D(color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0); 7 | } 8 | }// namespace 9 | 10 | FractalWidget::~FractalWidget() { 11 | // Make sure the context is current when deleting the buffers. 12 | makeCurrent(); 13 | delete geometries; 14 | doneCurrent(); 15 | } 16 | 17 | void FractalWidget::wheelEvent(QWheelEvent *e) { 18 | static const qreal degreesCoefficient = 1.0 / 360; 19 | static const qreal EPS = 0.001; 20 | QPoint numDegrees = e->angleDelta(); 21 | 22 | static const qreal minZoom = -5.0; 23 | static const qreal maxZoom = 9.0; 24 | qreal delta = numDegrees.y() * degreesCoefficient; 25 | qreal newValue = fractalData->zoomCoefficient + delta; 26 | qreal newSpeed = fractalData->rotateSpeed; 27 | 28 | if(newValue > fractalData->defaultZoom) { 29 | newSpeed /= (1 + (newValue - fractalData->defaultZoom) * 0.1); 30 | } 31 | 32 | if(EPS < abs(delta) && minZoom <= newValue && newValue <= maxZoom) { 33 | fractalData->zoomCoefficient = newValue; 34 | fractalData->rotateSpeed = newSpeed; 35 | update(); 36 | } 37 | } 38 | 39 | void FractalWidget::mousePressEvent(QMouseEvent *e) { 40 | // Save mouse press position 41 | mousePressPosition = QVector2D(e->position()); 42 | mousePressed = true; 43 | } 44 | 45 | void FractalWidget::mouseReleaseEvent(QMouseEvent *) { 46 | mousePressed = false; 47 | } 48 | 49 | namespace { 50 | QVector3D rotate(QVector3D point, qreal alpha, QVector3D axis) { 51 | qreal t11 = cos(alpha) + (1 - cos(alpha)) * axis.x() * axis.x(); 52 | qreal t12 = (1 - cos(alpha)) * axis.x() * axis.y() - sin(alpha) * axis.z(); 53 | qreal t13 = (1 - cos(alpha)) * axis.x() * axis.z() + sin(alpha) * axis.y(); 54 | qreal t21 = (1 - cos(alpha)) * axis.x() * axis.y() + sin(alpha) * axis.z(); 55 | qreal t22 = cos(alpha) + (1 - cos(alpha)) * axis.y() * axis.y(); 56 | qreal t23 = (1 - cos(alpha)) * axis.y() * axis.z() - sin(alpha) * axis.x(); 57 | qreal t31 = (1 - cos(alpha)) * axis.x() * axis.z() - sin(alpha) * axis.y(); 58 | qreal t32 = (1 - cos(alpha)) * axis.y() * axis.z() + sin(alpha) * axis.x(); 59 | qreal t33 = cos(alpha) + (1 - cos(alpha)) * axis.z() * axis.z(); 60 | return QVector3D(point.x() * t11 + point.y() * t21 + point.z() * t31, 61 | point.x() * t12 + point.y() * t22 + point.z() * t32, 62 | point.x() * t13 + point.y() * t23 + point.z() * t33); 63 | } 64 | };// namespace 65 | 66 | void FractalWidget::rotateFractal(QVector2D const &diff) { 67 | if(diff.x() == 0 && diff.y() == 0) 68 | return; 69 | QVector2D alpha = diff * (M_PI / 720.); 70 | 71 | QVector3D vecAxisY = (pointAxisY - fractalData->camera).normalized(); 72 | 73 | pointAxisX = rotate(pointAxisX, alpha.x(), vecAxisY); 74 | pointAxisY = rotate(pointAxisY, alpha.x(), vecAxisY); 75 | fractalData->camera = rotate(fractalData->camera, alpha.x(), vecAxisY); 76 | 77 | QVector3D vecAxisX = (pointAxisX - fractalData->camera).normalized(); 78 | 79 | fractalData->camera = rotate(fractalData->camera, alpha.y(), vecAxisX); 80 | pointAxisX = rotate(pointAxisX, alpha.y(), vecAxisX); 81 | pointAxisY = rotate(pointAxisY, alpha.y(), vecAxisX); 82 | 83 | update(); 84 | } 85 | 86 | void FractalWidget::mouseMoveEvent(QMouseEvent *e) { 87 | if(!mousePressed) 88 | return; 89 | rotateFractal(QVector2D(e->position()) - mousePressPosition); 90 | mousePressPosition = QVector2D(e->position()); 91 | } 92 | 93 | void FractalWidget::initializeGL() { 94 | this->setMouseTracking(true); 95 | 96 | initializeOpenGLFunctions(); 97 | 98 | glClearColor(0, 0, 0, 1); 99 | 100 | initShaders(); 101 | 102 | // Enable depth buffer 103 | glEnable(GL_DEPTH_TEST); 104 | 105 | // Enable back face culling 106 | glEnable(GL_CULL_FACE); 107 | 108 | geometries = new GeometryEngine; 109 | 110 | // Prepare for auto-rotation 111 | timer = new QTimer; 112 | elapsedTimer = new QElapsedTimer(); 113 | connect(timer, &QTimer::timeout, [&]() { autoRotate(); }); 114 | elapsedTimer->start(); 115 | timer->start(); 116 | } 117 | 118 | void FractalWidget::initShaders() { 119 | // Compile vertex shader 120 | if(!program.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vshader.glsl")) 121 | close(); 122 | 123 | // Compile fragment shader 124 | if(!program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/fshader.glsl")) 125 | close(); 126 | 127 | // Link shader pipeline 128 | if(!program.link()) 129 | close(); 130 | 131 | // Bind shader pipeline for use 132 | if(!program.bind()) 133 | close(); 134 | } 135 | 136 | void FractalWidget::resizeGL(int w, int h) { 137 | // Calculate aspect ratio 138 | qreal aspect = qreal(w) / qreal(h ? h : 1); 139 | 140 | const qreal zNear = 3.0, zFar = 7.0, fov = 45.0; 141 | 142 | projection.setToIdentity(); 143 | 144 | // Set perspective projection 145 | projection.perspective(fov, aspect, zNear, zFar); 146 | } 147 | 148 | void FractalWidget::paintGL() { 149 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 150 | 151 | QMatrix4x4 matrix; 152 | matrix.translate(0.0, 0.0, fractalData->zoomCoefficient); 153 | matrix.lookAt(fractalData->camera, -fractalData->camera, pointAxisY - fractalData->camera); 154 | 155 | program.setUniformValue("mvp_matrix", projection * matrix); 156 | 157 | program.setUniformValue("POWER", (GLint) fractalData->n); 158 | program.setUniformValue("Resolution", dynamic_cast(QCoreApplication::instance())->devicePixelRatio() * QVector2D(this->width(), this->height())); 159 | program.setUniformValue("CriticalPointX", (GLfloat) fractalData->a); 160 | program.setUniformValue("CriticalPointY", (GLfloat) fractalData->b); 161 | program.setUniformValue("CriticalPointZ", (GLfloat) fractalData->c); 162 | program.setUniformValue("TYPE", (GLint) fractalData->type); 163 | program.setUniformValue("Ambience", transformColor(fractalData->ambienceColor)); 164 | program.setUniformValue("ColorFractal", transformColor(fractalData->fractalColor)); 165 | program.setUniformValue("CameraPosition", fractalData->camera); 166 | program.setUniformValue("ZoomCoefficient", (GLfloat) fractalData->zoomCoefficient); 167 | 168 | // Draw geometry 169 | geometries->drawGeometry(&program); 170 | } 171 | 172 | void FractalWidget::setFractalData(FractalData *data) { 173 | fractalData = data; 174 | } 175 | 176 | void FractalWidget::autoRotate() { 177 | if(fractalData->isRotating) { 178 | auto nextPos = static_cast(elapsedTimer->elapsed()); 179 | qreal dx = (nextPos - autoRotationPos) * fractalData->absoluteSpeed; 180 | autoRotationPos = nextPos; 181 | rotateFractal({static_cast(dx), 0.0}); 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/GeometryEngine.cpp: -------------------------------------------------------------------------------- 1 | #include "GeometryEngine.hpp" 2 | 3 | struct VertexData { 4 | QVector3D position; 5 | QVector2D texCoord; 6 | }; 7 | 8 | GeometryEngine::GeometryEngine() : indexBuf(QOpenGLBuffer::IndexBuffer) { 9 | initializeOpenGLFunctions(); 10 | 11 | // Generate 2 VBOs 12 | arrayBuf.create(); 13 | indexBuf.create(); 14 | 15 | // Initializes geometry and transfers it to VBOs 16 | initGeometry(); 17 | } 18 | 19 | GeometryEngine::~GeometryEngine() { 20 | arrayBuf.destroy(); 21 | indexBuf.destroy(); 22 | } 23 | 24 | void GeometryEngine::initGeometry() { 25 | // We would need only 8 vertices but we have to 26 | // duplicate vertex for each face because texture coordinate 27 | // is different. 28 | VertexData vertices[] = { 29 | // Vertex data for face 0 30 | {QVector3D(-1.0f, -1.0f, 1.0f), QVector2D(0.0f, 0.0f)}, // v0 31 | {QVector3D(1.0f, -1.0f, 1.0f), QVector2D(0.33f, 0.0f)}, // v1 32 | {QVector3D(-1.0f, 1.0f, 1.0f), QVector2D(0.0f, 0.5f)}, // v2 33 | {QVector3D(1.0f, 1.0f, 1.0f), QVector2D(0.33f, 0.5f)}, // v3 34 | 35 | // Vertex data for face 1 36 | {QVector3D(1.0f, -1.0f, 1.0f), QVector2D(0.0f, 0.5f)}, // v4 37 | {QVector3D(1.0f, -1.0f, -1.0f), QVector2D(0.33f, 0.5f)}, // v5 38 | {QVector3D(1.0f, 1.0f, 1.0f), QVector2D(0.0f, 1.0f)}, // v6 39 | {QVector3D(1.0f, 1.0f, -1.0f), QVector2D(0.33f, 1.0f)}, // v7 40 | 41 | // Vertex data for face 2 42 | {QVector3D(1.0f, -1.0f, -1.0f), QVector2D(0.66f, 0.5f)}, // v8 43 | {QVector3D(-1.0f, -1.0f, -1.0f), QVector2D(1.0f, 0.5f)}, // v9 44 | {QVector3D(1.0f, 1.0f, -1.0f), QVector2D(0.66f, 1.0f)}, // v10 45 | {QVector3D(-1.0f, 1.0f, -1.0f), QVector2D(1.0f, 1.0f)}, // v11 46 | 47 | // Vertex data for face 3 48 | {QVector3D(-1.0f, -1.0f, -1.0f), QVector2D(0.66f, 0.0f)}, // v12 49 | {QVector3D(-1.0f, -1.0f, 1.0f), QVector2D(1.0f, 0.0f)}, // v13 50 | {QVector3D(-1.0f, 1.0f, -1.0f), QVector2D(0.66f, 0.5f)}, // v14 51 | {QVector3D(-1.0f, 1.0f, 1.0f), QVector2D(1.0f, 0.5f)}, // v15 52 | 53 | // Vertex data for face 4 54 | {QVector3D(-1.0f, -1.0f, -1.0f), QVector2D(0.33f, 0.0f)}, // v16 55 | {QVector3D(1.0f, -1.0f, -1.0f), QVector2D(0.66f, 0.0f)}, // v17 56 | {QVector3D(-1.0f, -1.0f, 1.0f), QVector2D(0.33f, 0.5f)}, // v18 57 | {QVector3D(1.0f, -1.0f, 1.0f), QVector2D(0.66f, 0.5f)}, // v19 58 | 59 | // Vertex data for face 5 60 | {QVector3D(-1.0f, 1.0f, 1.0f), QVector2D(0.33f, 0.5f)}, // v20 61 | {QVector3D(1.0f, 1.0f, 1.0f), QVector2D(0.66f, 0.5f)}, // v21 62 | {QVector3D(-1.0f, 1.0f, -1.0f), QVector2D(0.33f, 1.0f)}, // v22 63 | {QVector3D(1.0f, 1.0f, -1.0f), QVector2D(0.66f, 1.0f)} // v23 64 | }; 65 | 66 | GLushort indices[] = { 67 | 0, 1, 2, 3, 3, // Face 0 - triangle strip ( v0, v1, v2, v3) 68 | 4, 4, 5, 6, 7, 7, // Face 1 - triangle strip ( v4, v5, v6, v7) 69 | 8, 8, 9, 10, 11, 11, // Face 2 - triangle strip ( v8, v9, v10, v11) 70 | 12, 12, 13, 14, 15, 15, // Face 3 - triangle strip (v12, v13, v14, v15) 71 | 16, 16, 17, 18, 19, 19, // Face 4 - triangle strip (v16, v17, v18, v19) 72 | 20, 20, 21, 22, 23 // Face 5 - triangle strip (v20, v21, v22, v23) 73 | }; 74 | 75 | // Transfer vertex data to VBO 0 76 | arrayBuf.bind(); 77 | arrayBuf.allocate(vertices, 24 * sizeof(VertexData)); 78 | 79 | // Transfer index data to VBO 1 80 | indexBuf.bind(); 81 | indexBuf.allocate(indices, 34 * sizeof(GLushort)); 82 | } 83 | 84 | void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program) { 85 | // Tell OpenGL which VBOs to use 86 | arrayBuf.bind(); 87 | indexBuf.bind(); 88 | 89 | // Draw geometry using indices from VBO 1 90 | glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, nullptr); 91 | } 92 | -------------------------------------------------------------------------------- /src/MainWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "MainWindow.hpp" 2 | #include 3 | 4 | typedef QString string; 5 | namespace { 6 | int getValFromBox(QDoubleSpinBox *box, QSlider *bar) { 7 | return (bar->maximum() - bar->minimum()) * (box->value() - box->minimum()) / (box->maximum() - box->minimum()); 8 | } 9 | 10 | double getValFromBar(QDoubleSpinBox *box, QSlider *bar) { 11 | return box->minimum() + (box->maximum() - box->minimum()) * (bar->value() - bar->minimum()) / (bar->maximum() - bar->minimum()); 12 | } 13 | 14 | QString timeFormat(qint64 time) { 15 | return QString::number(time / 1000) + " s " + QString::number(time % 1000) + " ms"; 16 | } 17 | 18 | void saveImageToFile(const QImage &image, const QString &fileName) { 19 | image.save(fileName); 20 | } 21 | }// namespace 22 | 23 | MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { 24 | ui->setupUi(this); 25 | ui->recordWidget->close(); 26 | prevSize = this->size(); 27 | ui->rotationSlider->setValue(100 * FractalData::defaultSpeed); 28 | connectBoxBar(); 29 | connect(ui->recordButton, &QPushButton::clicked, [&]() { recordClickAction(); }); 30 | setValues(); 31 | updateButtons(); 32 | ui->fractalWidget->setFractalData(&data); 33 | readAndDraw(); 34 | makeMenu(); 35 | hideBorders(); 36 | } 37 | 38 | MainWindow::~MainWindow() { 39 | delete ui; 40 | delete timer; 41 | delete elapsedTimer; 42 | delete temporaryDir; 43 | } 44 | 45 | void MainWindow::makeMenu() { 46 | auto fileMenu = menuBar()->addMenu("File"); 47 | fileMenu->addAction("Load fractal", [&]() { loadFromFile(); }); 48 | fileMenu->addAction("Save fractal", [&]() { saveToFile(); }); 49 | fileMenu->addAction("Save as image", [&]() { saveToImage(); }); 50 | fileMenu->addAction("Save as video", [&]() { recordVideo(); }); 51 | fileMenu->addAction("Exit", [&]() { QApplication::quit(); }); 52 | 53 | auto settingsMenu = menuBar()->addMenu("Settings"); 54 | settingsMenu->addAction( 55 | "Fullscreen view", [&]() { hideAndShow(); }, QKeySequence(tr("F11"))); 56 | auto aboutMenu = menuBar()->addMenu("Help"); 57 | aboutMenu->addAction("About", [&]() { 58 | QMessageBox aboutBox; 59 | aboutBox.setIcon(QMessageBox::Information); 60 | aboutBox.setWindowTitle("About Fractals 3D"); 61 | aboutBox.setTextFormat(Qt::RichText); 62 | aboutBox.setText("Fractals 3D is a program designed for exploring three-dimensional fractals. Made by the three students of the HSE University Saint Petersburg campus.

Authors: Sergey Zhuravlev, Stepan Konstantinov, Daria Ledneva
Mentor: Anton Sosnin

Version: " + dynamic_cast(QCoreApplication::instance())->applicationVersion() + "
Source: github.com/Constantor/fractals3d
License: GNU GPL v3.0"); 63 | aboutBox.exec(); 64 | }); 65 | } 66 | 67 | void MainWindow::updateButtons() { 68 | ui->fractalColorButton->setPalette(QPalette(data.fractalColor)); 69 | ui->fractalColorButton->setText(data.fractalColor.name()); 70 | ui->ambienceColorButton->setPalette(QPalette(data.ambienceColor)); 71 | ui->ambienceColorButton->setText(data.ambienceColor.name()); 72 | } 73 | 74 | void MainWindow::chooseColor(QColor const &color, ColorType type = FRACTAL) { 75 | QColor *colorMemory; 76 | if(type == AMBIENCE) 77 | colorMemory = &data.ambienceColor; 78 | else 79 | colorMemory = &data.fractalColor; 80 | if(color.isValid()) { 81 | *colorMemory = color; 82 | updateButtons(); 83 | readAndDraw(); 84 | } 85 | } 86 | 87 | void MainWindow::askColor(ColorType type) { 88 | QString title; 89 | if(type == AMBIENCE) 90 | title = "Select ambience color"; 91 | else 92 | title = "Select fractal color"; 93 | chooseColor(QColorDialog::getColor(Qt::green, this, title), type); 94 | } 95 | 96 | void MainWindow::connectBoxBar() { 97 | connect(ui->firstCoordBox, &QDoubleSpinBox::valueChanged, ui->firstCoordBar, [&]() { ui->firstCoordBar->setValue(getValFromBox(ui->firstCoordBox, ui->firstCoordBar)); }); 98 | connect(ui->firstCoordBar, &QSlider::valueChanged, ui->firstCoordBox, [&]() { ui->firstCoordBox->setValue(getValFromBar(ui->firstCoordBox, ui->firstCoordBar)); }); 99 | connect(ui->secondCoordBox, &QDoubleSpinBox::valueChanged, ui->secondCoordBar, [&]() { ui->secondCoordBar->setValue(getValFromBox(ui->secondCoordBox, ui->secondCoordBar)); }); 100 | connect(ui->secondCoordBar, &QSlider::valueChanged, ui->secondCoordBox, [&]() { ui->secondCoordBox->setValue(getValFromBar(ui->secondCoordBox, ui->secondCoordBar)); }); 101 | connect(ui->thirdCoordBox, &QDoubleSpinBox::valueChanged, ui->thirdCoordBar, [&]() { ui->thirdCoordBar->setValue(getValFromBox(ui->thirdCoordBox, ui->thirdCoordBar)); }); 102 | connect(ui->thirdCoordBar, &QSlider::valueChanged, ui->thirdCoordBox, [&]() { ui->thirdCoordBox->setValue(getValFromBar(ui->thirdCoordBox, ui->thirdCoordBar)); }); 103 | connect(ui->powerSpinBox, &QSpinBox::valueChanged, ui->powerBarSlider, [&]() { ui->powerBarSlider->setValue(ui->powerSpinBox->value() / 2); }); 104 | connect(ui->powerBarSlider, &QSlider::valueChanged, ui->powerSpinBox, [&]() { ui->powerSpinBox->setValue(2 * ui->powerBarSlider->value()); }); 105 | connect(ui->firstCoordBox, &QDoubleSpinBox::valueChanged, [&]() { readAndDraw(); }); 106 | connect(ui->firstCoordBar, &QSlider::valueChanged, [&]() { readAndDraw(); }); 107 | connect(ui->secondCoordBox, &QDoubleSpinBox::valueChanged, [&]() { readAndDraw(); }); 108 | connect(ui->secondCoordBar, &QSlider::valueChanged, [&]() { readAndDraw(); }); 109 | connect(ui->thirdCoordBox, &QDoubleSpinBox::valueChanged, [&]() { readAndDraw(); }); 110 | connect(ui->thirdCoordBar, &QSlider::valueChanged, [&]() { readAndDraw(); }); 111 | connect(ui->powerSpinBox, &QSpinBox::valueChanged, [&]() { readAndDraw(); }); 112 | connect(ui->powerBarSlider, &QSlider::valueChanged, [&]() { readAndDraw(); }); 113 | connect(ui->typeBox, &QComboBox::currentIndexChanged, [&]() { readAndDraw(); }); 114 | connect(ui->fractalColorButton, &QPushButton::clicked, [&]() { askColor(FRACTAL); }); 115 | connect(ui->ambienceColorButton, &QPushButton::clicked, [&]() { askColor(AMBIENCE); }); 116 | connect(ui->randomizeButton, &QPushButton::clicked, [&]() { generateRandom(); }); 117 | connect(ui->rotationBox, &QCheckBox::stateChanged, [&]() { readAndDraw(); }); 118 | connect(ui->zoomButton, &QPushButton::clicked, [&]() { 119 | data.setZoomCoefficient(); 120 | ui->fractalWidget->repaint(); 121 | }); 122 | connect(ui->rotationSlider, &QSlider::valueChanged, [&]() { 123 | ui->rotationBox->setCheckState(Qt::Checked); 124 | data.setAbsoluteSpeed(ui->rotationSlider->value() / 100.0); 125 | }); 126 | } 127 | 128 | void MainWindow::readAndDraw() { 129 | if(!isSetting) { 130 | data = FractalData(ui->firstCoordBox->value(), ui->secondCoordBox->value(), ui->thirdCoordBox->value(), ui->powerSpinBox->value(), 131 | static_cast(ui->typeBox->currentIndex()), data.fractalColor, data.ambienceColor, data.camera, data.zoomCoefficient, ui->rotationBox->isChecked()); 132 | ui->fractalWidget->repaint(); 133 | } 134 | } 135 | 136 | void MainWindow::loadFromFile() { 137 | QString fileName = QFileDialog::getOpenFileName(this, tr("Open Fractal"), "", tr("3D Fractal Data (*.f3d);;All Files (*)")); 138 | if(fileName.isEmpty()) 139 | return; 140 | else { 141 | QFile file(fileName); 142 | 143 | if(!file.open(QIODevice::ReadOnly)) { 144 | QMessageBox::information(this, tr("Unable to open file"), 145 | file.errorString()); 146 | return; 147 | } 148 | 149 | QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); 150 | data.readFrom(doc); 151 | file.close(); 152 | 153 | setValues(); 154 | readAndDraw(); 155 | } 156 | } 157 | 158 | void MainWindow::saveToFile() { 159 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save fractal configuration"), "", tr("3D Fractal Data (*.f3d);;All files (*.*)")); 160 | if(!fileName.isEmpty()) { 161 | QFile file(fileName); 162 | 163 | if(!file.open(QIODevice::WriteOnly)) { 164 | QMessageBox::information(this, tr("Unable to save the file"), file.errorString()); 165 | return; 166 | } 167 | 168 | QJsonObject output; 169 | output.insert("Fractal", data.serialize()); 170 | 171 | QJsonDocument doc(output); 172 | file.write(doc.toJson()); 173 | file.close(); 174 | } 175 | } 176 | 177 | void MainWindow::saveToImage() { 178 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save fractal image"), "", tr("Image files (*.png *.jpg *.jpeg *.bmp)")); 179 | if(!fileName.isEmpty()) { 180 | QFileInfo fileInfo(fileName); 181 | if(fileInfo.exists() && !fileInfo.isWritable()) { 182 | QMessageBox::information(this, tr("Unable to write to the file"), 183 | "Failed to save fractal data to " + fileInfo.fileName()); 184 | return; 185 | } 186 | saveImageToFile(ui->fractalWidget->grabFramebuffer(), fileName); 187 | } 188 | } 189 | 190 | void MainWindow::setValues() { 191 | isSetting = true; 192 | ui->firstCoordBox->setValue(data.a); 193 | ui->secondCoordBox->setValue(data.b); 194 | ui->thirdCoordBox->setValue(data.c); 195 | ui->powerSpinBox->setValue(data.n); 196 | ui->typeBox->setCurrentIndex(data.type); 197 | updateButtons(); 198 | isSetting = false; 199 | } 200 | 201 | void MainWindow::recordVideo() { 202 | ui->recordLabel->setText("Recording is not started."); 203 | ui->recordProgressBar->setValue(0); 204 | ui->recordWidget->show(); 205 | } 206 | 207 | void MainWindow::startRecord() { 208 | isOnRecord = true; 209 | ui->recordButton->setText("Stop"); 210 | time = 0, frames = 0; 211 | temporaryDir = new QTemporaryDir; 212 | recorder = new Recorder(Recorder::Mode::kWaitProcessing); 213 | recorder->start(); 214 | timer = new QTimer(this); 215 | elapsedTimer = new QElapsedTimer; 216 | connect(timer, &QTimer::timeout, [&]() { shot(); }); 217 | elapsedTimer->start(); 218 | timer->start(); 219 | } 220 | 221 | void MainWindow::shot() { 222 | time = elapsedTimer->elapsed(); 223 | string fileName = QStringLiteral("%1.png").arg(time, 10, 10, QLatin1Char('0')); 224 | recorder->push_back({ui->fractalWidget->grabFramebuffer(), temporaryDir->filePath(fileName)}); 225 | frames++; 226 | ui->recordLabel->setText("Recording: " + timeFormat(time)); 227 | ui->recordProgressBar->setValue(100 * time / LIMIT); 228 | if(LIMIT <= time) 229 | stopRecord(); 230 | } 231 | 232 | void MainWindow::stopRecord() { 233 | timer->stop(); 234 | isOnRecord = false; 235 | saveVideo(); 236 | ui->recordButton->setText("Start"); 237 | ui->recordWidget->close(); 238 | } 239 | 240 | void MainWindow::saveVideo() { 241 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save Fractal Video"), "", tr("Video Files(*.mp4 *.avi);;All Files (*)")); 242 | if(!fileName.isEmpty()) { 243 | QFileInfo fileInfo(fileName); 244 | if(fileInfo.exists() && !fileInfo.isWritable()) { 245 | QMessageBox::information(this, tr("Unable to write to the file"), 246 | "Can't save to " + fileInfo.fileName()); 247 | return; 248 | } 249 | //int framerate = frames * 1000 / time; 250 | QString command = QString("ffmpeg -y -pattern_type glob -i '%1/*.png' -c:v libx264 -pix_fmt yuv420p -vf \"crop=trunc(iw/2)*2:trunc(ih/2)*2,fps=60\" %2 > /dev/null 2> /dev/null").arg(temporaryDir->path(), fileName); 251 | std::system(command.toStdString().data()); 252 | } 253 | } 254 | 255 | void MainWindow::recordClickAction() { 256 | if(isOnRecord) 257 | stopRecord(); 258 | else 259 | startRecord(); 260 | } 261 | 262 | void MainWindow::generateRandom() { 263 | data.genRandom(); 264 | setValues(); 265 | ui->fractalWidget->repaint(); 266 | } 267 | 268 | 269 | void MainWindow::keyPressEvent(QKeyEvent *event) { 270 | if(event->key() == Qt::Key_F11) { 271 | hideAndShow(); 272 | } 273 | if(event->key() == Qt::Key_Escape && isFullScreen) { 274 | hideAndShow(); 275 | } 276 | QWidget::keyPressEvent(event); 277 | } 278 | 279 | void MainWindow::hideAndShow() { 280 | if(isFullScreen) { 281 | ui->menubar->show(); 282 | ui->inputWidget->show(); 283 | ui->statusbar->show(); 284 | this->resize(prevSize); 285 | isFullScreen = false; 286 | } else { 287 | prevSize = this->size(); 288 | ui->menubar->hide(); 289 | ui->inputWidget->hide(); 290 | ui->statusbar->hide(); 291 | this->showMaximized(); 292 | isFullScreen = true; 293 | } 294 | } 295 | 296 | void MainWindow::hideBorders() { 297 | ui->statusbar->hide(); 298 | ui->centralwidget->setContentsMargins(0, 0, 0, 0); 299 | } 300 | -------------------------------------------------------------------------------- /src/Recorder.cpp: -------------------------------------------------------------------------------- 1 | #include "Recorder.hpp" 2 | 3 | Recorder::Recorder(Mode mode) : instantStop(mode == Mode::kInstantStop) {} 4 | 5 | Recorder::~Recorder() noexcept { 6 | stop(); 7 | } 8 | 9 | void Recorder::start() { 10 | if(!running) { 11 | running = true; 12 | worker = std::thread(&Recorder::run, this); 13 | } 14 | } 15 | 16 | void Recorder::stop() { 17 | if(!running) 18 | return; 19 | { 20 | std::unique_lock lock(queueMutex); 21 | running = false; 22 | queueCondition.notify_all(); 23 | } 24 | worker.join(); 25 | } 26 | 27 | void Recorder::push_back(std::pair &&data) { 28 | std::unique_lock lock(queueMutex); 29 | queue.emplace(std::move(data)); 30 | queueCondition.notify_all(); 31 | } 32 | 33 | void Recorder::run() { 34 | while(running || !queue.empty()) { 35 | std::unique_lock lock(queueMutex); 36 | queueCondition.wait(lock, [this] { return !queue.empty() || !running; }); 37 | if(!running && instantStop) 38 | break; 39 | if(queue.empty()) 40 | continue; 41 | 42 | auto data = std::move(queue.front()); 43 | queue.pop(); 44 | lock.unlock(); 45 | 46 | data.first.save(data.second); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ui/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1000 10 | 871 11 | 12 | 13 | 14 | Fractals 3D 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 0 23 | 0 24 | 25 | 26 | 27 | 28 | 200 29 | 16777215 30 | 31 | 32 | 33 | 34 | 35 | 36 | Fractal type 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Mandelbrot 45 | 46 | 47 | 48 | 49 | Round fractal 50 | 51 | 52 | 53 | 54 | Flower 2.0 fractal 55 | 56 | 57 | 58 | 59 | Flower fractal 60 | 61 | 62 | 63 | 64 | Circle fractal 65 | 66 | 67 | 68 | 69 | Sponge fractal 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | QFrame::HLine 78 | 79 | 80 | QFrame::Sunken 81 | 82 | 83 | 84 | 85 | 86 | 87 | First add coordinate 88 | 89 | 90 | 91 | 92 | 93 | 94 | 3 95 | 96 | 97 | -2.000000000000000 98 | 99 | 100 | 2.000000000000000 101 | 102 | 103 | 0.001000000000000 104 | 105 | 106 | QAbstractSpinBox::DefaultStepType 107 | 108 | 109 | 110 | 111 | 112 | 113 | 4000 114 | 115 | 116 | 2000 117 | 118 | 119 | Qt::Horizontal 120 | 121 | 122 | 123 | 124 | 125 | 126 | QFrame::HLine 127 | 128 | 129 | QFrame::Sunken 130 | 131 | 132 | 133 | 134 | 135 | 136 | Second add coordinate 137 | 138 | 139 | 140 | 141 | 142 | 143 | 3 144 | 145 | 146 | -2.000000000000000 147 | 148 | 149 | 2.000000000000000 150 | 151 | 152 | 0.001000000000000 153 | 154 | 155 | QAbstractSpinBox::DefaultStepType 156 | 157 | 158 | 159 | 160 | 161 | 162 | 4000 163 | 164 | 165 | 2000 166 | 167 | 168 | Qt::Horizontal 169 | 170 | 171 | 172 | 173 | 174 | 175 | QFrame::HLine 176 | 177 | 178 | QFrame::Sunken 179 | 180 | 181 | 182 | 183 | 184 | 185 | Third add coordinate 186 | 187 | 188 | 189 | 190 | 191 | 192 | 3 193 | 194 | 195 | -2.000000000000000 196 | 197 | 198 | 2.000000000000000 199 | 200 | 201 | 0.001000000000000 202 | 203 | 204 | 205 | 206 | 207 | 208 | 4000 209 | 210 | 211 | 2000 212 | 213 | 214 | Qt::Horizontal 215 | 216 | 217 | 218 | 219 | 220 | 221 | QFrame::HLine 222 | 223 | 224 | QFrame::Sunken 225 | 226 | 227 | 228 | 229 | 230 | 231 | Power 232 | 233 | 234 | 235 | 236 | 237 | 238 | 2 239 | 240 | 241 | 36 242 | 243 | 244 | 1 245 | 246 | 247 | 248 | 249 | 250 | 251 | 2 252 | 253 | 254 | 36 255 | 256 | 257 | Qt::Horizontal 258 | 259 | 260 | 261 | 262 | 263 | 264 | QFrame::HLine 265 | 266 | 267 | QFrame::Sunken 268 | 269 | 270 | 271 | 272 | 273 | 274 | Auto rotation 275 | 276 | 277 | 278 | 279 | 280 | 281 | Rotation speed 282 | 283 | 284 | 285 | 286 | 287 | 288 | 1 289 | 290 | 291 | Qt::Horizontal 292 | 293 | 294 | 295 | 296 | 297 | 298 | QFrame::HLine 299 | 300 | 301 | QFrame::Sunken 302 | 303 | 304 | 305 | 306 | 307 | 308 | Normalize zoom 309 | 310 | 311 | 312 | 313 | 314 | 315 | QFrame::HLine 316 | 317 | 318 | QFrame::Sunken 319 | 320 | 321 | 322 | 323 | 324 | 325 | Fractal color 326 | 327 | 328 | 329 | 330 | 331 | 332 | Color not chosen 333 | 334 | 335 | 336 | 337 | 338 | 339 | QFrame::HLine 340 | 341 | 342 | QFrame::Sunken 343 | 344 | 345 | 346 | 347 | 348 | 349 | Ambience color 350 | 351 | 352 | 353 | 354 | 355 | 356 | Color not chosen 357 | 358 | 359 | 360 | 361 | 362 | 363 | QFrame::HLine 364 | 365 | 366 | QFrame::Sunken 367 | 368 | 369 | 370 | 371 | 372 | 373 | Generate random 374 | 375 | 376 | 377 | 378 | 379 | 380 | Qt::Vertical 381 | 382 | 383 | 384 | 20 385 | 40 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 0 401 | 0 402 | 403 | 404 | 405 | 406 | 0 407 | 0 408 | 409 | 410 | 411 | 412 | 16777215 413 | 16777215 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | true 422 | 423 | 424 | 425 | 0 426 | 0 427 | 428 | 429 | 430 | 431 | 0 432 | 50 433 | 434 | 435 | 436 | 437 | 16777215 438 | 50 439 | 440 | 441 | 442 | false 443 | 444 | 445 | 446 | 447 | 448 | Start 449 | 450 | 451 | 452 | 453 | 454 | 455 | Recording is not started. 456 | 457 | 458 | 459 | 460 | 461 | 462 | 0 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 0 478 | 0 479 | 1000 480 | 30 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | FractalWidget 489 | QWidget 490 |
FractalWidget.hpp
491 | 1 492 |
493 |
494 | 495 | 496 |
497 | --------------------------------------------------------------------------------