Author Topic: Binary ASCII fractal  (Read 1476 times)

Galileo

  • Guest
Binary ASCII fractal
« on: April 21, 2018, 10:31:34 AM »
A short but eye-catching program.

Code: [Select]
// Adapted to Yabasic by Galileo, 04/2018
// I no remember the origin of this code

open window 512,512
backcolor 0,0,0
clear window
w=512 : h=512
sx=-2.2 : sy=-1.7 : sw=3.4 : sh=3.4

do
x = int(ran(h/10)) * 11
y = int(ran(w/10)) * 11
gx=x/w*sw+sx
gy=y/h*sh+sy
zx=gx
zy=gy
for c=0 to 255
cl  = c
nzx = zx*zx - zy*zy + gx
zy  = 2*zx*zy+gy
zx  = nzx
if zx*zx + zy*zy > 4 then
   cl = c
   break
end if
next c
r = cl     
g = cl*32
b = cl*64
if g > 255 g = mod(g,255)
if b > 255 b = mod(b,255)
color 0, 0, 0
fill rectangle x, y+2, x+5, y+13
color r,g,b
bit$ = chr$(ran()+48.5)
text x, y, bit$, "lt"
loop

ZXDunny

  • Guest
Re: Binary ASCII fractal
« Reply #1 on: April 21, 2018, 06:44:15 PM »
Didn't we do this one a while back?

Anyway, SpecBAS:

Code: [Select]
1paper 0:cls:FOR y=-29TO 30;x=-10TO 89:m,r=0:FOR k=0TO 224:j=r^2-m^2-2+x/25,m=2*r*m+y/25,r=j,l=k,k=IIF(j^2+m^2>11,225,k):NEXT k:PRINT INK l;"01"(1+rnd*2);:NEXT x;y

B+

  • Guest
Re: Binary ASCII fractal
« Reply #2 on: April 21, 2018, 09:54:07 PM »
Code: [Select]
'quick test.bas for SmallBASIC 0.12.12 by bplus 2018-04-21"
'yes, we didi this before, I have a file dated 2016-09-21 for asc mandelbrot
'here is a mod of that

for y = -35 to 35
  for x = -10 to 89
    m = 0 : r = 0
    for k = 1 to 113
      j = r^2 - m^2 - 2 + x/25
      m = 2*r*m + y/25
      r = j
      l = k & 15
      if j^2 + m^2 > 11 then k=114
    next
    color 16-l, 0
    text (x + 10)*8, (y + 35)*8, 8, rnd*2\1
  next
next
pause

sub text(x, y, size, s) ' a sub to make translating to SmallBASIC from SdlBasic easier
  'when this sub is used text size is altered for the rest of the run
  local l
  l.w = window() : l.w.setfont(size, "pt", 0, 0)
  at x, y : ? s
  showpage
end

Edit: oops did not need ? = print between two loops using sub text.
« Last Edit: April 22, 2018, 12:18:33 PM by B+ »