Message from Chris Warren-Smith
#1
Chris at Google:
Quote:I found an interesting article on hacker news about a new visualisation of prime numbers: https://news.ycombinator.com/item?id=17103157

I was going to post this on the Joyful Programmer but it won't let me reset my password.

Anyway, here's my version in SmallBASIC.
Code:
'http://www.gibney.de/parallax_primes
'https://news.ycombinator.com/item?id=17103157
packSize = 10 ' Number of integers per cell
const cellSize = 8

func isPrime(n)
  local s = sqr(n)
  local i = 2
  while i <= s
    if (n % i == 0) then return false
    i++
  wend
  return n > 1
end

func packHasPrimes(num, y)
  local i
  for i = 0 to packSize
    if (isPrime(num)) then return true
    num += y
  next i
  return false
end

sub drawPattern
  local black = rgb(0,20,0)
  local red = rgb(120,0,0)
  local x, y, col, x1, y1
  local curNum = 1

  for y = 1 to 80
    for x = 0 to y
      col = iff(packHasPrimes(curNum + x, y), black, red)
      x1 = xmax / 2  + (x * cellSize) - (y * cellSize / 2)
      y1 = (y * cellSize)
      rect x1, y1, x1 + cellSize, y1 + cellSize, col filled
    next x
    curNum += packSize * y
  next y
end

color 1,rgb(40,50,0): cls
for packSize = 1 to 50
  drawPattern
  showpage
  delay 100
next
pause

Note: when copy/pasting message there was allot of HTML crud I had to edit, I think I got it right?
Now I am going to check it out with a few runs...

Walter is Edition still closed to new members?
B += x
Reply
#2
scratching my head? 

The drawing stops here:
B += x
Reply
#3
Another head scratcher is that old Lander code from 80's on the Home Page for SmallBASIC.

It's like he deliberately wants to turn everyone off to SmallBASIC.

I will offer slight update, at least it won't be console text program.
B += x
Reply
#4
@Bplus,

Where did the quote come from? How do I get a hold of this Chris?

I think what he needs is clear his browser cache and everything will work. If it doesn't, I can manually change it for him.

Let me know how to get a hold of Chris, so I can try to resolve his issue.
Dedicated to empowering computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
profile for Walter Whitman at Stack Overflow, Q&A for professional and enthusiast programmers


Reply
#5
Sorry forgot to link:
https://plus.google.com/communities/1080...6282026044
B += x
Reply
#6
(06-02-2018, 12:47 AM)bplus Wrote: Another head scratcher is that old Lander code from 80's on the Home Page for SmallBASIC.

It's like he deliberately wants to turn everyone off to SmallBASIC.

I will offer slight update, at least it won't be console text program.

For you Chris (if you are still watching), to show off more what SmallBASIC can do, an updated Lander program.
Code:
' Lander update.bas SmallBASIC 0.12.11 (B+=MGA) 2018-06-01

'modified code from my 2nd mod of:
'Lander mod 2.txt for JB v2 B+ 2018-05-29 big mod of
'Lander by Carl mod Rod mod B+.txt for JB v2 started 2018-05-26
'where I rewired controls and changed physics of Lander Model.

'This will further depart from Carls's original by hand drawing Lander
'at different angles instead of using sprites and, alas, landscape will
'have to be updated each frame because there is no drawing on top of images
'in SmallBASIC.

' INSTRUCTIONS:
   'Use the left or right arrow keys to rotate Lander left or right.
   'Use the up arrow for thruster burst. These moves cost fuel!
   'The Fuel Gage is Red Horizontal line below landscape.
   'The fuel level is Yellow.
   
   'You must make a VERY gentle and level landing
   'on one of the flat areas!
   
   'Horizontal location, speed in green.
   '  Vertical location, speed in blue


definekey 0xFF04, moveLeft   'press left arrow rotate craft
definekey 0xFF05, moveRight  'press right arrow, rotate craft
definekey 0xFF09, moveUp     'press up arrow, for forward thrust
definekey 27, quit           'press esc to quit

