Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. const canvasSketch = require('canvas-sketch');
  2. const { lerp } = require('canvas-sketch-util/math');
  3. const random = require('canvas-sketch-util/random');
  4. const palettes = require('nice-color-palettes');
  5.  
  6. const settings = {
  7. dimensions: [2048, 2048],
  8. };
  9.  
  10. const sketch = () => {
  11. const colorsCount = 5; //random.rangeFloor(1, 6);
  12. const palette = random.shuffle(random.pick(palettes)).slice(0, colorsCount);
  13.  
  14. const createLine = f => {
  15. const points = [];
  16. const count = 3000;
  17.  
  18. for (let x = 500; x < count + 500; x += 1) {
  19. const u = (x - 500) / (count - 1);
  20.  
  21. const radius = random.noise1D((x / count) * 2, f) * 0.5 + 1;
  22.  
  23. points.push({
  24. position: u,
  25. radius,
  26. });
  27. }
  28.  
  29. return { points };
  30. };
  31.  
  32. const margin = 400;
  33.  
  34. return ({ context: ctx, width, height }) => {
  35. ctx.fillStyle = 'hsl(0,0%,98%)';
  36. ctx.fillRect(0, 0, width, height);
  37.  
  38. const { points } = createLine(random.range(1, 10) / 10 + 1);
  39. let diff = 2;
  40.  
  41. const countLines = 100;
  42. for (let i = 1; i < countLines; i += 1) {
  43. diff += i * 1.2;
  44. const color = random.pick(palette);
  45. random.setSeed(Math.random());
  46. ctx.beginPath();
  47. ctx.strokeStyle = color;
  48. ctx.lineWidth = diff;
  49. points.forEach(({ position, radius }) => {
  50. ctx.lineTo(position * width, (radius * height) / 2 + diff);
  51. });
  52. ctx.stroke();
  53. }
  54. };
  55. };
  56.  
  57. canvasSketch(sketch, settings);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement