Posts: 2,830
Threads: 340
Joined: Apr 2022
Reputation:
246
(11-20-2024, 11:59 PM)fistfullofnails Wrote: Thanks everyone, but I still need to start with something simple, like a square, because I really don't understand what's happening.
Code: (Select All) FOR i = 1 to 3
PRINT "***"
NEXT
The above would print 3 lines for you of "***", making your square.
***
***
***
Posts: 4,123
Threads: 184
Joined: Apr 2022
Reputation:
242
11-21-2024, 02:30 PM
(This post was last modified: 11-21-2024, 04:09 PM by bplus.)
@fistfullofnails You can "Print patterns" on Screen 0, the default screen (when Screen is not called in code), simply by changing colors and printing a space = " ". A space ONLY prints the background color AND can be used to clear text on a line instead of CLS so you can erase parts of screen without erasing everything.
There are 8 background colors in Screen 0 and here is a horizontal striped using color changes and printing spaces:
Code: (Select All) For row = 1 To 25 ' the default = screen 0 has 25 rows to put characters you type
For col = 1 To 80 ' the default = screen 0 has 80 columns to put characters you type
' you can color screen 0 simple by specifying a backcolor and printing a space
Color , row Mod 8 ' a mod b divides a by b and return remainder a number between 0 & b-1 inclusive
Locate row, col: Print " "; ' print a space at each location
Next
Next
simply change
Color ,row, Mod 8
to
Color , col, Mod 8
and the horizontal stripes become vertical!
Code: (Select All) For row = 1 To 25 ' the default = screen 0 has 25 rows to put characters you type
For col = 1 To 80 ' the default = screen 0 has 80 columns to put characters you type
' you can color screen 0 simple by specifying a backcolor and printing a space
Color , col Mod 8 ' a mod b divides a by b and return remainder a number between 0 & b-1 inclusive
Locate row, col: Print " "; ' print a space at each location
Next
Next
b = b + ...
Posts: 4,123
Threads: 184
Joined: Apr 2022
Reputation:
242
11-21-2024, 02:45 PM
(This post was last modified: 11-21-2024, 03:47 PM by bplus.)
OK @fistfullofnails to print a true square on default screen 0
Here is red square printed with background color 4 into middle of screen:
Code: (Select All) ' a character cell is 8 pixels wide X 16 pixels high
rowStart = 11: rowEnd = 15 ' 5 vertical rows 5 * 16 = 80 pixels
colStart = 36: colEnd = 45 ' 10 columns 10 * 8 = 80 pixels
' 80 pixels X 80- pixels = true square in screen 0
' pick a color 0 to 7 not 0 = default black background say 4
backcolor = 4 ' try different colors here 4 is red
' color forecolor, backcolor '<<< command to control color
Color , backcolor ' set color to 4, now anywhere we print backcolor is red = 4
' color our square on default black background
For row = rowStart To rowEnd
For col = colStart To colEnd
Locate row, col: Print " "; ' print a space at each location of the square
Next
Next
Sleep
b = b + ...
Posts: 4,123
Threads: 184
Joined: Apr 2022
Reputation:
242
bplus riffing on the last again:
Code: (Select All) rowStart = 11: rowEnd = 15 ' 5 vertical rows 5 * 16 = 80 pixels
colStart = 36: colEnd = 45 ' 10 columns 10 * 8 = 80 pixels
' 80 pixels X 8- pixels = true square in screen 0
' pick a color 0 to 7 not 0 say
sqH = 5 ' 1 to 25 rows
sqW = 2 * sqH ' for a square width = 2*height = twice as many columns
sqLeft = 36 ' left most column
sqTop = 11 ' top most row
backcolor = 4 ' try different colors here 4 is red
GoSub printSquare
Locate 22, 23: Print "zzz... press any for random squares"
Sleep
' riffing again
' pick a random square height max is 25
Do
sqH = Int(Rnd * 25) + 1 ' 1 to 25 rows
sqW = 2 * sqH ' for a square width = 2*height = twice as many columns
sqLeft = Int(Rnd * (80 - sqW)) + 1 ' left most column
sqTop = Int(Rnd * (25 - sqH)) + 1 ' top most row
backcolor = (backcolor + 1) Mod 8 ' 0 to 7 colors (including black as "eraser"
GoSub printSquare
_Limit 2
Loop Until _KeyDown(27) ' until escape key is pressewd
End
printSquare:
Color , backcolor
For row = sqTop To sqTop + sqH - 1
For col = sqLeft To sqLeft + sqW - 1
Locate row, col: Print " "; ' print a space at each location of the square
Next
Next
Return
b = b + ...
Posts: 15
Threads: 3
Joined: Dec 2022
Reputation:
0
OK, I can make some sense of this. Thanks for the explanations as well.
Posts: 15
Threads: 3
Joined: Dec 2022
Reputation:
0
(11-20-2024, 03:21 PM)SMcNeill Wrote: Aren't you guys making this all too complicated for such a simple task and question?
Code: (Select All)
For i = 0 To 20
Print Space$(40 - i); String$(i * 2 + 1, "*")
Next
Three simple lines of code. That's all you need. Nothing fancy. Nothing complex. Just a FOR statement, a PRINT statement, and a NEXT.
I get this and can back engineer it for the most part to figure out what's going on. So I notice if I place anything greater than a single character in place of the asterik, the String$ command seems to only print out the very first character. For example if I entered "Car" in place of "*", then it would just print out the C character every time, instead of the word Car. Am I correct on that?
Posts: 2,445
Threads: 247
Joined: Apr 2022
Reputation:
125
12-27-2024, 01:10 AM
(This post was last modified: 12-27-2024, 01:18 AM by Pete.)
You are. String$() is engineered to only give one character and if you try an include more it just spits out the first character. There have been a few times I wished we had on keyword that could handle multiple characters.
Oh, and x-mas tree code...
Code: (Select All)
Locate 7
a$ = "*"
For i = 1 To 14
If i > 10 Then a$ = "*"
Locate , _Width \ 2 - Len(a$) \ 2 + 1
Print a$
a$ = a$ + "**"
Next
Pete
Shoot first and shoot people who ask questions, later.
Posts: 15
Threads: 3
Joined: Dec 2022
Reputation:
0
Posts: 2,445
Threads: 247
Joined: Apr 2022
Reputation:
125
12-27-2024, 02:44 AM
(This post was last modified: 12-27-2024, 02:49 AM by Pete.)
@fistfullofnails
You want animation with that?
Code: (Select All)
Width 60, 24
_Font 16
_ScreenMove _Middle
_Title "'Tis The Season"
train$ = Space$(_Width) + "[oo]-[oo]-[Oo>"
Palette 7, 63
Color 2, 7: Cls
msg$ = "Merry Christmas"
Locate 4, _Width \ 2 - Len(msg$) \ 2 + 1
Color 4, 7: Print msg$: Color 2
Locate 7
a$ = "*"
For i = 1 To 14
If i > 10 Then a$ = "*": Color 0
Locate , _Width \ 2 - Len(a$) \ 2 + 1
Print a$
a$ = a$ + "**"
Next
y = CsrLin - 1
Color 2: Locate y, 1: Print String$(_Width, 177);
_Delay 2: x = 5: z = Timer
Do
Locate 7: a$ = "*"
For i = 1 To 10
Locate , _Width \ 2 - Len(a$) \ 2 + 1
Color 2: Print a$;
For j = 1 To Len(a$)
If Rnd * 20 > 17 Then
Locate , _Width \ 2 - Len(a$) \ 2 + j
Color 12 + 16: Print "*";
End If
Next
Print
a$ = a$ + "**"
Next
If Abs(z - Timer) > x Then
z = Timer
If t = Len(train$) + 1 Then
t = 1: x = 3
Else
Sound 300, .05
t = t + 1: x = .05
Locate y - 1, 1: Color 0: Print Mid$(train$, Len(train$) - t, _Width);
If t >= _Width / 2 + Len(_Trim$(train$)) Then Color 0: Locate , _Width \ 2 + 1: Print "*";
End If
End If
Loop Until InKey$ = Chr$(27)
System
Pete
Shoot first and shoot people who ask questions, later.
Posts: 384
Threads: 34
Joined: Jul 2022
Reputation:
30
01-02-2025, 05:51 PM
(This post was last modified: 01-02-2025, 05:55 PM by TempodiBasic.)
(11-21-2024, 02:22 AM)SMcNeill Wrote: (11-20-2024, 11:59 PM)fistfullofnails Wrote: Thanks everyone, but I still need to start with something simple, like a square, because I really don't understand what's happening.
Code: (Select All) FOR i = 1 to 3
PRINT "***"
NEXT
The above would print 3 lines for you of "***", making your square.
***
***
***
Happy new year friends!
Sorry Steve you have missed the goal of the task of fist_full_of_nails..
he likes a square of 4 * for 3 rows...
so
Code: (Select All)
print "***"
is incorrect.
And that the Befana brings us other than black coal!
la Befana
images
@Pete
I love it, so nice and in movement!
|