const d2r = pi/180

'stars
ns = 125
dim sx(ns), sy(ns), sr(ns), sc(ns)
for i = 0 to ns
 sx(i) = rnd * xmax
 sy(i) = rnd * ymax
 r = rnd
 if r < .8 then
   sr(i) = 1
 elif r < .95
   sr(i) = 2
 else
   sr(i) = 3
 fi
 sc(i) = rgb(rnd*74 + 180, rnd*74 + 180, rnd*74 + 180)
next

' ground profile with flat zones for landing
dim terraH(xmax), terraC(xmax)
rate1 = rnd / (rnd * 10 + 15)
rate2 = rnd / (rnd * 5 + 5)
for x = 0 to xmax
 if x > 0 and rnd < 0.012 then
   xstop = min(xmax, x + 50)
   for lz = x to xstop
     terraH(lz) = y
     c = rnd * 50 + 50
     terraC(lz) = c
   next
   x = lz - 1
 else
   holder1 = holder1 + rate1
   holder2 = holder2 + rate2
   holder3 = holder3 + sin(holder2)/20
   y = 600 + sin(holder1) * 50 + cos(holder2) * 50 + cos(holder3) * 15
   terraH(x) = y
   c = rnd * 50 + 50
   terraC(x) = c
 end if
next

w = window()

label restart  'initialize
fuel = 500  'this is the space vehicle's fuel

'vda is vehicle degree angle = orientation of the vehicle, mainly it's thrusters
vda = 0     'the vehicle is traveling right across screen due East = 0 degrees = 0 Radians
speed = 6   'this is the speed the vehicle is moving in the vda direction
vx = 50     'this is current x position of vehicle 10 pixles from left side
vy = 10     'this is current y position of vehicle 10 pixels down from top of screen

'd stands for delta with stands for change dx = change in x, dy = change in y
'dg is change due to gravity (vertical)
'dat is change of acceleration due to thrust
dx = speed * cos(d2r * vda)  'this is the horizontal x change on screen due to speed and angle
dy = speed * sin(d2r * vda)  'this is the vertical y change on screen due to speed and angle
dg = .1     'this is the constant acceleration gravity applies to the vehicle
dat = 2     'this is burst of acceleration a thrust or reverse thrust will apply to speed and angle

while 1
 cls
 scene
 'fuel line
 rect 20, ymax - 25, xmax - 20, ymax - 5, 12 filled
 ff = fuel/500 * (xmax - 40)
 rect 20, ymax - 20, ff + 20, ymax - 10, 14 filled
 color 10
 at 10, ymax/2 :      ? "Horizontal: ";int(vx);", ";int(dx)
 color 9
 at 10, ymax/2 + 20 : ? "  Vertical: ";int(vy);", ";int(dy)

 'vehicle falls faster and faster, because gravity effects the vertical speed
 dy = dy + dg  'speed up falling due to gravity acceleration

 'new position = last postion plus the horizontal and vertical changes from momentum
 vx = vx + dx
 vy = vy + dy

 if vx < 0 or vx > xmax or vy < -50 then
   w.alert("You have drifted off screen.")
   goto playAgain
 end if
 if vy <= terraH(vx) and fuel > 0 then
   Lander vx, vy, d2r * vda
 else
   crash$ = ""
   if vda <> 270 then crash$ = crash$ + "Vehicle not upright. "
   if dy > 4 then crash$ = crash$ + "Came down too fast. "
   if dx > 4 then crash$ = crash$ + "Still moving hoizontally too fast. "
   if fuel <= 0 then crash$ = crash$ + "Ran out of fuel. "
   if terraH(vx -10) <> terraH(vx + 10) then crash$ = crash$ + "Did not land on level site. "
   if crash$ <> "" then
     w.alert(crash$,  "You crashed!")
   else
     w.alert("Nice job!", "Successful landing!")
   end if
   goto playAgain
 end if
 showpage
 delay 100
wend

