forked from parallel101/hw01
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,814 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
build | ||
GNUmakefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
project(hellocmake LANGUAGES CXX) | ||
|
||
add_subdirectory(stbiw) | ||
if (NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
add_executable(main main.cpp) | ||
target_link_libraries(main PUBLIC stbiw) | ||
#add_subdirectory(stbiw) | ||
|
||
add_executable(main main.cpp rainbow.cpp mandel.cpp) | ||
#target_link_libraries(main PUBLIC stbiw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
#include "stb_image_write.h" | ||
#include "rainbow.h" | ||
#include "mandel.h" | ||
|
||
int main() { | ||
test_rainbow(); | ||
test_mandel(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "mandel.h" | ||
#include <stb_image_write.h> | ||
#include <vector> | ||
#include <complex> | ||
|
||
void test_mandel() { | ||
std::vector<char> buf(512 * 512); | ||
for (int j = 0; j < 512; j++) { | ||
for (int i = 0; i < 512; i++) { | ||
float x = i / 512.f * 3.0f - 2.0f; | ||
float y = j / 512.f * 3.0f - 1.5f; | ||
std::complex<float> c(x, y); | ||
std::complex<float> z(0, 0); | ||
for (int steps = 0; steps < 256 / 4; steps++) { | ||
z = z * z + c; | ||
if (std::norm(z) >= 4.f) { | ||
buf[j * 512 + i] = 255 - steps * 4; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
stbi_write_png("mandel.png", 512, 512, 1, buf.data(), 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
void test_mandel(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "rainbow.h" | ||
#include <stb_image_write.h> | ||
#include <vector> | ||
|
||
void test_rainbow() { | ||
std::vector<char> buf(512 * 512 * 3); | ||
for (int j = 0; j < 512; j++) { | ||
for (int i = 0; i < 512; i++) { | ||
buf[(j * 512 + i) * 3 + 0] = i / 2; | ||
buf[(j * 512 + i) * 3 + 1] = j / 2; | ||
buf[(j * 512 + i) * 3 + 2] = 0; | ||
} | ||
} | ||
stbi_write_png("rainbow.png", 512, 512, 3, buf.data(), 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
void test_rainbow(); |
Oops, something went wrong.