Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASCII cube
#1
ASCII cube

ASCII theme + cube theme = ASCII cube theme

Given: enter the sides of the cube and build a pseudo 3d

I think 7 layers are possible

Code: (Select All)
'12345678x12345x KUB.bas
'********x=====x 1
'*******/*****/1 2
'******/*****/*2 2
'*****/*****/**3 2
'****/*****/***X 3
'***/*****/***1  4
'**/*****/***2   4
'*/*****/***3    4
'1234567***4     5
'1*****1**5      6
'2*****2*6       6
'3*****37        6
'1234567         7
KUB.bas program works if a b c is successfully selected

Does anyone have any experience in creating a parametric ASCII cube?

Code: (Select All)
a = 7: b = 5: c = 8 ' KUB.bas
For i = 1 To c: Print "*";: Next
Print "x";: For i = 1 To a - 2: Print "=";: Next: Print "x 1"

For i = 1 To c - 0 - b:
    For j = c - i To 1 Step -1: Print ".";: Next:

    Print "/";: For k = 1 To a - 2: Print "-";: Next: Print "/";
    For n = 1 To i - 1: Print "o";: Next: Print "| 2"
Next

For j = c - i To 1 Step -1: Print ".";: Next:
Print "/";: For k = 1 To a - 2: Print "-";: Next: Print "/";
For n = 1 To i - 1: Print "o";: Next: Print "x 3"

For m = i To 2 Step -1
    For j = m - 1 To 1 Step -1: Print ".";: Next:
    Print "/";: For k = 1 To a - 2: Print "-";: Next: Print "/";
    For n = 1 To i - 1: Print "o";: Next: Print "/ 4"
Next

Print "x";: For i = 1 To a - 2: Print "=";: Next: Print "x";
For n = 1 To i - 3: Print "o";: Next: Print "/ 5"

For p = 1 To b - 2: Print "|";
    For k = 1 To a - 2: Print "-";: Next: Print "|";
    For n = 1 To b - p - 2: Print "o";: Next: Print "/ 6"
Next

Print "x";: For i = 1 To a - 2: Print "=";: Next: Print "x 7"


Code: (Select All)
**********x=====x 1
........./-----/| 2
......../-----/o| 2
......./-----/oo| 2
....../-----/ooo| 2
...../-----/ooox 3
..../-----/ooo/ 4
.../-----/ooo/ 4
../-----/ooo/ 4
./-----/ooo/ 4
x=====xooo/ 5
|-----|oo/ 6
|-----|o/ 6
|-----|/ 6
x=====x 7

https://jdoodle.com/ia/PXs and press Execute

Variant to shift diagonally from top right to left down
in cycle has not yet been developed
and there are apparently 3 layers of cycles
and possibly a shift to right down
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic

Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
Reply
#2
Code: (Select All)
Randomize Timer ' KUBIK.bas
'........T=====T 1
'......./-----/| 2
'....../-----/|| 2
'...../-----/||| 2
'..../-----/|||J 3
'.../-----/|||/ 4
'../-----/|||/ 4
'./-----/|||/ 4
'T=====T|||/ 4
'|*****|||/ 4
'|*****||/ 4
'|*****|/ 4
'L=====J 5
a = Int(Rnd*13)+3: b = Int(Rnd*7)+3: c = Int(Rnd*13)+3
Locate 1, 1: For i = 1 To c: Print ".";: Next
Print "T";: For i = 1 To a-2: Print "=";: Next: Print "T 1"

For i = 1 To b-2:
    For j = 1 To a+c-2: Print ".";: Next: Print "|| 2"
Next

For i = 1 To a+c-2: Print ".";: Next: Print "|J 3"

For i = 1 To c-1: Locate i+1, 1
    For j = c-i To 1 Step -1: Print ".";: Next: Print "/";
    For k = 1 To a-2: Print "-";: Next: Print "/"

    For m = 1 To b-2
        For n = 1 To c+a-1-i: Print "|";: Next: Print
    Next: _Delay .5

    For p = 1 To a+c-1-i: Print "|";: Next: Print "/ 4"
Next

