Thursday, January 12, 2017

Pedometer reading from 2015 and 2016

It's interesting to look back on my pedometer readings from 2015 and 2016 using my Omron HJ-720IT.

I thought I was pretty consistent from year to year and month to month.

Each hundred steps equals roughly a minute of walking, so 8000 steps is roughly 80 minutes.

Wednesday, January 11, 2017

Tiger Learning computer based on the Apple IIe


This is really something. I never knew these even existed. I always wished that they would've made an Apple II dtv like the c64 dtv.


Bounty Bob Strikes Back

I used to really love Miner 2049er on my old apple II back in the day. I wish I'd had a c64 or an atari so I could've played Bounty Bob Strikes Back.

These are the classic games I loved: Miner 2049er, Jumpman, Hard Hat Mack, Mr Robot and his Robot Factory. Genius. Give me this over ultra manic 3d games any day.



And an Atari ST remake called Clod Hopper.

TurtleGraphics with the Turtle in Excel

Let's add a turtle to the Graph.





So we put a bunch of parameters on the sheet for TurtleAngle, TurtleXY, TurtleScale, along with a set of points for the turtle:



and set up some matrices to rotate, scale, and translate the points:



And a little bit of code to update the turtle:



Oh and don't forget to add the range of computed points to the graph as another data series.




And the code is pretty short:

If you're using Libreoffice Calc, add

Option VBASupport 1

and comment out the line in colorpoint


Dim xpos, ypos, angle, pencolor As Single
Dim turtlescale As Single
Dim penstatus As Integer
Dim pi As Single
Dim rowpos As Integer

Sub colorpoint(rowpos)
     'comment out for LibreOffice Calc
     ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).Points(rowpos).Format.Line.ForeColor.RGB = pencolor
End Sub


Sub pc(acolor)
pencolor = acolor
End Sub

Sub initturtle()
rowpos = 1
pi = 3.14
xpos = 0
ypos = 0
angle = 0
pencolor = RGB(255, 0, 0)
penstatus = 1
Cells(1, 1).Resize(500, 2).Clear
turtlescale = 1
updateturtle
End Sub

Sub tsize(x)
  turtlescale = x / 100
  updateturtle
End Sub

Sub updateturtle()
  Cells(1, 6) = angle
  Cells(2, 6) = xpos
  Cells(2, 7) = ypos
  Cells(3, 6) = turtlescale
End Sub


Sub pu()
 penstatus = 0
End Sub

Sub pd()
 penstatus = 1
End Sub

Sub setangle(x)
  angle = x
  updateturtle
End Sub


Sub rt(x)
  angle = angle - x
  updateturtle
End Sub

Sub lt(x)
  rt -x
End Sub


Sub movepos(newxpos, newypos)
  
  oldxpos = xpos
  oldypos = ypos 
    
  If penstatus = 1 Then
    If (rowpos = 1) Then
      ActiveSheet.Cells(rowpos, 1) = oldxpos
      ActiveSheet.Cells(rowpos, 2) = oldypos
      colorpoint rowpos
      rowpos = rowpos + 1
      ActiveSheet.Cells(rowpos, 1) = newxpos
      ActiveSheet.Cells(rowpos, 2) = newypos
      colorpoint rowpos
    ElseIf (ActiveSheet.Cells(rowpos, 1) = oldxpos) And (ActiveSheet.Cells(rowpos, 2) = oldypos) Then
      rowpos = rowpos + 1
      colorpoint rowpos
      ActiveSheet.Cells(rowpos, 1) = newxpos
      ActiveSheet.Cells(rowpos, 2) = newypos
    Else
      rowpos = rowpos + 1
      colorpoint rowpos
      'assigning a cell to empty doesn't actually do anything in LibreOffice
      'LibreOffice likes clear though
      ActiveSheet.Cells(rowpos, 1) = Empty  
      ActiveSheet.Cells(rowpos, 2) = Empty
      ActiveSheet.Cells(rowpos, 1).clear  
      ActiveSheet.Cells(rowpos, 2).clear  
      rowpos = rowpos + 1
      colorpoint rowpos
      ActiveSheet.Cells(rowpos, 1) = oldxpos
      ActiveSheet.Cells(rowpos, 2) = oldypos
      rowpos = rowpos + 1
      colorpoint rowpos
      ActiveSheet.Cells(rowpos, 1) = newxpos
      ActiveSheet.Cells(rowpos, 2) = newypos
  End If
  End If
   xpos = newxpos
   ypos = newypos
   updateturtle
End Sub

Sub fd(dist)
  newxpos = xpos + Cos(angle / 360 * 2 * pi) * dist
  newypos = ypos + Sin(angle / 360 * 2 * pi) * dist
  movepos newxpos, newypos
End Sub
Sub bk(x)
  fd -x
End Sub


Sub refresh()
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End Sub


Sub test1()
Call initturtle: For j = 1 To 6: For i = 1 To 20: call refresh: lt 360 / 20: fd 20: Next i: rt 60: Next j
End Sub

Sub test2()
Call initturtle: For i = 1 To 50: call refresh: Call pu: movepos Rnd() * 50, Rnd() * 50: Call pd: movepos Rnd() * 50, Rnd() * 50: pc RGB(Rnd() * 255, Rnd() * 255, Rnd() * 255): Next i
End Sub

Tuesday, January 10, 2017

Getting excel to refresh the screen

Figured this out today:

just toggle Application.ScreenUpdating with:

Application.ScreenUpdating = False
Application.ScreenUpdating = True

and excel will refresh the screen.

so make a routine and call it refresh:

