Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (790)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  OpenSimplexNoise - Looping noise  (Read 2783 times)
0 Members and 1 Guest are viewing this topic.
Offline Ecumene

JGO Kernel


Medals: 199
Projects: 4
Exp: 8 years


I did not hit her! I did not!


« Posted 2015-09-30 01:51:19 »

I've made a class with the common implementation of sampling 2 maps and using the OpenSimplex eval 4D function.

This is especially useful for anyone looking for a terrain generator. A friend of mine asked me to help him with this, and I needed it for myself also.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
public class OpenSimplexLoop {
   private OpenSimplexNoise noise;
   private int sizex, sizey;
   
   public OpenSimplexLoop(OpenSimplexNoise noise, int sizex, int sizey) {
      this.noise = noise;
      this.sizex = sizex;
      this.sizey = sizey;
   }
   
   public double loopedNoise(double radx, double rady){
      double s = (radx) / sizex;
      double t = (rady) / sizey;
     
      double x1 = -10, x2 = 10;
      double y1 = -10, y2 = 10;
     
      double dx = x2 - x1;
      double dy = y2 - y1;
     
      double x = x1 + Math.cos(s * 2 * Math.PI) * dx / (2 * Math.PI);
      double y = y1 + Math.cos(t * 2 * Math.PI) * dy / (2 * Math.PI);
      double z = x1 + Math.sin(s * 2 * Math.PI) * dx / (2 * Math.PI);
      double w = y1 + Math.sin(t * 2 * Math.PI) * dy / (2 * Math.PI);
     
      return noise.eval(x, y, z, w);
   }
}


Just plug in the size of your map in the constructor and then sample it within the bounds using
loopedNoise(...)


Some results

Here's a 400x400 img with the seed 300


Here's a 800x800 img with the seed 300 and the coordinates scaled by / 2 (making the noise algo extrapolate)


I based this off of this article also, the author talked about some of the scaling values in the comments if you read his code and are confused.
http://www.gamedev.net/blog/33/entry-2138456-seamless-noise/

Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (2830 views)
2018-11-16 13:46:03

hadezbladez (1019 views)
2018-11-16 13:41:33

hadezbladez (2793 views)
2018-11-16 13:35:35

hadezbladez (546 views)
2018-11-16 13:32:03

EgonOlsen (3816 views)
2018-06-10 19:43:48

EgonOlsen (4226 views)
2018-06-10 19:43:44

EgonOlsen (2537 views)
2018-06-10 19:43:20

DesertCoockie (3350 views)
2018-05-13 18:23:11

nelsongames (3461 views)
2018-04-24 18:15:36

nelsongames (4455 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!