You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


In a doNUT SHELL
05-03-2017, 11:32 PM (This post was last modified: 05-11-2017 12:56 AM by Waltersmind.)
Post: #1
 (Print Post)
In a doNUT SHELL
Got it!

Code Snippet: [Select]
' In a doNUT SHELL.bas SmallBASIC 0.12.9 (B+=MGA) 2017-05-03

const cx = xmax/2  'center screen
const cy = ymax/2
const tw = txtw("W") 'text char width
const th = txth("Q") 'text char height

sub midInk(r1, g1, b1, r2, g2, b2, fr)
 color rgb(r1+(r2-r1)*fr, g1+(g2-g1)*fr, b1+(b2-b1)*fr)
end

tload("In a doNUT SHELL.bas", f, 1)
lenF = len(f)
'lenF = 800  'don't want to get much more than 800 chars

tArea = tw * th * lenF / 1.95  'text area in pixels
'had to divide by 2 for some reason then fudge

'tArea = pi * (2/3 * r)^2
'9/4 * tArea/pi = r^2
r = sqr(9/4 * tArea/pi)

'divide screen into character cells and see if in or out of donut
' if in, print a character from this source code until run out
' then send XO's
idx = 0
for y = 0 to ymax step th
 for x = 0 to xmax step tw
   d = ((x - cx) ^ 2 + (y - cy) ^ 2) ^.5
   if r/3 < d and d < r then
     idx +=1
     at x, y
     midink(255, 255, 255, 80, 40, 20, abs(2/3*r - d)/(.335*r))
     if idx < lenF then
       ? mid(f, idx, 1);
     else
       this = iff(idx mod 2, "X", "O") : ? this;
     fi
   fi
 next
next
print
pause  

   
Find all posts by this user
Like Post
The following 2 users Like bplus's post:
Anthony.R.Brown, Waltersmind (Admin)
05-03-2017, 11:56 PM (This post was last modified: 05-03-2017 11:56 PM by bplus.)
Post: #2
 (Print Post)
RE: In a doNUT SHELL
Like your choice of expresso Big Grin
Find all posts by this user
Like Post
05-04-2017, 12:31 PM (This post was last modified: 05-11-2017 12:56 AM by Waltersmind.)
Post: #3
 (Print Post)
RE: In a doNUT SHELL
Aha! It often pays to translate code into different dialects. Here are improvements I discovered while preparing a Just Basic post:

Code Snippet: [Select]
' In a doNUT SHELL.bas SmallBASIC 0.12.9 (B+=MGA) 2017-05-04
' translating to JB, I discovered an improvemnet!

const cx = xmax/2  'center screen
const cy = ymax/2
const tw = txtw("W") 'text char width
const th = txth("Q") 'text char height

sub midInk(r1, g1, b1, r2, g2, b2, fr)
 fc = rgb(r1+(r2-r1)*(1-fr), g1+(g2-g1)*(1-fr), b1+(b2-b1)*(1-fr))
 bc = rgb(r1+(r2-r1)*fr, g1+(g2-g1)*fr, b1+(b2-b1)*fr)
 color fc, bc
end

open "In a doNUT SHELL.bas" for input as #1
while eof(1) = 0
   input #1, fline
   f = f + fline + ":"
wend
close #1

lenF = len(f)
'lenF = 800  'don't want to get much more than 800 chars

tArea = tw * th * lenF / 1.95  'text area in pixels
'had to divide by 2 for some reason then fudge

'tArea = pi * (2/3 * r)^2
'9/4 * tArea/pi = r^2
r = sqr(9/4 * tArea/pi)

'divide screen into character cells and see if in or out of donut
' if in, print a character from this source code until run out
' then send XO's
idx = 0
for y = 0 to ymax step th
 for x = 0 to xmax step tw
   d = ((x - cx) ^ 2 + (y - cy) ^ 2) ^.5
   if r/3 < d and d < r then
     idx +=1
     at x, y
     midink(255, 255, 255, 80, 40, 20, abs(2/3*r - d)/(.335*r))
     if idx < lenF then
       ? mid(f, idx, 1);
     else
       this = iff(idx mod 2, "X", "O") : ? this;
     fi
   fi
 next
next
print
pause  

But how could it get any better?, you ask. (see attachment)

   
Find all posts by this user
Like Post
The following 1 user Likes bplus's post:
Anthony.R.Brown
05-04-2017, 04:23 PM
Post: #4
 (Print Post)
