I’ve been working on a random path generator using Perlin noise, and it works pretty well, but I’ve been having problems trying to test its to create extremely long paths; right now I’m just plotting the path on a really big image, but it runs out of space pretty quickly. Is there any better way to do this?
For the record, here’s my current source:
--# Main -- Trails -- Use this function to perform your initial setup function setup() displayMode(FULLSCREEN) alg = 2 size = 1/100 speed = 1 rsize = 0.1 rot = 1 fspeed = 100 cp = vec2(WIDTH/2/rsize-100, HEIGHT/4/rsize+100) background(255) ---[[ im = image(WIDTH*2, HEIGHT*2) spriteMode(CORNER) xmin = 9^99 xmax = -1 ymin = 9^99 ymax = -1 --points = {} --backingMode(RETAINED) end -- This function gets called once every frame function draw() -- This sets a dark background color background(255) setContext(im) if ElapsedTime < 0.5 then background(255) end -- Sometimes needed, idk strokeWidth(1) resetMatrix() -- Do your drawing here for n = 1, fspeed do local p = cp cp = algs[alg](cp, size, rot) stroke(0, 0, 0, 255) fill(0, 0, 0, 255) line(p.x * rsize, p.y * rsize, cp.x * rsize, cp.y * rsize) end setContext() translate(math.floor((WIDTH / 2) - cp.x*rsize), math.floor((HEIGHT - 50) - cp.y*rsize)) sprite(im, 0,0, im.width, im.height) resetMatrix() end --# Algs algs = {} algs[1] = function(np, s) np.x = np.x + noise(np.x*s)*speed np.y = np.y + noise(np.y*s)*speed return np end algs[2] = function(np, s, rot) local r = noise(np.x*s, np.y*s)*speed np.x = np.x + math.sin(r*6*math.pi*rot) * speed np.y = np.y + math.cos(r*6*math.pi*rot) * speed return np end algs[3] = function(np, s) local x = noise(np.x*s)*speed local y = noise(np.y*s)*speed if x == 0 then x = 0.05 end if y == 0 then y = 0.05 end x, y = x / (x + y), y / (x + y) np.x = np.x + x * speed np.y = np.y + y * speed return np end ```