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"
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
11-05-2023, 04:05 PM (This post was last modified: 11-07-2023, 10:20 AM by DANILIN.)
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"
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
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
^
|
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
11-07-2023, 12:49 AM (This post was last modified: 11-07-2023, 01:31 AM by bplus.)
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
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!