RE: In a doNUT SHELL
I think the first is a Plain doNUT and the Second is Covered in Chocolate! Smile 


Anthony.
Find all posts by this user
Like Post
The following 1 user Likes Anthony.R.Brown's post:
bplus
05-04-2017, 04:38 PM (This post was last modified: 05-11-2017 12:55 AM by Waltersmind.)
Post: #5
 (Print Post)
RE: In a doNUT SHELL
figosdev, for you a special treat, candy sprinkles!

Code Snippet: [Select]
' In a doNUT SHELL.bas SmallBASIC 0.12.9 (B+=MGA) 2017-05-04
' translating to JB, I discovered an improvement!
' now with candy sprinkles!

const cx = xmax/2  
const cy = ymax/2
const tw = txtw("W")
const th = txth("Q")
def rand(lo, hi) = (rnd * (hi - lo + 1)) \ 1 + lo
def rclr = rgb(rand(64, 255), rand(64, 255), rand(64, 255))
sub midInk(r1, g1, b1, r2, g2, b2, fr, tf)
 if tf then
   fc = rClr()
 else
   fc = rgb(r1+(r2-r1)*(1-fr), g1+(g2-g1)*(1-fr), b1+(b2-b1)*(1-fr))
 fi
 bc = rgb(r1+(r2-r1)*fr, g1+(g2-g1)*fr, b1+(b2-b1)*fr)
 color fc, bc
end
open "In a doNUT SHELL.bas" for input as #1
while eof(1) = 0
   input #1, fline
   f = f + fline + ":"
wend
close #1
lenF = len(f)
tArea = tw * th * lenF / 2  
r = sqr(9/4 * tArea/pi)
for y = 0 to ymax
 for x = 0 to xmax
   d = ((x - cx) ^ 2 + (y - cy) ^ 2) ^.5
   if r/3 < d +20 and d - 20< r then
     midink(180, 90, 55, 80, 40, 20, 1 - abs(2/3*r - d)/(.335*r), 0)
     pset x+5, y+10
   fi
 next
next
idx = 0
for y = 0 to ymax step th
 for x = 0 to xmax step tw
   d = ((x - cx) ^ 2 + (y - cy) ^ 2) ^.5
   if r/3 < d and d < r then
     idx +=1
     at x, y
     midink(180, 90, 55, 80, 40, 20, abs(2/3*r - d)/(.335*r), 1)
     if idx < lenF then
       ? mid(f, idx, 1);
     else
       this = iff(idx mod 2, "X", "O") : ? this;
     fi
   fi
 next
next
print
pause  

   
Find all posts by this user
Like Post
05-08-2017, 08:08 AM
Post: #6
 (Print Post)
RE: In a doNUT SHELL
Not a manly thing to say, but everyone should keep in touch with their inner child and their source of wonder.
Find all posts by this user
Like Post
05-08-2017, 03:27 PM
Post: #7
 (Print Post)
RE: In a doNUT SHELL
When a Man loses their inner Child they lose their Innocence! Wink


Anthony.
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Othello
QB64 Member Project - Splatter
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Connect Four
QB64 Member Project - Algeria Weather
QB64 Member Project - Inside Moves
QB64 Member Project - Amazon
QB64 Member Project - Input
QB64 Member Project - Blokus
QB64 Member Project - Bowditch curve
QB64 Member Project - Color Rotating Text
QB64 Member Project - Spiro Roses
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Point Blank
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Color Triangles
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Foursight
QB64 Member Project - Rubix's Magic
QB64 Member Project - Martin Fractals version two
QB64 Member Project - ARB Checkers
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Basic Dithering
QB64 Member Project - Domain
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Isolation
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Score 4
QB64 Member Project - Rotating Background
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Qubic
QB64 Member Project - 9 Board
QB64 Member Project - Dakapo
QB64 Member Project - Swirl
QB64 Member Project - Overboard
QB64 Member Project - Dreamy Clock
QB64 Member Project - Sabotage
QB64 Member Project - Touche
QB64 Member Project - Line Thickness
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Kings Court
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Quarto
QB64 Member Project - Pivot version two
QB64 Member Project - Martin Fractals version one
QB64 Member Project - Exit
QB64 Member Project - Pivet version one