Author Topic: Pulsar Star Galaxy Rotation  (Read 1251 times)

B+

  • Guest
Pulsar Star Galaxy Rotation
« on: May 29, 2017, 09:36:18 PM »
Ready for a wicked headache?

Code: [Select]
' Pulsar star galaxy rotation.bas SmallBASIC 0.12.9 (B+=MGA) 2017-05-30

'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'
'   CAUTION: DO NOT RUN THIS CODE IF YOU ARE SUSCEPTIBLE to SEIZURES
'
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

sr = 10 : cx = xmax/2 : cy = ymax/2 : b = 1 : bdir = 1
rr = rnd : gg = rnd : bb = rnd
while 1
  cls
  nstars = 1 : starN = 1
  for s = 1 to sr step 3
    color rgb(rnd*255, rnd*255, rnd *255)
    star cx, cy, .1*s, s, 5, deg(a)*20
  next
  rr = 2 * sr
  while nstars < 1000
    circ = 2 * pi * rr
    n = int(circ / (2*sr))
    clr++
    color rgb(127+127*sin(clr*rr), 127+127*sin(clr*gg), 127+127*sin(clr*bb))
    for i = 1 to n
      x = cx + b*rr*cos(i * 2*pi/n + a)
      y = cy + 1/b*rr*sin(i * 2*pi/n + a)
      star x, y, .1*sr, .8*sr, 5, deg(a)*20
    next
    nstars = nstars + n
    rr = rr + 2 * sr
  wend
  showpage
  a = a + pi/90
  b = b + .01 * bdir
  if b > 2.5  then bdir = bdir * -1 : b = 2.5
  if b < .2 then bdir = bdir * -1 : rr = rnd : gg = rnd : bb = rnd : b = .2
wend

sub star( x, y, rInner, rOuter, nPoints, angleOffset)
  local pAngle, radAngleOffset, i, x1, y1, x2, y2, x3, y3
  ' x, y are same as for circle,
  ' rInner is center circle radius
  ' rOuter is the outer most point of star
  ' nPoints is the number of points,
  ' angleOffset = angle offset IN DEGREES, it will be converted to radians in sub
  ' this is to allow us to spin the polygon of n sides
  pAngle = RAD(360 / nPoints)  :  radAngleOffset = RAD(angleOffset)
  x1 = x + rInner * cos(radAngleOffset)
  y1 = y + rInner * sin(radAngleOffset)
  for i = 0 to nPoints - 1
    x2 = x + rOuter * cos(i * pAngle + radAngleOffset + .5 * pAngle)
    y2 = y + rOuter * sin(i * pAngle + radAngleOffset + .5 * pAngle)
    x3 = x + rInner * cos((i + 1) * pAngle + radAngleOffset)
    y3 = y + rInner * sin((i + 1) * pAngle + radAngleOffset)
    line x1, y1, x2, y2
    line x2, y2, x3, y3
    x1 = x3 : y1 = y3
  next
end sub

Screenshots look harmless enough... hee, hee...