Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Yabasic => Topic started by: bikemadness on November 01, 2021

Title: Fractions Of An Inch
Post by: bikemadness on November 01, 2021
Divided into 128 segments and their millimeter lengths.

I once did this on paper with a calculator.

Code: [Select]
denominator=128
dim loop(denominator)
dim topnum(denominator)
dim count(denominator)
dim botnum(denominator)

for a=1 to denominator
topnum(a)=a
count(a)=1
botnum(a)=denominator
next a

open window 640,512
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
col=1
gap=0

for a=1 to denominator
loop(a)=topnum(a)/2

if frac(topnum(a)/2)=0 then
count(a)=count(a)*2
topnum(a)=loop(a)
else
col=col+1

if topnum(a)<10 then
align=10
elseif topnum(a)>99 then
align=-10
else
align=0
endif

if botnum(a)/count(a)<=8 then
setrgb 1,256,0,0
else
setrgb 1,256,256,256
endif

text 10+gap+align,15*col,str$(topnum(a))+"/"+str$(botnum(a)/count(a))
endif

text 80+gap,15*col,str$((a/denominator)*25.4,"##.##")

if col>32 then
gap=gap+160
col=1
endif

next a

until (1=0)