# Script Part I

This entry deals with the examples from the script.

## Basic noise

Perlin noise is a random sequence generator producing a more natural, harmonic succession of numbers than that of the standard random() function.

```void setup(){
size(500,500);
background(0);
noStroke();
for (int x=0;x<width; x=x+20){ // space between rect is 20
rect(x,height/2-random(100),10,10); // variation of y pos, random value up to 100
}
}```
```void setup() {
size(500, 500);
background(0);
noStroke();
for (int x=0; x<width; x=x+20) { // space between rect is 20
float noiseForce = noise(x/100.)*200; // adds noise
rect(x, height/2-noiseForce, 10, 10); // variation of y pos, random value up to 100
}
}```
```void setup() {
size(500, 500);
background(0);
noStroke();
fill(255);
for (int x=0; x<width; x=x+10) { // loop for width
for (int y=0; y<height; y=y+10) { // loop for height
float size = random(10);
rect(x, y, size, size);
}
}
}```
```void setup() {
size(500, 500);
background(0);
noStroke();
for (int x=0; x<width; x=x+10) {
for (int y=0; y<height; y=y+10) {
float xOff=x/100.;
float yOff=y/100.;
float size=noise(xOff, yOff)*10;
rect(x, y, size, size);
}
}
}```

## Some experiments

Experiment with different values related to noise in the above sketches. Try to understand what happens when you change certain values. Try to better understand how noise was applied, in the examples above.

I used the last code above and played around with the values.

```void setup() {
size(500, 500);
background(0);
noStroke();
for (int x=0; x<width; x=x+5) { // changed value to 5
for (int y=0; y<height; y=y+5) { // changed value to 5
float xOff=x/500.; // divided by 500.
float yOff=y/500.; // divided by 500.
float size=noise(xOff, yOff)*10;
rect(x, y, size, size);
}
}
}```

I wanted to put some text on the featured image and so I did. While I wanted to change the font, Processing threw me an error and I learnt about the way to print available fonts in the message box with PFont.list();

```PFont f; // STEP 1 Declare PFont variable

void setup() {
size(500, 500);
f = createFont("IBMPlexSerif-Bold", 16, true); // STEP 2 Create Font
background(0);
noStroke();
for (int x=0; x<width; x=x+5) {
for (int y=0; y<height; y=y+5) {
float xOff=x/500.;
float yOff=y/500.;
float size=noise(xOff, yOff)*5;
rect(x, y, size, size);
}
}
textFont(f, 60);                  // STEP 3 Specify font to be used
fill(0);                         // STEP 4 Specify font color
text("LET'S MAKE", 30, 80);
text("SOME NOISE!", 30, 140);

String[] fontList = PFont.list();
printArray(fontList);
}
```

29/06/20 I still need to work on the stuff below but I wanted to prepare it already at least and looked up the examples I want to work with in the coming days.

01/07/20 Finishing up with the exercises below

## Random code

Please pick up two of your previous sketches, where you have used “random”, and now try to use “noise” instead. Can you achieve some result so that you see the difference between random and noise? How would you characterize the visual difference?

### random()

```void setup() {
size(800, 800);
background(0);
int diameter=10;
for (int x=0; x< width; x=x+diameter) {
for (int y=0; y<height; y=y+diameter) {
if (x==10*diameter && y==10*diameter) {
fill(255);
} else {
diameter=int(random(5)); // diameter changed randomly
fill(random (255),random (0),random (0));
}
noStroke();
ellipse(x, y, diameter, diameter);
}
}
}```

### noise()

```void setup() {
size(500, 500);
background(0);
noStroke();
for (int x=0; x<width; x=x+5) { // changed value to 5
for (int y=0; y<height; y=y+5) { // changed value to 5
float xOff=x/300.; // divided by 500.
float yOff=y/300.; // divided by 500.
float size=noise(xOff, yOff)*6;
fill(random (255),random (0),random (0));
ellipse(x, y, size, size);
}
}
}```

However, in this example I put noise on the size and not on the fill.

Then I tried to put it on the fill. Aesthetically I come to a different result but I still find it interesting.

```void setup() {
size(800, 800);
background(0);
int diameter=10;

for (int x=0; x< width; x=x+diameter) {
for (int y=0; y<height; y=y+diameter) {
float xOff=x/400.;
float yOff=y/400.;
float c = noise(xOff, yOff)*255;
if (x==10*diameter && y==10*diameter) {
fill(20);
} else {
fill(c, 0, 0);
}
noStroke();
ellipse(x, y, diameter, diameter);
}
}
}```

I changed some values randomly and came to this result which I find kinda nice. I didn’t expect this.

```void setup() {
size(800, 800);
float diameter=15;
for (int x=0; x< width; x=x+ (int) diameter) {
for (int y=0; y<height; y=y+ (int) diameter) {
float xOff=x/100.;
float yOff=y/100;
float r = noise(xOff, yOff)*255;
float g = 50;
float b = 100;
fill (r, g, b);
noStroke();
ellipse(x, y, diameter, diameter);
}
}
}```

Last one…

```void setup() {
size(800, 800);
background(0);
for (int i=700; i>1; i=i-10) {  //note that we are counting down, in steps of -10
stroke(0);
float xOff=i/100.;
float yOff=i/100;
float r = noise(xOff, yOff)*255;
float g = 50;
float b = 100;
fill (r, g, b);
ellipse(400, 400, i, i);
}
}```

## Recap

I read through the chapter of the book and revisited the examples from the fun coding session and the script in order to better understand noise. However, I still need to do my own experiments which will be the tricky part.