AutoHotkey Community

It is currently May 27th, 2012, 11:00 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: February 20th, 2009, 7:39 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
(A bit offtopic)

I'm also making a function grapher using EasyBMP.
Image
Here's my source so far:

Code:
#Include *i EasyBMP.ahk
#NoEnv

; Settings part
graphname := " y = sin x"
sizew := 360
sizeh := 300
ScalarX := 360
ScalarY := 1
use_antialias := true
func_to_call := "sin"

rc := EasyBMP_Init() ; initializes EasyBMP
If !rc
{
   MsgBox, 16,, Error initializing EasyBMP!
   ExitApp
}

TRIG_INIT()
hBMP := BMP_Create()
BMP_Set(hBMP, "size", sizew, sizeh)
BMP_Set(hBMP, "bitdepth", 32)
BMP_FillBlock(hBMP, "w" sizew " h" sizeh)
Geometry_DrawLine(hBMP, "x" (sizew//2) " y0", "x" (sizew//2) " y" (sizeh-1), "red", false)
Geometry_DrawLine(hBMP, "x0 y" (sizeh//2), "x" (sizew-1) " y" (sizeh//2), "red", false)
OldPoint := ""

FactX := sizew/ScalarX
FactY := sizeh/(ScalarY*2)
Progress, A R0-1000, Drawing graph..., Graphing
Loop, %ScalarX%
{
   percent := Floor((A_Index*1000) / ScalarX)
   Progress, %percent%
   
   num := (A_Index-1)-(ScalarX/2)
   
   ; Do here your calculations
   val := %func_to_call%(num)
   
   ; Program continue
   val *= FactY
   val += sizeh/2
   If((val >= sizeh) || (val < 0))
      Continue
   xpos := Floor((A_Index-1) * FactX)
   ypos := (sizeh-1)-val+1
   If OldPoint =
      BMP_SetPixel(hBMP, xpos, ypos, "black")
   Else{
      Geometry_DrawLine(hBMP, OldPoint, "x" xpos " y" ypos, "black", use_antialias)
   }
   OldPoint := "x" xpos " y" ypos
}
Progress, Off
Text_DrawString(hBMP, "x5 y5", graphname, 16, "green")

Gui, Color, 0xFFFFFF
Gui, Add, Pic, x0 y0 vMyGraph
BMP_GetInfo(hBMP, w, h)
Win32_SetStaticBMP(hBMP, "MyGraph")
Gui, Show, w%w% h%h%, Graph
Return

GuiContextMenu:
MsgBox, 36, Graph, Do you want to save the graph as a file?
IfMsgBox, No
   Return
FileSelectFile, f, S,, Select file to save, Bitmap files (*.bmp)
If f =
   Return
SplitPath, f,, fD,, fN
f = %fD%\%fN%.bmp
SplashTextOn, 100, 100, Graph, Saving...
BMP_SaveFile(hBMP, f)
SplashTextOff
return

GuiClose:
BMP_Delete(hBMP)
EasyBMP_DeInit()
ExitApp

; Trigonometric functions - in degrees.
; They replace the original trigonometric functions,
; which use radians.

TRIG_INIT(){
   global DEG2RAD
   DEG2RAD := (4*ATan(1))/180
}

sin(x){
   global DEG2RAD
   Transform, o, Sin, % x * DEG2RAD
   Return o
}

cos(x){
   global DEG2RAD
   Transform, o, Cos, % x * DEG2RAD
   Return o
}

tan(x){
   global DEG2RAD
   Transform, o, Tan, % x * DEG2RAD
   Return o
}

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2009, 7:55 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
@fincs

Nice!
Might I suggest starting a separate thread?
I believe this deserves it.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2009, 7:59 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
SoggyDog wrote:
@fincs

Nice!
Might I suggest starting your own thread (aside from this one or your EasyBMP threads)?


I will include the program in the next EasyBMP DLL for AutoHotkey version.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 2:46 pm 
Offline

Joined: January 13th, 2009, 8:15 am
Posts: 25
SoggyDog wrote:
alarian wrote:
T_T

I have a problem...
How can I update data series when the SetDataSeries function requires an array?
No arrays in AHK

There are lots of ways around this;
Try olegbl's AHKArray [Real Array - One Variable].


I don't see how this changes the fact that I can't enter an array into the DllCall... These arrays won't return any value with array(0) or array(4) or anything like that....

So the problem remains.

How can I change the data of a Series and redraw it without recreating the whole region and chart and all?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 2:51 pm 
Offline

Joined: January 13th, 2009, 8:15 am
Posts: 25
alarian wrote:
T_T
How can I change the data of a Series and redraw it without recreating the whole region and chart and all?

AHA! I found a workaround...
First change the data in the .csv-file...
Code:
RedrawChart( GuiID, ListOne ) { ;;This function doesn't change anything visually
   result := DllCall("rmchart.dll\RMC_SETSERIESDATAFILE" 
         ,UInt,1000          ; ctrl id of the chart window
         ,UInt,1             ; Region
         ,UInt,1             ; Series
         ,Str,"test.csv")   ; CSVFile
          ; Draw the chart
   result := DllCall("rmchart.dll\RMC_DRAW"
         ,UInt,1000 )   ; CtrlId
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2009, 5:30 pm 
Offline

Joined: August 14th, 2007, 12:11 pm
Posts: 86
can the resulted image be saved?
I mean without any aditional dlls


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: iDrug and 58 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group