# JoyOfVex4

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

### Day 4

chramp can be a much more direct and visual way to shape things. Eg, to alter distance from the previous lesson:

```float d = length(@P);
d *= ch('scale');
@P.y = chramp('myramp',d);
```

Alter the scale slider so that the ramped values fit onto the grid. Invert the ramp so that it starts high, ends low. Click a few more points within the ramp, change the shape. Make a rough sine wave just using the ramp. Now change the scale slider, see that it repeats (kind of a misbehavior that chramp has an implicit modulo, explain that a bit)

Add time to the mix, now you have a way to define time based waveforms:

```float d = length(@P);
d *= ch('scale');
d += @Time;
@P.y = chramp('myramp',d);
```

Show how you can make sawtooths, or move up, hold, move back, hold, scale time to speed up and slow down, use the different ramp curve modes to get smoothed motion. Explain that the chramp editor is a bit lame and doesn't easily let you go above 1 or below 0, and editing curve points is a pain, but its still very useful.

Tie this into previous lessons, like feeding it a sine wave, shape the sine:

```float d = length(@P);
d *= ch('scale');
d += @Time;
d = sin(d);
@P.y = chramp('myramp',d);
```

chramps also implicitly clamp 0 to 1, so usually good practice to fit to 0 1 before feeding to chramp:

```float d = length(@P);
d *= ch('scale');
d += @Time;
d = fit(sin(d),-1,1,0,1);
@P.y = chramp('myramp',d);
```

Point out that generally its good to make things work in 0 to 1, that this process is called normalisation, most functions work more predictably when the inputs are normalised. For vectors, there's a function to do this, will be covered in future topics.

Exercises:

1. Create sawtooth waves, triangle waves, square waves
2. Affect colour in this way to make a shape pules with pleasing colours
3. Do this to the different colour components at different rates, get trippy
4. Affect colour and position in different ways, find the most interesting way to break the pig. Keep all the effects controllable from channels.