Announcement

Collapse
No announcement yet.

Sine wave in console or CC Graphics window

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sine wave in console or CC Graphics window

    Can anyone out there help me with information or sample code in how to draw a Sine Wave in either a CC console window or in the consol itself using ascii characters like *, +, or #

  • #2
    maybe to simple??

    Code:
    ' PBCC 5
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
    
     LOCAL i AS LONG
     LOCAL k AS SINGLE
    
       FOR i=-40 TO 40
          k=(SIN(i/10)*10)+14
          LOCATE k, i+40
          PRINT "#"
       NEXT i
       WAITKEY$
    
    END FUNCTION
    BASIC shampoo - DO:LATHER:RINSE:LOOP UNTIL CLEAN <>0

    Comment


    • #3
      CHANGE PARAMETERS TO POSITION PROPERLY

      Code:
       
      'PBCC 5 GRAPHIC WINDOW
       
      #COMPILE EXE
      #CONSOLE OFF
      DEFLNG a-z
      FUNCTION PBMAIN () AS LONG
       DESKTOP GET CLIENT TO PixW,PixH
       x1=0
       y1=0
       x2=PixW
       y2=PixH
       a%=200
       xc%=300
       yc%=500
       DESKTOP GET SIZE TO WinX,WinY
       GRAPHIC WINDOW caption$,x1,y1,x2,y2 TO hwin
       GRAPHIC ATTACH hwin,0,REDRAW
       GRAPHIC SET LOC -2,0
       GRAPHIC SCALE (x1,y2)-(x2,y1)
       GRAPHIC WIDTH 1
       FOR hh%=90 TO 450
        fi!=hh%*0.0174533
        x!=xc%+hh%
        y!=yc%+a%*COS(fi!)
        IF hh% MOD 5 = 0 THEN
         GRAPHIC SET POS(x!,y!)
         GRAPHIC PRINT "+"
        END IF
        'GRAPHIC LINE (x!,y!)-(x!+1,y!+1),%RED
       NEXT
       GRAPHIC REDRAW
       GRAPHIC WAITKEY$ TO HK$
      END FUNCTION

      Code:
       
      'PBCC 4 and Graphic Window
       
      #COMPILE EXE
      DEFLNG a-z
      FUNCTION PBMAIN () AS LONG
       DESKTOP GET CLIENT TO PixW,PixH
       x1=0
       y1=0
       x2=PixW
       y2=PixH
       a%=200
       xc%=100
       yc%=500
       caption$="Sine Wave"
       DESKTOP GET SIZE TO WinX,WinY
       GRAPHIC WINDOW caption$,x1,y1,x2,y2 TO hwin
       GRAPHIC ATTACH hwin,0,REDRAW
       GRAPHIC SET LOC -2,0
       GRAPHIC SCALE (x1,y2)-(x2,y1)
       GRAPHIC SET POS (100,100)
       GRAPHIC FONT "Arial",20,1
       GRAPHIC PRINT "Close the window to end"
       GRAPHIC WIDTH 1
       GRAPHIC FONT "Arial",5,1
       FOR hh%=90 TO 450
        fi!=hh%*0.0174533
        x!=xc%+2*hh%
        y!=yc%+a%*COS(fi!)
        IF hh% MOD 2 = 0 THEN
         GRAPHIC SET POS(x!,y!)
         GRAPHIC PRINT "*"
        END IF
        GRAPHIC LINE(280,yc%-3)-(1000,yc%-3)
        'GRAPHIC LINE (x!,y!)-(x!+1,y!+1),%RED  'uncomment to see a line plot
       NEXT
       GRAPHIC REDRAW
       WAITKEY$
      END FUNCTION
      Last edited by Manuel Valdes; 4 May 2009, 07:53 PM.

      Comment


      • #4
        Thanks for the Info. I only asked it because I'm a newbie in PBCC graphics. But then we probably all are because CC Graphics has only been around since CC4 I think . My basic programming during the CC4 period was mainly confined to FreeBASIC under Linux and I have since returned to Windows when Vista came out and the first program I updated since returning to Windows was PB CC 5. I also indend to upgrade my regular Windows Compiler from version 7 to version 9 and update my PB Forms designer when I get the cash to it.

        Comment

        Working...
        X