Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Starfields 2 - scrolling into the screen
-- StarfFields by Bri_G based on HTML by Seb Lee-Delisle
-- Scrolling field movement into screen
--[[ if require ~= nil then
require("loveCodea")
end --]]
function setup()
--
fov = 250
wide = WIDTH
high = HEIGHT
midX = wide/2
midY = high/2
stars = 1000
pts = { x3D = {}, y3D = {}, z3D = {} }
for i= 1, stars do
pts.x3D[i] = math.random()*wide-midX
pts.y3D[i] = math.random()*high-midY
pts.z3D[i] = math.random()*500-250
end
end
function draw()
--
background(0,0,0,255)
smooth()
fill(255,255,255,255)
for i = 1, stars do
pts.z3D[i] = pts.z3D[i] - 4
if pts.z3D[i] < -fov then pts.z3D[i] = pts.z3D[i] + 500 end
ThreeDto2D(i)
end
attribution()
end
function touched(touch)
end
function ThreeDto2D(i)
--
scale = fov/(fov+pts.z3D[i])
x2D = pts.x3D[i] * scale + midX
y2D = pts.y3D[i] * scale + midY
strokeWidth(scale)
stroke(255,255,255,255)
fill(100,150,150+100*scale)
ellipse(x2D, y2D, scale, scale)
stroke()
end
function attribution()
pushStyle()
font("Georgia")
fontSize(16)
fill(100,250,100,255)
text("from js code by Seb Lee-Delisle", 200,35)
sprite("MWCWhite250", wide - 150,50)
popStyle()
end
@Bri-G

This comment has been minimized.

Copy link
Owner Author

Bri-G commented Jun 19, 2012

Hi All,

Second in the series of Starfields from the code provided by Seb Lee-Delisle. This one has the old favourite scrolling into the screen to give the impression of spaceflight. Check out the other files in my Gists.
Enjoy,
Bri_G

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.