Post by Rod on Feb 12, 2020 15:29:56 GMT -5
Over on the Facebook page there has been a post about a 256 color starfield demo coded in QB. I think that's a challenge to us. This is a nice simple starfield posted by Stefan. It is in black and white and not a sprite in sight. The challenge would be to get it showing 256 color blobs that get brighter and larger as they near the centre.
Sprites are pixel perfect but you might experiment with shaded masks or mesh masks. Its an adventure, sprites are not a necessity, code what you think looks good.
Sprites are pixel perfect but you might experiment with shaded masks or mesh masks. Its an adventure, sprites are not a necessity, code what you think looks good.
' Starfield Simulation Demo
'
' You may use and abuse this code in any kind, without any warranty
'
' Revision History
' ----------------
'
' Date | Name | Reason
' ------------|--------------|--------------------------
' 06.Jan.2005 | Stefan Pendl | Initial
nomainwin
global xCenter, yCenter, velocity
stars = 100
velocity = 2
turns = 100
eraseStars = 1 ' set this to zero to get straight lines for the starpathes
if not(eraseStars) then velocity = 1
dim starPos(stars, 4) ' 1 ... xPos
' 2 ... yPos
' 3 ... xDelta
' 4 ... yDelta
WindowWidth = 800
WindowHeight = 600
UpperLeftX = int((DisplayWidth - WindowWidth) / 2)
UpperLeftY = int((DisplayHeight - WindowHeight) / 2)
open "Starfield Simulation Demo" for graphics_nf_nsb as #main
#main "trapclose [quit]"
#main "down;fill black;flush"
#main "color white;backcolor black"
#main "home;posxy xCenter yCenter"
' get the areas for the 3D effect
xPos1 = xCenter / 3
xPos2 = xPos1 * 2
yPos1 = yCenter / 3
yPos2 = yPos1 * 2
xMin1 = xCenter - xPos1
xMax1 = xCenter + xPos1
xMin2 = xCenter - xPos2
xMax2 = xCenter + xPos2
yMin1 = yCenter - yPos1
yMax1 = yCenter + yPos1
yMin2 = yCenter - yPos2
yMax2 = yCenter + yPos2
' create the initial starfield
for num = 1 to stars
call SetStar num
#main "set "; starPos(num, 1); " "; starPos(num, 2)
next
' simulate a starflight
while count < turns
for num = 1 to stars
' erase old stars, using the biggest pen size used
#main "discard;color black;size 3"
if eraseStars then #main "set "; starPos(num, 1); " "; starPos(num, 2)
' calculate the new position
starPos(num, 1) = starPos(num, 1) + starPos(num, 3)
starPos(num, 2) = starPos(num, 2) + starPos(num, 4)
' init a new star if one is leaving the screen
if starPos(num, 1) < 0 or starPos(num, 1) > WindowWidth or _
starPos(num, 2) < 0 or starPos(num, 2) > WindowHeight then
call SetStar num
end if
' select pen depending on distance from center
pen = 1
select case
case starPos(num, 1) < xMin2 or _
starPos(num, 1) > xMax2 or _
starPos(num, 2) < yMin2 or _
starPos(num, 2) > yMax2
pen = 3
case starPos(num, 1) < xMin1 or _
starPos(num, 1) > xMax1 or _
starPos(num, 2) < yMin1 or _
starPos(num, 2) > yMax1
pen = 2
end select
#main "color white;size "; pen
#main "set "; starPos(num, 1); " "; starPos(num, 2)
next
count = count + 1
wend
wait
[quit]
close #main
end
sub SetStar num
' set x and y position
starPos(num, 1) = int(rnd(0)*WindowWidth)
starPos(num, 2) = int(rnd(0)*WindowHeight)
' calculate relation between x and y
starPos(num, 3) = abs((starPos(num, 1) - xCenter) / (starPos(num, 2) - yCenter + .001)) * velocity
starPos(num, 4) = abs((starPos(num, 2) - yCenter) / (starPos(num, 1) - xCenter + .001)) * velocity
if starPos(num, 1) < xCenter then starPos(num, 3) = -1 * starPos(num, 3)
if starPos(num, 2) < yCenter then starPos(num, 4) = -1 * starPos(num, 4)
end sub