label playAgain
w.ask("", "Play Again?")
if w.answer = 0  then goto restart
stop

sub scene
 for i = 0 to ns
   circle sx(i), sy(i), sr(i), 1, sc(i) filled
 next
 for i = 0 to xmax
   line i, terraH(i) , i, ymax, rgb(terraC(i), terraC(i), terraC(i))
 next
end
'                              arrow + esc key
sub moveUp
 'here is the vertical and horizontal change from a burst of fuel for thrust
 thrustx = dat * cos(d2r * vda )
 thrusty = dat * sin(d2r * vda )

 'now change the horizontal and vertical momentums from the thrust
 dx = dx + thrustx
 dy = dy + thrusty

 'update the position

 vx = vx + dx
 vy = vy + dy
 circle vx, vy, 5, 1, 14 filled
 showpage

 'the thrust cost fuel
 fuel = fuel - 10
end

sub moveLeft
 local x1, y1
 x1 = vx + 10 * cos(d2r * vda + .5 * PI)
 y1 = vy + 10 * sin(d2r * vda + .5 * PI)
 circle x1, y1, 5, 1, 14 filled
 showpage
 vda = vda - 22.5
 if vda < -0.01 then vda = 360
 fuel = fuel - 10
end

sub moveRight
 local x1, y1
 x1 = vx + 10 * cos(d2r * vda - .5 * PI)
 y1 = vy + 10 * sin(d2r * vda - .5 * PI)
 circle x1, y1, 5, 1, 14 filled
 showpage
 vda = vda + 22.5
 if vda > 337.51 then vda = 0
 fuel = fuel - 10
end

sub quit
 stop
end

sub Lander(x0, y0, rAngle) 'rebuilt from ground up literally!
 'x0, y0 are at the base of the lander, the rocket will point rAngle up when landing
 local pangle, x1, x2, y1, y2, x3, y3, x4, y4, i, arr
 color rgb(195, 195, 225)

 x1 = x0 + 10 * cos(rAngle - .5 * PI)
 y1 = y0 + 10 * sin(rAngle - .5 * PI)
 x2 = x0 + 10 * cos(rAngle + .5 * PI)
 y2 = y0 + 10 * sin(rAngle + .5 * PI)
 x3 = x0 + 10 * cos(rAngle)
 y3 = y0 + 10 * sin(rAngle)
 x4 = x0 + 25 * cos(rAngle)
 y4 = y0 + 25 * sin(rAngle)
 'legs/fins
 line x3, y3, x1, y1
 line x3, y3, x2, y2
 line x4, y4, x1, y1
 line x4, y4, x2, y2
 x5 = x0 + 20 * cos(rAngle)
 y5 = y0 + 20 * sin(rAngle)
 pangle = 2 * pi / 8
 dim arr(2 * 8 + 1)
 for i = 0 to 8
     x1 = x4 + 15 * cos(i * pangle + rAngle)
     y1 = y4 + 15 * sin(i * pangle + rAngle)
   arr(2 * i) = x1
   arr(2 * i + 1) = y1
 next
 drawpoly arr filled
end

So it's 130 more lines,... it's fun graphics program that will develop your astronaut skills!

Here is what a bad crash looks like:


And one of many successful landings:


I have to say, it was a real B getting this going from JB code. A bad case of the invisible characters that creep into the SB editor, st a program line does not end where you'd think it should. Anyway, got thru that and learned to use some Windows message boxes and even used an answer to Play Again. Oh the fun part was adding little flashes under the legs or main thruster whenever the user presses an arrow key and burns fuel. That part was fun!
B += x
Reply
#7
Well I get the feeling we are being watched. ;-))


Chris, did you try tossing your cookies from browser when you exit this site?
Wait... you aren't even getting logged in first...?

Dang, I am not sure I want to try another Source Forge Forum.
B += x
Reply
#8
Curious.

I recognize the game, albeit an earlier version, but I couldn't find it on the SB site... I was going to compare it to the current version... Oh well...

J
May your journey be free of incident.

Live long and prosper.
Reply