Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
SleepingShell committed May 11, 2023
0 parents commit bd728c2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
refs/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Noir implementation of the Dark Forest game (https://zkga.me)
5 changes: 5 additions & 0 deletions perlin/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = ["SleepingShell"]
compiler_version = "0.4.1"

[dependencies]
42 changes: 42 additions & 0 deletions perlin/src/lib.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use dep::std;

// Taken from darkforest-eth, nefgatives were mod 1000
global DIRECTIONS: [(Field, Field); 16] = [(1000,0),(923,382),(707,707),(382,923),(0,1000),(617,923),(292,707),(76,382),(0,0),(76,617),(292,292),(617,76),(999,0),(382,76),(707,292),(923,617)];
//global DENOMINATOR = 1125899906842624000;
global DENOMINATOR = 1125899906842624;

// Return a psuedorandom integer in [0, 15]
fn Random(x : Field, y : Field, scale : Field) -> u4 {
let t = std::hash::mimc_bn254([x, y, scale]);
std::println(t);

let bits = t.to_le_bits(32);
8*(bits[3] as u4) + 4*(bits[2] as u4) + 2*(bits[1] as u4) + (bits[0] as u4)
//((t as u120) & 0x0f) as Field
}

fn RandomGradientAt(x: Field, y: Field, scale: Field) -> (Field, Field) {
let rand = Random(x, y, scale);

let mut direction = (0,0);
for i in 0..15 {
if (i as u4 == rand) {
direction = DIRECTIONS[i];
}
}

let x = direction.0;
let y = direction.1;

(x * DENOMINATOR , y * DENOMINATOR)
}

#[test]
fn test_Random() {
let r = Random(1, 3, 16);
std::println(r);

let (gx, gy) = RandomGradientAt(1,4,16);
std::println(gx);
std::println(gy);
}

0 comments on commit bd728c2

Please sign in to comment.