Plotting Circles in PICO-8

Click on the image below to start the program and see the excitement of trigonometry in action! Plotting circles in PICO-8.

Introduction

Recently I have been playing around with PICO-8. It’s a “fantasy console” that hearkens back to the NES days and includes a fully integrated development environment. This makes it a really convenient tool for learning game development or even just some graphics programming.

For this example, I wanted to learn how to program an object that orbits some origin point. In the context of game development, maybe it could be a shield or some kind of particle effect that orbits around the player’s position.

To do this, I had to learn about plotting circles in PICO-8. To my surprise, the math required is fairly minimal!

The math

You need the X and Y co-ordinate of an origin point, the radius (or distance you’d like the outer point to orbit at) and the angle of the point to plot in relation to the origin.

origin_x = 64
origin_y = 64
radius   = 10
angle    = 0

x = origin_x + radius * cos(angle/360)
y = origin_y + radius * sin(angle/360)

Using the math above, the first set of X and Y values returned would be (74,24). If we were to increment the angle by 5, the next result would be (74,62) when rounded.

Throw this into a loop that increments the angle each update, then plots the new point and job done!

Example program code

The below code is all you need to create a working example in PICO-8. PICO-8 calls the _UPDATE() function 30 times a second and the _DRAW() function 15, 30 or 60 times a second.

origin_x = 64
origin_y = 64
radius   = 10
angle    = 0
inc      = 5
x,y      = 0,0

function _update()
 angle += inc
 
 if (angle > 360) angle -= 360 //Keeps the angle between 0 and 360
 
 x = origin_x + radius * cos(angle/360)
 y = origin_y + radius * sin(angle/360)
end

function _draw()
 cls() //Clear the screen
 circfill(origin_x, origin_y, 3, 7) //Draw the inner circle
 circfill(x, y, 1, 7) //Draw the orbiting circle
end

What next?

My example program that I’ve embedded at the very start of this post is just an expanded version of the above code. I added in some controls for increasing and decreasing the radius, increasing and decreasing the angle increment (speed at which it moves) and holding the X key will pause it. Then I just plotted a few extra lines to help visualise the movement of the X and Y values.

I’m hoping to use this new knowledge to build some PICO-8 games with more interesting movement paths. I’m currently working on a Space Invaders style of game as a learning project and using similar math to enable enemies to move in more interesting patterns, as oppose to just moving straight down the screen.

Starting to wish I paid more attention in high school trigonometry classes!

Identify Locked AD Users via PowerShell

If you manage your Active Directory using only the ADUC GUI, it’s not particularly easy to identify all locked user accounts at once. Whilst you can do this by using queries within ADUC, I find it much more convenient to use PowerShell. In this short guide I will show you how to identify locked AD users via PowerShell.

The PowerShell cmdlets used in this post are from the ActiveDirectory module. This should already be installed on your Domain Controller, but can also be installed locally as part of Remote Server Administration Tools (RSAT).

If you have dabbled with the ActiveDirectory module before, your first instinct might be to use the Get-ADUser cmdlet to return all users and then filter the output to show only those with a LockedOut property equal to true.

Output of trying to identify Locked AD Users via PowerShell using Get-ADUser

As shown in the screenshot above, this approach doesn’t work. It produces an error message directing you to the Search-ADAccount cmdlet instead.

Running the Search-ADAccount cmdlet with the -LockedOut flag will return a list of all accounts that are currently locked. You can then pipe the output to the select cmdlet (an alias for Select-Object) to only include useful information.

Identifying Locked AD Users via PowerShell using Search-ADAccount

As shown in the redacted screenshot above, you can output the user’s name, samAccountName and PasswordExpired properties to get a more easily manageable overview. The PasswordExpired property can be useful if you are troubleshooting account lockouts.

If at this point you want to unlock one or more of the accounts, PowerShell can come to the rescue again! There is an Unlock-ADUser command which, when given a username (or list of them), will unlock the account from the command line.

So, in summary, if you want a quick list of all the currently locked out AD users, run the following:

Search-ADAccount -LockedOut | select -Property name, samAccountName, PasswordExpired

If you found that user “dean” was locked out, you could unlock the account with the following command:

Unlock-ADAccount dean

Hopefully this guide offers a quick insight into the power of PowerShell. It’s an incredibly useful tool that all Windows admins can benefit from.

mssql server service status screenshot

Microsoft SQL Server on Arch Linux

Part of my day job involves managing a system that runs on a MSSQL database. Because of that, I like to spend some time improving my knowledge of MSSQL and having a local installation is a great tool to play with. I recently installed Arch Linux on a Dell OptiPlex 3040 that I had lying around and decided to use it as a dev machine. This article covers how I installed Microsoft SQL Server on Arch Linux. I do this using AUR repositories.

Creating and Installing the Packages

First up, I create a location for my AUR repositories. Then I clone the GIT repositories that I need to get things up and running:

mkdir ~/aur
cd ~/aur
git clone https://aur.archlinux.org/mssql-server.git
git clone https://aur.archlinux.org/msodbcsql.git
git clone https://aur.archlinux.org/mssql-tools.git

mssql-server – this is for the main MS SQL Server installation
msodbcsql – this is for connecting to MS SQL Server
mssql-tools – these are the command line tools for interacting with MS SQL Server

Once the GIT repos have been cloned, it’s time to build the packages for installation using makepgk.

cd ~/aur/mssql-server
makepkg -sirc
cd ~/aur/msodbcsql
makepkg -sirc
cd ~/aur/mssql-tools
mkpkg -sirc

When running makepkg I use the following options:

-s – installs any missing dependencies using the package manager
-i – installs the package after it has been built
-r – removes any dependencies required by the build process that aren’t required afterwards
-c – cleans up any leftover work files or directories created during the build process

Now all three of the packages should be installed. The mssql-server service should also now be running and enabled to start automatically. You can check by running:

systemctl status mssql-server.service

The output should hopefully look something like this:

mssql server service status screenshot

If it’s showing as “inactive (dead)” you can easily start the service and enable it to run automatically:

systemctl enable --now mssql-server.service

You can then confirm that it’s running by using the command shown previously.

Initial Setup of SQL Server

At this point it’s time to run the setup utility for SQL Server. You can view the options for this tool by running:

/opt/mssql/bin/mssql-conf --help

There are a few useful options in here, like resetting the sa (database admin) password. However in this instance I just want to run the initial setup utility:

/opt/mssql/bin/mssql-conf setup

This tool will walk you through setting the admin password, choosing which edition of SQL Server to run, setting the language and accepting the licencing terms.

After running that setup utility you’re done! You should now have a working installation of Microsoft SQL Server running on Arch Linux. Easy-peasy!

Installing Azure Data Studio

Unfortunately Microsoft haven’t released a Linux version of SQL Server Management Studio. However, there is an alternative, albeit one that isn’t as feature packed as SSMS. That alternative is Azure Data Studio.

Azure Data Studio a MSSQL management tool that is built on top of the Microsoft Visual Studio Code editor. It’s perfectly fine for interacting with SQL Server but it does lack all the “wizards” that you can access from the menus in SSMS.

If you want to install Azure Data Studio there is an AUR repo for that too!

cd ~/aur
git clone https://aur.archlinux.org/azuredatastudio-bin.git
cd ~/aur/azuredatastudio-bin
makepkg -sirc

Once installed you should be able to launch Azure Data Studio, connect to your local SQL instance and start playing!

azure data studio screenshot

Mastodon