First, the shell.
Equilateral triangle
[[email protected] my_script]# sh ff.shnum:6 * *** ***** ******* ********************[[email protected] my_script]# cat ff.sh#!/bin/bash############################################################## ############ file name: ff.sh# author: huxianyong# mail: [email protected]# created time: 2017 June 07 Wednesday 16 41 minutes, 14 seconds ################################## ###################################### #read -p "num:" numfor ((i=1;i<= $num; i++)) Dofor ((j= $num (j>i;j--)) doecho -e " \c" Donefor ((l=1;l<=i;l++)) doecho -e "*\c" Donefor ((r=1;r <i;r++)) doecho -e "*\c" Doneechodone or read -p "num:" numfor ((i=1;i<= $num; i++)) do for ((j= $num; j>i;j--)) do echo -e " \c " done for ((l=1;l<=2*i-1;l++)) do echo -e "*\c" done echodone
[[Email protected] my_script]# SH ff.shnum:6 * * * * * * * * * * * * * * * * * * * * * * * * *[[email protected] My_scrip t]# Cat ff.sh#!/bin/bash########################################################################## File Name:ff.sh # author:huxianyong# Mail: [email protected]# Created time:2017 June 07 Wednesday 16:41 14 seconds ################################## ###################################### #read-P "num:" Numfor ((i=1;i<= $num; i++)) Dofor ((j= $num; j>i;j--)) Doecho-e "\c" Donefor ((l=1;l<=i;l++)) doecho-e "* \c" Doneechodone
Isosceles Right Triangle
[[Email protected] my_script]# sh ff.shnum:5*************************[[email protected] my_script]# cat ff.sh#!/bin/ bash########################################################################## File name:ff.sh# Author:huxianyong # Mail: [email protected]# Created time:2017 June 07 Wednesday 16:41 14 seconds #################################################### #################### #read-P "num:" Numfor ((i=1;i<= $num; i++)) Do for ((l=1;l<=2*i-1;l++)) do echo-e "*\c "Done Echodone
Rhombic
for ((i = 1; i < 12; i++)) do if [[ $i -le 6 ]]; then for (( j = $ ((12-i)); j > i; j--)) do echo -n " "; done for ((m = 1; m <= $ (2*i-1); m++)) do #echo -n "$i " echo -n "* " done echo&nBSP; "" elif [[ $i -gt 6 ]]; then n=$ ((12-i)) for ((j = $ ((12-n)); j > n; j--)) do echo -n " "; done for ((m = 1; m <= $ (2*n-1); m++)) do #echo -n "$i " echo -n "* " done echo "" fi done
The other shapes are similar.
Python print Diamond
* * * * * * * * * * * * * * * * *s = ' * ' For I in range (1, 8, 2): Print ((s*i). Center (7)) for I in Reversed (range (1, 6, 2) ): Print ((s*i). Center (7))
This article is from the "Forand" blog, make sure to keep this source http://853056088.blog.51cto.com/12966870/1933243
Write all kinds of graphics in shell or Python