Created
June 19, 2012 10:00
-
-
Save Bri-G/2953341 to your computer and use it in GitHub Desktop.
Starfields 3 - this one spins around a star matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- StarfFields by Bri_G based on HTML by Seb Lee-Delisle | |
| -- Rotating field around a central star matrtix | |
| --[[ 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 | |
| rotateStarfield(i, 0.04) | |
| 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 rotateStarfield(i, angle) | |
| -- | |
| cosRY = math.cos(angle) | |
| sinRY = math.sin(angle) | |
| tempZ = pts.z3D[i] | |
| tempX = pts.x3D[i] | |
| pts.x3D[i] = (tempX*cosRY)+(tempZ*sinRY) | |
| pts.z3D[i] = (tempX*-sinRY)+(tempZ*cosRY) | |
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi All,
Third in the series of Starfields from the code provided by Seb Lee-Delisle. This one has the old a scrolling effect around a starfield matrix. Check out the other files in my Gists.
Enjoy,
Bri_G