Skip to content

Instantly share code, notes, and snippets.

@Bri-G
Created May 29, 2012 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bri-G/2823293 to your computer and use it in GitHub Desktop.
Save Bri-G/2823293 to your computer and use it in GitHub Desktop.
Nodules
-- A converted javascript (by Keith Peters) adapted for Codea by Bri_G
-- ref. http://www.bit-101.com/blog/?p=3214
-- excellent description given note - retained background used
function setup()
-- system and variable initialisations
displayMode(FULLSCREEN)
backingMode(RETAINED)
wide = WIDTH
high = HEIGHT
pts = {}
points = 100
nopts = 1
max = 150
bckgnd = "FALSE"
end
function draw()
-- background not used so network built up from start
-- normal or inverse colouring can be used
-- rem out the next 4 lines for black background
if bckgnd == "FALSE" then
background(255,255,255,255)
bckgnd = "TRUE"
end
-- generate a random point on the screen
temp = vec2(math.random(wide), math.random(high))
-- loop to check if new point networkable with dist < 150
-- checks for each point in the array
for i = 1, points do
pts[i] = vec2(math.random(wide), math.random(high))
dx = pts[i].x - temp.x
dy = pts[i].y - temp.y
dist = math.sqrt(dx*dx + dy*dy)
if (dist < max) then
-- change the number in lineWidth to modify display
lineWidth = 5 - dist/max
strokeWidth(lineWidth)
stroke(218, 43, 53, 20)
line(pts[i].x, pts[i].y, temp.x, temp.y)
end
end
nopts = nopts + 1
pts[nopts] = temp
end
@Bri-G
Copy link
Author

Bri-G commented May 29, 2012

This file was produced from a javascript file by Keith Peters. It was adapted for Codea by Bri_G
ref. http://www.bit-101.com/blog/?p=3214
The reference page gives an excellent description of it's construction
note - retained background used to produce the required cumulative effect, use of background for each draw() pass gives minimal flashing output.
I think this looks better in inverse colouring red on black background.
Don't run it too long - heavy on CPU usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment