Author Topic: ASCII squared pattern demo  (Read 3169 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
ASCII squared pattern demo
« on: May 07, 2021, 05:23:44 pm »
Hi QB64 community
here a little demo of ASCII pattern art
the program prints a pattern of simmetric image in a square stamp.
Code: QB64: [Select]
  1. Const True = -1, False = 0, It = 10, En = 20
  2. Dim iPlay, inpNum, iTotc, iLang, a As String
  3. iLang = False
  4. iPlay = True
  5. While iLang = False
  6.     Locate 10, 28
  7.     Print "Choose language... IT or EN "
  8.     a = UCase$(InKey$)
  9.     If Len(a) > 0 Then
  10.         If Asc(a) = 69 Then iLang = En
  11.         If Asc(a) = 73 Then iLang = It
  12.     End If
  13.  
  14. While iPlay = True
  15.     guida iLang
  16.     Input inpNum
  17.     If inpNum > 0 And inpNum <= 10 Then
  18.         iTotc = (2 * inpNum) + (2 * (inpNum - 1))
  19.         ' met… superiore
  20.         For iCount = 1 To inpNum Step 1
  21.             StampaSpazio (iCount - 1) ' spazi iniziali
  22.             StampaNum (iCount) ' cifra in *
  23.             StampaSpazio (iTotc - 2 * (iCount - 1) - (2 * iCount)) 'spazi intermedi
  24.             StampaNum (iCount) 'cifra in *
  25.             StampaSpazio (iCount - 1) 'spazi finali
  26.             Print
  27.         Next
  28.  
  29.         For iCount = inpNum To 0 Step -1
  30.             StampaSpazio (iCount - 1) 'spazi all'inizio
  31.             StampaNum (iCount) ' cifra in *
  32.             StampaSpazio (iTotc - 2 * (iCount - 1) - (2 * iCount)) 'spazi intermedi
  33.             StampaNum (iCount) ' cifra in *
  34.             StampaSpazio (iCount - 1)
  35.             Print
  36.         Next
  37.     End If
  38.     If inpNum = 0 Then iPlay = False
  39.  
  40. Sub guida (iL As Integer)
  41.     If iL = It Then
  42.         Print " Questo programma disegna un pattern quadrato in base al numero immesso"
  43.         Print " prego inserire un numero da 1 a 10 e 0 per terminare"
  44.     ElseIf iL = En Then
  45.         Print " This program draws a pattern squared on the number of input taken"
  46.         Print " please insert a number from 1 to 10 and 0 to quit program "
  47.     End If
  48.  
  49. Sub StampaSpazio (iChar)
  50.     Dim iCount As Integer
  51.     For iCount = 0 To iChar Step 1
  52.         Print " ";
  53.     Next
  54.  
  55. Sub StampaNum (iChar)
  56.     Dim iCount As Integer
  57.     For iCount = 1 To iChar Step 1
  58.         Print "*";
  59.     Next

Thanks to take a look.
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: ASCII squared pattern demo
« Reply #1 on: May 07, 2021, 07:02:15 pm »
That's pretty good for ASCII :)

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: ASCII squared pattern demo
« Reply #2 on: May 09, 2021, 12:06:40 pm »
@bplus
we must wait for Pete's judgement, the King of ASCII. ;)

This my code is a procedural solution about the task but I think that it can be solved using a math model for calculations to drive the output.

It needs more research.
Programming isn't difficult, only it's  consuming time and coffee