LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-06-2019, 03:44 PM   #1
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 2,239

Rep: Reputation: 474Reputation: 474Reputation: 474Reputation: 474Reputation: 474
The power of bash: Plotting.


I'm going to keep these simple so that the scripts aren't too long.
If you want a graph, center line or voltage numbers, then put them in. Using awk for these.

Examples:
Code:
#! /usr/bin/env bash

#Plotting a sinusoidal wave.
#Terminal need to be at least 80 char wide/30 lines tall.

a=0; b=0
step=10
hplot=3
cline=12
amp=11
PI=3.14159

clear
printf "%45s %s\n %s\n" "Sine wave plot"

while [ $a -le 720 ]; do

    vplot=$(awk "BEGIN{ printf \"%.12f\", \
                ((sin($a*($PI/180))*$amp)+$cline)}")
                
    vplot=$((24 - ${vplot/.*}))
    
    printf "\x1B["$vplot";"$hplot"f*"
    printf "\x1B[26;1fPhase angle for wave is "$b" degrees."
    
    sleep 0.2
    a=$((a + step))
    b=$((b + 10))
    
    if [ $b -gt 360 ]; then
        b=10
    fi
    
    hplot=$((hplot + 1))
done
echo -e "\n"
Code:
#! /usr/bin/env bash

#Plotting 2 sinusoidal waves 180 deg out of phase.
#Terminal need to be at least 80 char wide/30 lines tall.

a=0
step=10
hplot=3
cline=12
amp=11
PI=3.14159

clear
printf "%45s %s\n %s\n" "Sine wave plot"

while [ $a -le 720 ]; do

    vplot1=$(awk "BEGIN{ printf \"%.12f\", \
                ((sin($a*($PI/180))*$amp)+$cline)}")
                
    vplot2=$(awk "BEGIN{ printf \"%.12f\", \
                ((sin($a*($PI/-180))*$amp)+$cline)}")
                
    vplot1=$((24 - ${vplot1/.*}))
    vplot2=$((24 - ${vplot2/.*}))
    
    tput bold
    tput setaf 1
    printf "\x1B["$vplot1";"$hplot"fx"
    tput setaf 4
    printf "\x1B["$vplot2";"$hplot"fx"
    tput sgr0
    printf "\x1B[26;1fPlot for "$a" degrees."
    
    sleep 0.1
    a=$((a + step))
    hplot=$((hplot + 1))
    
done
echo -e "\n"
Code:
#! /usr/bin/env bash

#Plotting 3 sinusoidal waves 90 deg out of phase.
#Terminal need to be at least 80 char wide/30 lines tall.

a=0
b=90
c=180
step=10
hplot=3
cline=12
amp=11
PI=3.14159

clear
printf "%45s %s\n %s\n" "Sine wave plot"

while [ $a -le 720 ]; do

    vplot1=$(awk "BEGIN{ printf \"%.12f\", \
                ((sin($a*($PI/180))*$amp)+$cline)}")
                
    vplot2=$(awk "BEGIN{ printf \"%.12f\", \
                ((sin($b*($PI/180))*$amp)+$cline)}")
                
    vplot3=$(awk "BEGIN{ printf \"%.12f\", \
                ((sin($c*($PI/180))*$amp)+$cline)}")
                
    vplot1=$((24 - ${vplot1/.*}))
    vplot2=$((24 - ${vplot2/.*}))
    vplot3=$((24 - ${vplot3/.*}))
    
    tput bold
    tput setaf 1
    printf "\x1B["$vplot1";"$hplot"fO"
    tput setaf 4
    printf "\x1B["$vplot2";"$hplot"fO"
    tput setaf 2
    printf "\x1B["$vplot3";"$hplot"fO"
    tput sgr0
    printf "\x1B[26;1fPlot for "$a" degrees."
    
    sleep 0.1
    a=$((a + step))
    b=$((b + step))
    c=$((c + step))
    hplot=$((hplot + 1))
    
done
echo -e "\n"
 
Old 08-07-2019, 11:15 AM   #2
wagscat123
Member
 
Registered: Jan 2009
Location: Maryland-Pennsylvania border, USA
Distribution: openSUSE 15.1, Tumbleweed, Ubuntu 19.04, Mageia 6, Fedora 30, Debian 10, and Linux Mint 19.1
Posts: 777
Blog Entries: 11

Rep: Reputation: 109Reputation: 109
Well done. For science nerd who lives this in Python and IDL, and worships the Tux, having cosines swirling around on Yakuake is awesome

Last edited by wagscat123; 08-07-2019 at 11:17 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Power failure" at bash prompt - But no loss of power or UPS etc chrisphysics Linux - Kernel 4 08-05-2013 03:49 AM
[SOLVED] What plotting software should I use for Plotting ASCII data in Ubuntu? msbstar Linux - Newbie 7 04-12-2011 10:30 PM
C function for plotting a pixel in Linux ( like putpixel of bgi)? chandan Programming 4 01-23-2004 09:16 AM
looking for windows like GUI based data plotting tool samik Linux - Software 1 10-27-2003 01:57 AM
redhat 7.1 plotting programs suqu Red Hat 2 10-16-2003 12:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration