DrHuang.com | list | math | function | coding | graphics | example | help | ? | 中文
+ + + =

X

Save Your Code

If you click the save button, your code will be saved, and you get an URL you can share with others.

By clicking the "Save" button you agree to our terms and conditions.

Report Error

X

Save to Google Drive

If you have a Google account, you can save this code to your Google Drive.

Google will ask you to confirm Google Drive access.

X

Open from Google Drive

If you have saved a file to Google Drive, you can open it here:

File Save Orien Theme Result Size: 300 x 150
x
 
<body>
<div id="p5container"></div>
<script src="/script/p5/p5.min.js"></script>
<script>
var yoff = 0.0;        // 2nd dimension of perlin noise
function setup() {
  var canvas = createCanvas(640, 360);
  canvas.parent("p5container");
}
function draw() {
  background(20);
  fill('blue');
  // We are going to draw a polygon out of the wave points
  beginShape(); 
  
  var xoff = 0;       // Option #1: 2D Noise
  // var xoff = yoff; // Option #2: 1D Noise
  
  // Iterate over horizontal pixels
  for (var x = 0; x <= width; x += 10) {
    // Calculate a y value according to noise, map to 
    var y = map(noise(xoff, yoff), 0, 1, 200,300); // Option #1: 2D Noise
    // var y = map(noise(xoff), 0, 1, 200,300);    // Option #2: 1D Noise
    
    // Set the vertex
    vertex(x, y); 
    // Increment x dimension for noise
    xoff += 0.05;
  }
  // increment y dimension for noise
  yoff += 0.01;
  vertex(width, height);
  vertex(0, height);
  endShape(CLOSE);
}
</script>
</body>
X

Report a Problem: