Sign in to follow this  
Followers 0
Achilles

Make graph paper images

1 post in this topic

I actually made this for my Calculus teacher because she's pretty cool. In her tests she cuts out graph paper from a notebook and glues it on the test paper and then photocopies it... so I decided I would make this to see if it can make her job easier.

The one bug I was talking about is when you have a 10x10 (which is default) grid and you click export. The Y axis is a pixel too thin. Also, if the grid is 10x10 and you move the Y axis over to the left you will have blank spot in the picture when it is exported.

I realize this won't be useful to... hmm.. probably anybody, but it could help people learn.

#include <GuiConstants.au3>
#include <A3LGDIPlus.au3>
#include <A3LScreenCap.au3>

Opt('GUIOnEventMode', 1) 

$lengthX = 150
$lengthY = 150

$xAxis = 5 
$yAxis = 5

$lblXAxis = -1 
$lblYAxis = -1
$cmbComboX = -1
$cmbComboY = -1

_CreateGUI()

While 1 
    Sleep(1000) 
WEnd 

Func _CreateGUI() 
    GuiCreate('Graph Paper', $lengthX + 65, $lengthY + 150) 
        GuiSetOnEvent($GUI_EVENT_CLOSE, '_Exit') 

    GuiCtrlCreateLabel('', 10, 10, $lengthX, $lengthY) 
        GuiCtrlSetState(-1, $GUI_DISABLE)
        GuiCtrlSetBkColor(-1, 0xFFFFFF) 

    For $index = 10 to $lengthX Step 15
        GuiCtrlCreateLabel('', $index, 10, 1, $lengthY) 
            GuiCtrlSetBkColor(-1, 0xBABCCC) 
    Next 

    For $index = 10 to $lengthY Step 15
        GuiCtrlCreateLabel('', 10, $index, $lengthX, 1) 
            GuiCtrlSetBkColor(-1, 0xBABCCC) 
    Next 

    $lblXAxis = GuiCtrlCreateLabel('', $xAxis * 15 + 10, 10, 2, $lengthY) 
        GuiCtrlSetBkColor(-1, 0)    
        
    $lblYAxis = GuiCtrlCreateLabel('', 10, $yAxis * 15 + 10, $lengthX, 2) 
        GuiCtrlSetBkColor(-1, 0)

    GuiCtrlCreateButton('<', $lengthX + 15, 10, 20, $lengthY) 
        If $lengthX <= (15 * 7) then 
            GuiCtrlSetState(-1, $GUI_DISABLE)
        Else
            GuiCtrlSetOnEvent(-1, '_RemoveX') 
        EndIf   
        
    GuiCtrlCreateButton('>', $lengthX + 40, 10, 20, $lengthY) 
        GuiCtrlSetOnEvent(-1, '_AddX') 
        
    GuiCtrlCreateButton('Remove', 10, $lengthY + 15, $lengthX, 20)
        If $lengthY <= (15 * 7) then 
            GuiCtrlSetState(-1, $GUI_DISABLE)
        Else
            GuiCtrlSetOnEvent(-1, '_RemoveY') 
        EndIf
        
    GuiCtrlCreateButton('Add', 10, $lengthY + 40, $lengthX, 20)
        GuiCtrlSetOnEvent(-1, '_AddY') 

    GuiCtrlCreateLabel('X axis:', 10, $lengthY + 68, 50, 20)
    $cmbComboX = GuiCtrlCreateCombo('', 60, $lengthY + 65, 100, 20, $CBS_DROPDOWNLIST) 
        $data = ''

        For $index = 0 to ($lengthX - Mod($lengthX, 15)) / 15
            $data &= $index & '|' 
        Next 
        $data = StringTrimRight($data, 1) 
        
        GuiCtrlSetData($cmbComboX, $data, $xAxis) 

    GuiCtrlCreateLabel('Y axis:', 10, $lengthY + 98, 50, 20)
    $cmbComboY = GuiCtrlCreateCombo('', 60, $lengthY + 95, 100, 20, $CBS_DROPDOWNLIST) 
        $data = ''

        For $index = 0 to ($lengthY - Mod($lengthY, 15)) / 15
            $data &= $index & '|' 
        Next 
        $data = StringTrimRight($data, 1) 
        
        GuiCtrlSetData($cmbComboY, $data, $yAxis) 

    GuiCtrlCreateButton('Export', 10, $lengthY + 122, $lengthX, 22) 
        GuiCtrlSetOnEvent(-1, '_Export')

    GUIRegisterMsg($WM_COMMAND, 'MY_WM_COMMAND')
    GuiSetState()   
EndFunc

Func _Export() 
    $title = 'Graph ' & ($lengthX - Mod($lengthX, 15)) / 15 & 'x' & ($lengthY - Mod($lengthY, 15)) / 15 
    
    If FileExists($title & '.jpg') then
        $count = 0
        
        Do
            $count += 1
            $title = 'Graph (' & $count & ') ' & ($lengthX - Mod($lengthX, 15)) / 15 & 'x' & ($lengthY - Mod($lengthY, 15)) / 15
        Until Not FileExists($title & '.jpg')
    EndIf
        
    WinSetState('Graph Paper', '', @SW_SHOW)
    _ScreenCap_CaptureWnd($title & '.jpg', WinGetHandle('Graph Paper'), 13, 34, $lengthX + 14, $lengthY + 35)

EndFunc

Func _AddX() 
    $lengthX += 15
    
    GuiDelete() 
    
    _CreateGUI()
EndFunc 

Func _AddY() 
    $lengthY += 15
    
    GuiDelete() 
    
    _CreateGUI()
EndFunc 

Func _RemoveX() 
    $lengthX -= 15
    
    GuiDelete() 
    
    _CreateGUI()    
EndFunc 


Func _RemoveY() 
    $lengthY -= 15
    
    GuiDelete() 
    
    _CreateGUI()    
EndFunc

Func _Exit()
    Exit 
EndFunc 

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nID = BitAnd($wParam, 0x0000FFFF)

    If $nID = $cmbComboX then
        If GuiCtrlRead($cmbComboX) <> $xAxis then 
            GuiCtrlDelete($lblXAxis) 
            
            $xAxis = GuiCtrlRead($cmbComboX)
            
            $lblXAxis = GuiCtrlCreateLabel('', $xAxis * 15 + 10, 10, 2, $lengthY) 
                GuiCtrlSetBkColor(-1, 0)    
        EndIf

        Return 0
    ElseIf $nID = $cmbComboY then 
        If GuiCtrlRead($cmbComboY) <> $yAxis then 
            GuiCtrlDelete($lblYAxis)
            $yAxis = GuiCtrlRead($cmbComboY)
            
            $lblYAxis = GuiCtrlCreateLabel('', 10, $yAxis * 15 + 10, $lengthX, 2) 
                GuiCtrlSetBkColor(-1, 0)            
        EndIf

        Return 0        
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0