Skip to content
oonap0ooPublic

About

Basic programming using BASIC-256

Topics

Resources

Stars

21 stars

Watchers

0 watching

Forks

Latest commit

 

History

33 Commits

Folders and files

Repository files navigation

BASIC-256

Basic programming using BASIC-256

From the website:

'BASIC-256 is a beginner-friendly programming language that makes learning to code fun with graphics, math, and immediate results.'

https://basic256.org/

There were several significant updates made available recently.

Use the online documentation:

https://doc.basic256.org/

First test of BASIC-256

Using the graphics output and measuring the execution time.

The code: test256.kbs

The IDE of BASIC-256 with the program:

test256_list.png

The output saved to PNG by the program:

test256.png

Julia Fractal

Drawing a Julia fractal. The code takes about 21s to complete. It calculates half of the fractal and plots the other half from the same data using symmetry.

The code: julia.kbs

The output saved to PNG by the program: julia256.png

Minsky Circle Algorithm

Drawing a circle using only addition, subtraction and integer division.

The main loop:

x=1024: y=0 # initial values
do
    x = x - y\32 # using integer division
    y = y + x\16 # new value of x has to be used
    x = x - y\32 # 3rd step to reduce phase error
	plot(x,y)
until x=1024 and y=0 # until back to initial values

The integer division by powers of 2 could be done using bit shift to the right also.

Using info from: "Drawing Circles · Hrvoje's Blog"

The code: minsky.kbs

minsky.png

Double Pendulum

Attempting to simulate a double pendulum using BASIC-256.

Using equations found at: https://www.physics.usyd.edu.au/~wheat/dpend_html/

The code: double_pendulum.kbs

A GIF screen recording of the animation:

double_pendulum.gif

Longer video on Youtube

Barnsley Fern

This algorithm generates an image of a fern.

Using information from the wikipedia article

It applies 4 possible transformations on the coordinates of a point x,y. The probabilities of these four being choosen differ for transformation.

The following code is iterated many times, each iteration one out of four tranformations are applied and one point is plotted.

r = rand() # value between 0 and 1
begin case # choose 1 out of 4 possible transforms
case r < 0.01 # probability 1%
	xn = 0.0
	y = 0.16 * y
case r < 0.86 # probability 85%
	xn = 0.85 * x + 0.04 * y
	y = -0.04 * x + 0.85 * y + 1.6
case r < 0.93 # probability 7%
	xn = 0.2 * x - 0.26 * y
	y = 0.23 * x + 0.22 * y + 1.6
else # probability 7%
	xn = -0.15 * x + 0.28 * y
	y = 0.26 * x + 0.24 * y + 0.44
end case
x = xn
call plotpoint(x,y,xscale,yscale,hw,h)

The code: barnsley_fern2.kbs

The generated image:

barnsley_fern2.png

Non-periodic

Made using the new BASIC-256 version 2.1.0

While exploring Javascript with P5.JS, I came op with these simple animations.

After learning online that a function like

sin(pi*x)+sin(4.5*x) 

is not periodic I made this animation which uses this function for the x and y coordinates of points but evaluated at different regions.

I ported them to BASIC-256 to give the new incarnation of this BASIC version a try. I had forgotten a lot and the online help was very useful.

The code:

non-periodic.kbs non-periodic_polar.kbs

Still images from the animations:

non-periodic.png non-periodic_polar.png

Swirl and swirl 3D

Also ported from earlier versions in javascript P5.JS. These animations generate a visual effect based on the equations of a sphere using spherical coordinates.

x = R sin(u) cos(v)
y = R sin(u) sin(v)
z = R cos(u)

The code:

swirl2.kbs swirl3D.kbs

A still images from the animations (the window containing the graphical output can also be detached from the IDE as a seperate window and enlarged)

swirl2.png swirl3D.png

Torus

This version puts the points on the surface of a torus.

X = (2R + Rcos(v))cos(u)
Y = (2R + Rcos(v))sin(u)
Z = R sin(v)

The 3D torus is plotted on the 2D image as

xplot = X
yplot = .7Y + .7Z

Where the factor .7 approximates 1/sqrt(2)

The code:

torus.kbs

A still from the animation:

(the window containing the graphical output can also be detached from the IDE as a seperate window and enlarged)

torus.png

About

Basic programming using BASIC-256

Topics

Resources

Stars

21 stars

Watchers

0 watching

Forks

Contributors