Locate i+1, 1: Print "T";:
For i = 1 To a-2: Print "=";: Next: Print "T"
For i = 1 To b-2: Print "|";
    For j = 1 To a-2: Print "*";: Next: Print "|"
Next

Print "L";: For i = 1 To a-2: Print "=";: Next: Print "J 5"

who will simplify without locate?

UPDATE: c = Int(Rnd*13)+3


.bas   main.bas (Size: 1.19 KB / Downloads: 55)

Vizual Run https://qbjs.org/?mode=auto&src=https://...p?aid=2387


.bas   Kube11.bas (Size: 1.31 KB / Downloads: 53) bplus 2023-11-05

Vizual Run https://qbjs.org/?mode=auto&src=https://...p?aid=2390
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic

Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
Reply
#3
Error when c = 0 an extra layer gets drawn every other time b + c lines are printed when c = 0 an extra line is printed:
   
b = b + ...
Reply
#4
Here are some real Ascii Cubes:
Code: (Select All)
_Title "Ansii Cubes" 'bplus 2023-11-06

Screen _NewImage(1200, 700, 32)
_ScreenMove 50, 30
Randomize Timer
Do
    Color &HFF000000, 0
    Cls
    crates = Int(Rnd * 7) + 1
    For i = 1 To crates
        rc~& = _RGB32(Rnd * 125 + 55, Rnd * 125 + 55, Rnd * 125 + 55)
        rx = Rnd * _Width \ 8
        ry = Rnd * _Height \ 16
        rw = Int(Rnd * 31) + 5
        rh = Int(Rnd * 21) + 5
        rd = Int(Rnd * 11) + 5
        cube rx, ry, rw, rh, rd, rc~&
    Next
    Sleep
Loop Until _KeyDown(27)

Sub cube (x, y, w, h, deep, bcolor~&)
    'x, y in char cells is top RIGHT Corner
    ' so width w goes LEFT, height h goes down, deep goes up and right
    Color , bcolor~& ' front side
    char$ = Chr$(65 + Int(Rnd * 26))
    For yy = y To y + h
        For xx = x To x - w Step -1
            If xx * 8 > 0 And xx * 8 < _Width Then
                If yy * 16 > 0 And yy * 16 < _Height Then
                    Locate yy, xx: Print char$;
                End If
            End If
        Next
    Next
    Color , bcolor~& + _RGB32(25, 25, 25) ' right side
    For xx = x To x + deep
        For yy = y To y + h
            If (xx + 1) * 8 > 0 And (xx + 1) * 8 < _Width Then
                If (yy - i) * 16 > 0 And yy * 16 < _Height Then
                    Locate yy - i, xx + 1: Print "|";
                End If
            End If
        Next
        i = i + 1
    Next
    Color , bcolor~& + _RGB32(50, 50, 50)
    i = 0
    For yy = y - 1 To y - deep Step -1 ' topside
        For xx = x + 1 To x - w Step -1
            If (xx + i) * 8 > 0 And (xx + i) * 8 < _Width Then
                If yy * 16 > 0 And yy * 16 < _Height Then
                    Locate yy, xx + i: Print "-";
                End If
            End If
        Next
        i = i + 1
    Next
End Sub


Attached Files Image(s)
   
b = b + ...
Reply
#5
^
|
Cool program, but I think Danilin was presenting this as a challenge. Cannot use ```LOCATE```. This must work even in many 8-bit and limited BASICs.

I was going to use a 2D array of bytes and treat it like a graphics screen instead of ```LOCATE``` but with some BASICs offered on computers with 4KB RAM or less that's cheating. Anyway, I'm going by the first post of this topic.

I came up with something but requires specific values for ```a```, ```b``` and ```c```. I made a few adjustments to the routine. But sometimes the cube is weirdly drawn.

Code: (Select All)

'by Danilin QB64 Phoenix forums
'changed a bit so it accepts parameters
'the middle one is the only one that draws correctly
' according to my modifications
$CONSOLE:ONLY
danilincube 7, 5, 8
danilincube 10, 6, 12
danilincube 12, 10, 14
system

