Programming Microsoft Paint

If you look at that pic above, you would not believe that it’s MS paint, but yes, i plotted these sines, cosines and circle graphs using normal Ms Paint

The trick is : control your mouse using Python. simple . Here’s the base code :

# ############################################################## #
#                  - ABOUT THE PROGRAM -
# Program name : dirty ms paint plotting trial program
# Program description : changes program background on radio button
#                       click
# Author : Abdur-Rahmaan Janhangeer
# Date : 27th of March 2017
# License : MIT with emphasis :
# You are free to modify and distribute the program provided that
# attribution is  C L E A R L Y  made.
# Python version : Python 3.4
# ############################################################# #
# ############################################################# #
#                      - INDEX -
# 1 import statement/s
# 2 sleep
# 3 infinite loop
# 4 variables and model
# 5 drawer
# ############################################################# #
# ############################################################# #
#                   - CONVENTIONS USED -
# --- naming ---
# rx - radius x
# dx - change in x
# ############################################################# #
# ############################################################# #
#                  - NOTES AND WARNINGS -
# ---warning---
# 
# ---notes---
# one shot comments used
# ############################################################# #

import math
import pyautogui
time.sleep(5)
pyautogui.FAILSAFE = True
try:
    pyautogui.click(200,400)
    distance=50 #path covered
    while True:
        ry=40 #vary that normally stands for radius.
              #as useful when drawing ellipse
        #rx=40

        x=1
        #y=1

        distance +=100
        x +=20
        #y +=10
        #rx+=10
        #ry+=10
        #dx =math.sin(distance)*rx
        dy =math.cos(distance)*ry    
        # view after model
        pyautogui.dragRel( x, dy, duration =0.2) #replace x with dx for circle
        
except KeyboardInterrupt:
    print("\nDone")

 

Now if the program does not respond, press ctrl+alt+delete on windows

The picture is a collection of different graphs.

Install pyautogui

I installed it by pip setup.py install after downloading

see automate the boring stuffs with python for more.

Advertisements