sub refresh
Application.ScreenUpdating = False
Application.ScreenUpdating = True
end sub



sub test1
Call initturtle: For j = 1 To 6: For i = 1 To 20: lt 360 / 20: fd 20: call refresh : Next i: rt 60: Next j
end sub

Simple rotation matrix in Libreoffice Calc

Just for fun, I thought I'd see how the matrix multiplication works in Libreoffice.

So we have a little set of XY points in a1:b5 to draw a triangular shape.

Put the rotation angle in c1 and convert that to radians in d1.

A rotation matrix in e1:f2 that is transposed from the wikipedia form as it gets multipled rows by columns.

and put a matrix forula with CTRL+SHIFT+ENTER in g1:h5.

Insert a chart with a two data ranges, graphing a1:b5 and g1:h5. It looks best if you set the axes from -20 to 20.










LibreOffice calc redraws the graph on the fly so you get an animation with this:




Monday, January 9, 2017

Turtlegraphics on an Excel xy scatter chart

I was making an xy chart and discovered that if I had gaps in the data, that they would appear as disconnected lines in the chart.

So then I could make vector graphics on a chart.

And do some turtle graphics.


First, make a blank workbook and then insert a xy scatter chart, set the data source as A1:B200, and make sure that gaps will appear for empty lines.

Then have this code in a VBA Module:

Dim xpos, ypos, angle, pencolor As Single
Dim penstatus As Integer
Dim pi As Single
Dim rowpos As Integer



Sub pc(acolor)
pencolor = acolor
End Sub

Sub initturtle()
rowpos = 1
pi = 3.14
xpos = 0
ypos = 0
angle = 0
pencolor = RGB(255, 0, 0)
penstatus = 1
End Sub


Sub pu()
 penstatus = 0
End Sub

Sub pd()
 penstatus = 1
End Sub

Sub rt(x)
  angle = angle - x
End Sub

Sub lt(x)
  rt -x
End Sub

Sub colorpoint(rowpos)
      ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).Points(rowpos).Format.Line.ForeColor.RGB = pencolor
End Sub

Sub movepos(newxpos, newypos)
  
  oldxpos = xpos
  oldypos = ypos  
  If penstatus = 1 Then
    If (rowpos = 1) Then
      ActiveSheet.Cells(rowpos, 1) = oldxpos
      ActiveSheet.Cells(rowpos, 2) = oldypos
      colorpoint rowpos
      rowpos = rowpos + 1
      ActiveSheet.Cells(rowpos, 1) = newxpos
      ActiveSheet.Cells(rowpos, 2) = newypos
      colorpoint rowpos
   ElseIf (ActiveSheet.Cells(rowpos, 1) = oldxpos) And (ActiveSheet.Cells(rowpos, 2) = oldypos) Then
      rowpos = rowpos + 1
      colorpoint rowpos
      ActiveSheet.Cells(rowpos, 1) = newxpos
      ActiveSheet.Cells(rowpos, 2) = newypos
      'rowpos = rowpos + 1
    Else
      rowpos = rowpos + 1
      colorpoint rowpos
      ActiveSheet.Cells(rowpos, 1) = Empty
      ActiveSheet.Cells(rowpos, 2) = Empty
      rowpos = rowpos + 1
      colorpoint rowpos
      ActiveSheet.Cells(rowpos, 1) = oldxpos
      ActiveSheet.Cells(rowpos, 2) = oldypos
      rowpos = rowpos + 1
      colorpoint rowpos
      ActiveSheet.Cells(rowpos, 1) = newxpos
      ActiveSheet.Cells(rowpos, 2) = newypos
  End If
  End If
   xpos = newxpos
   ypos = newypos
End Sub

Sub fd(x)
  newxpos = xpos + Cos(angle / 360 * 2 * pi) * x
  newypos = ypos + Sin(angle / 360 * 2 * pi) * x
  movepos newxpos, newypos
  
End Sub
Sub bk(x)
  fd -x
End Sub


sub test1
Call initturtle: For j = 1 To 6: For i = 1 To 20: lt 360 / 20: fd 20: Next i: rt 60: Next j
end sub

sub test2
Call initturtle: For i = 1 To 50: Call pu: movepos Rnd() * 50, Rnd() * 50: Call pd: movepos Rnd() * 50, Rnd() * 50: pc RGB(Rnd() * 255, Rnd() * 255, Rnd() * 255): Next i
end sub



If I do this from the immediate window:

pd : fd 20

for some reason I get an error (it doesn't like functions without parameters followed with a colon)

so I have to use

call pd: fd 20

to get them all on one line.

You can put for loops in the immediate window as well:

initturtle:for i = 1 to 180: call pu : rt 1 : fd 5: call pd : rt 1 : fd 5 : next i

I have yet to add a couple of functions, but this is proof of concept.

Oh yeah, to clear the graphics, just select column A and B and clear the contents.

I was thinking I could add the "turtle" by creating another data series in the chart.

It seems to work in libreoffice calc if I just comment out the line in colorpoint (but then you don't get the color you want):

Sub colorpoint(rowpos)
'ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).Points(rowpos).Format.Line.ForeColor.RGB = pencolor
End Sub

sub test1
Call initturtle: For j = 1 To 6: For i = 1 To 20: lt 360 / 20: fd 20: Next i: rt 60: Next j
end sub






sub test2
Call initturtle: For i = 1 To 50: Call pu: movepos Rnd() * 50, Rnd() * 50: Call pd: movepos Rnd() * 50, Rnd() * 50: pc RGB(Rnd() * 255, Rnd() * 255, Rnd() * 255): Next i
end sub