-
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
1 parent
196a9e6
commit ddbf4fc
Showing
8 changed files
with
460 additions
and
9 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
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,126 @@ | ||
#include "math.h" | ||
|
||
|
||
static double rawnoise(int n) { | ||
n = (n << 13) ^ n; | ||
return (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); | ||
} | ||
|
||
static double noise1d(int x, int octave, int seed) { | ||
return rawnoise(x * 1619 + octave * 3463 + seed * 13397); | ||
} | ||
|
||
static double noise2d(int x, int y, int octave, int seed) { | ||
return rawnoise(x * 1619 + y * 31337 + octave * 3463 + seed * 13397); | ||
} | ||
|
||
static double noise3d(int x, int y, int z, int octave, int seed) { | ||
return rawnoise(x * 1919 + y * 31337 + z * 7669 + octave * 3463 + seed * 13397); | ||
} | ||
|
||
static double interpolate(double a, double b, double x) { | ||
double f = (1 - cos(x * 3.141593)) * 0.5; | ||
|
||
return a * (1 - f) + b * f; | ||
} | ||
|
||
static double smooth1d(double x, int octave, int seed) { | ||
int intx = (int)x; | ||
double fracx = x - intx; | ||
|
||
double v1 = noise1d(intx, octave, seed); | ||
double v2 = noise1d(intx + 1, octave, seed); | ||
|
||
return interpolate(v1, v2, fracx); | ||
} | ||
|
||
static double smooth2d(double x, double y, int octave, int seed) { | ||
int intx = (int)x; | ||
double fracx = x - intx; | ||
int inty = (int)y; | ||
double fracy = y - inty; | ||
|
||
double v1 = noise2d(intx, inty, octave, seed); | ||
double v2 = noise2d(intx + 1, inty, octave, seed); | ||
double v3 = noise2d(intx, inty + 1, octave, seed); | ||
double v4 = noise2d(intx + 1, inty + 1, octave, seed); | ||
|
||
double i1 = interpolate(v1, v2, fracx); | ||
double i2 = interpolate(v3, v4, fracx); | ||
|
||
return interpolate(i1, i2, fracy); | ||
} | ||
|
||
static double smooth3d(double x, double y, double z, int octave, int seed) { | ||
int intx = (int)x; | ||
double fracx = x - intx; | ||
int inty = (int)y; | ||
double fracy = y - inty; | ||
int intz = (int)z; | ||
double fracz = z - intz; | ||
|
||
|
||
double v1 = noise3d(intx, inty, intz, octave, seed); | ||
double v2 = noise3d(intx + 1, inty, intz, octave, seed); | ||
double v3 = noise3d(intx, inty + 1, intz, octave, seed); | ||
double v4 = noise3d(intx + 1, inty + 1, intz, octave, seed); | ||
double v5 = noise3d(intx, inty, intz + 1, octave, seed); | ||
double v6 = noise3d(intx + 1, inty, intz + 1, octave, seed); | ||
double v7 = noise3d(intx, inty + 1, intz + 1, octave, seed); | ||
double v8 = noise3d(intx + 1, inty + 1, intz + 1, octave, seed); | ||
|
||
double i1 = interpolate(v1, v2, fracx); | ||
double i2 = interpolate(v3, v4, fracx); | ||
double i3 = interpolate(v5, v6, fracx); | ||
double i4 = interpolate(v7, v8, fracx); | ||
|
||
double j1 = interpolate(i1, i2, fracy); | ||
double j2 = interpolate(i3, i4, fracy); | ||
|
||
return interpolate(j1, j2, fracz); | ||
} | ||
|
||
static double pnoise1d(double x, double persistence, int octaves, int seed) { | ||
double total = 0.0; | ||
double frequency = 1.0; | ||
double amplitude = 1.0; | ||
int i = 0; | ||
|
||
for(i = 0; i < octaves; i++) { | ||
total += smooth1d(x * frequency, i, seed) * amplitude; | ||
frequency /= 2; | ||
amplitude *= persistence; | ||
} | ||
|
||
return total; | ||
} | ||
|
||
static double pnoise2d(double x, double y, double persistence, int octaves, int seed) { | ||
double total = 0.0; | ||
double frequency = 1.0; | ||
double amplitude = 1.0; | ||
int i = 0; | ||
|
||
for(i = 0; i < octaves; i++) { | ||
total += smooth2d(x * frequency, y * frequency, i, seed) * amplitude; | ||
frequency /= 2; | ||
amplitude *= persistence; | ||
} | ||
|
||
return total; | ||
} | ||
|
||
static double pnoise3d(double x, double y, double z, double persistence, int octaves, int seed) { | ||
double total = 0.0; | ||
double frequency = 1.0; | ||
double amplitude = 1.0; | ||
int i = 0; | ||
|
||
for(i = 0; i < octaves; i++) { | ||
total += smooth3d(x * frequency, y * frequency, z * frequency, i, seed) * amplitude; | ||
frequency /= 2; | ||
amplitude *= persistence; | ||
} | ||
|
||
return total; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <nds.h> | ||
#include <nf_lib.h> | ||
#include <filesystem.h> | ||
#include "screen_utils.h" | ||
#include "scene.h" | ||
#include "../../effolkronium/random.hpp" | ||
#include "../perlin/perlin.cpp" | ||
|
||
|
||
|
||
|
||
|
||
class PerlinScene : public Scene | ||
{ | ||
int t = 0; | ||
|
||
using Random = effolkronium::random_static; | ||
|
||
|
||
public: | ||
void setup() { | ||
|
||
// Set the main diplay to frame buffer mode 0 (FB0). | ||
// In FB0 VRAM A is drawn to the screen. | ||
// REG_DISPCNT_MAIN = MODE_FB0; | ||
// // Enable VRAM A | ||
// VRAM_A_CR = VRAM_ENABLE; | ||
|
||
// Initialize 2D engine in both screens and use mode 0 | ||
// NF_Set2D(0, 5); | ||
// NF_Set2D(1, 5); | ||
|
||
// // Initialize NitroFS and set it as the root folder of the filesystem | ||
// nitroFSInit(NULL); | ||
// NF_SetRootFolder("NITROFS"); | ||
|
||
// initBGSys(); | ||
|
||
// NF_Load16bitsBg("clear", 1); | ||
// NF_Load16bitsImage("circlesmall", CIRCLE_IMG, 16, 16); | ||
} | ||
|
||
|
||
void update() { | ||
|
||
} | ||
|
||
|
||
void draw() { | ||
t++; | ||
|
||
for (int i=0; i<100; i++) { | ||
int x = Random::get(0, SCREENWIDTH); | ||
int y = Random::get(0, SCREENHEIGHT); | ||
|
||
int randomPixel = Random::get(0, SCREENHEIGHT*SCREENWIDTH); | ||
int color = noise3d(x, y, t, 1, 1) * 31; | ||
// VRAM_A[randomPixel] = RGB15(50, 50, 50); | ||
VRAM_A[randomPixel] = noise3d(x, y, t, 1, 1) * 31; | ||
} | ||
} | ||
}; |
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,45 @@ | ||
#include <nds.h> | ||
#include <stdio.h> | ||
|
||
#include "scene.h" | ||
#include "../../effolkronium/random.hpp" | ||
|
||
|
||
|
||
|
||
|
||
class CharsScene : public Scene | ||
{ | ||
int t = 0; | ||
|
||
using Random = effolkronium::random_static; | ||
|
||
|
||
public: | ||
void setup() { | ||
consoleDemoInit(); | ||
|
||
// PrintConsole* console = consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 8, 0, true, true); | ||
// consoleSelect(console); | ||
// consoleInit(NULL, 3, BgType_Text4bpp, BgSize_T_256x256, 8, 0, true, true); | ||
} | ||
|
||
|
||
void update() { | ||
|
||
} | ||
|
||
|
||
void draw() { | ||
t++; | ||
|
||
if (t % 10000 == 0) { | ||
printf("PARRALLEL PROBLEMSPARRALLEL PROB"); | ||
} | ||
|
||
if (t % 300000 == 1000) { | ||
consoleClear(); | ||
} | ||
|
||
} | ||
}; |
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
Oops, something went wrong.