sub danilincube (a as integer, b as integer, c as integer)
dim as integer i, j, k, m, n, p
For i = 1 To c: Print "*";: Next
Print "x";: For i = 1 To a - 2: Print "=";: Next: Print "x 1"

For i = 1 To c - b - 1
For j = c - i To 1 Step -1: Print ".";: Next:

Print "/";: For k = 1 To a - 2: Print "-";: Next: Print "/";
For n = 1 To i - 1: Print "o";: Next: Print "| 2"
Next

For j = c - i To 1 Step -1: Print ".";: Next:
Print "/";: For k = 1 To a - 2: Print "-";: Next: Print "/";
For n = 1 To i - 1: Print "o";: Next: Print "x 3"

For m = i To 2 Step -1
For j = m - 1 To 1 Step -1: Print ".";: Next:
Print "/";: For k = 1 To a - 2: Print "-";: Next: Print "/";
For n = 1 To i - 1: Print "o";: Next: Print "/ 4"
Next

Print "x";: For i = 1 To a - 2: Print "=";: Next: Print "x";
For n = 1 To i - 4: Print "o";: Next: Print "/ 5"

For p = 1 To b - 1: Print "|";
For k = 1 To a - 2: Print "-";: Next: Print "|";
For n = 1 To b - p - 1: Print "o";: Next: Print "/ 6"
Next

Print "x";: For i = 1 To a - 2: Print "=";: Next: Print "x 7"
end sub
Reply
#6
No Locate like this? Only 1 For loop too!
Code: (Select All)
'........T=====T 1
'......./-----/| 2
'....../-----/|| 2
'...../-----/||| 2
'..../-----/|||J 3
'.../-----/|||/ 4
'../-----/|||/ 4
'./-----/|||/ 4
'T=====T|||/ 4
'|*****|||/ 4
'|*****||/ 4
'|*****|/ 4
'L=====J 5
_Title "Kube"
Randomize Timer ' kube.bas  'bplus 2023-11-05
Do
    Cls
    a = Int(Rnd * 13) + 3: b = Int(Rnd * 7) + 3: c = Int(Rnd * 13) + 3
    If c < b Then c = b
    '  a = 7: b = 5: c = 8 ' <<<<<  test drawing above OK good!
    d = b + c: w = a - 2: h = b - 2: rw = 0
    For i = 1 To d
        If i > c Then
            If rw > d - i Then rw = d - i
        End If
        If i = 1 Then ' case 1
            Print String$(c - i + 1, ".") + "T" + String$(w, "=") + "T 1"; Tab(40); i
        ElseIf i < b Then ' case 2
            Print String$(c - i + 1, ".") + "/" + String$(w, "-") + "/" + String$(rw, "|") + " 2"; Tab(40); i
        ElseIf i = b Then ' case 3
            Print String$(c - i + 1, ".") + "/" + String$(w, "-") + "/" + String$(rw, "|") + "J 3"; Tab(40); i
        ElseIf i <= c Then
            Print String$(c - i + 1, ".") + "/" + String$(w, "-") + "/" + String$(rw, "|") + "/" + " 4"; Tab(40); i
        ElseIf i = c + 1 Then ' T bar
            Print "T" + String$(a - 2, "=") + "T" + String$(rw, "|") + "/ 4"; Tab(40); i
        ElseIf i > c + 1 And i <> d Then
            Print "|" + String$(a - 2, "*") + String$(rw, "|") + "/ 4"; Tab(40); i
        ElseIf i = d Then
            rw = 0
            Print "L" + String$(a - 2, "=") + "J 5"; Tab(40); i
        End If
        rw = rw + 1
        If rw > h Then rw = h
        If d - i + 1 < rw And i > c Then rw = d - i
    Next
    Print
    Print " a", " b", " c"
    Print a, b, c
    Sleep
Loop

b = b + ...
Reply
#7
"Cool program,"

I'll tell you what is cool to me about Ascii Cubes, it is first time I did this for a color:
Color , bcolor~& + _RGB32(25, 25, 25) ' right side to make lighter
Color , bcolor~& + _RGB32(50, 50, 50) ' top side to make lighter still!
b = b + ...
Reply




Users browsing this thread: 2 Guest(s)