TI/Skrypty z zajęć/3

Z Brain-wiki
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar  3 11:23:24 2020

@author: tgub
"""

'''
a       a
 a     a
  a   a
   a a
    a
   a a
  a   a
 a     a
a       a
'''

#funkcja rysujaca krzyz
def rysunek(n):

    #gorna czesc krzyza
    for i in range(n-1):
        print(i*' '+'a'+(2*n-3-2*i)*' '+'a')
    
    #srodek krzyza
    print((n-1)*' '+'a')
    
    #dolna czesc krzyza
    for i in range(n-2,-1,-1):
        print(i*' '+'a'+(2*n-3-2*i)*' '+'a')


def rysunek_one_line(n):
    for i in list(range(n))+list(range(n-2,-1,-1)):
        print(i*' '+'a'+(2*n-3-2*i)*' '+(' ' if i==(n-1) else 'a'))

def rysunek_one_line2(n):
    for i in range(2*n-1):
        print((n-1-abs(i-n+1))*' '+'a'+(2*n-3-2*(n-1-abs(i-n+1)))*' '+(' ' if (n-1-abs(i-n+1))==(n-1) else 'a'))

#rysunek_one_line2(4)

'''
r=3
 *** 
*****
*****
*****
 ***
'''

def kolko(r):
    n=int(round(r))
    for i in list(range(n-1,0,-1)) + list(range(n)):
        x = int(round((r*r-i*i)**0.5))
        print((n-x)*' '+'*' * (2*x-1))
#kolko(5)

    
        
def plot(fun, xmin, xmax, ymin, ymax):
    
    a = [[' ' for x in range(xmax-xmin+1)] for x in range(ymax-ymin+1)]
    for x in range(xmin,xmax+1):
        y = int(round(fun(x)))
        if (y>=ymin) and (y<=ymax):
            a[y-ymin][x-xmin] = '*'
    for x in a[::-1]:
        print('|'+''.join(x))
    print('+'+'-'*(xmax-xmin+1))
import math

plot(lambda x : 5*math.sin(x/3), 0,20,-5,5)
        

'''przykład
plot(lambda x : x, 0,10,5,10)

10 |     *
   |    *
   |   *
   |  *
   | *
5  |*
   +------
    5    10

'''

#a=[[' ' for x in range(3)] for x in range(3)]
#a[2][2]='*'
#a[1][1]='*'
#a[0][0]='*'
#
#
#pokaz(a)