PotterHarry Posted February 17, 2015 Report Share Posted February 17, 2015 Hi, I just wonder if someone could give me some pointers here, please. I'm trying to automate the drawing of lines on an art program. Straight lines are easy enough, but I've graduated to curves now, and I'm wondering how you would approach this? I will need to specify a coordinate, and then increment its position by small amounts to make a curve. There will most likely be an obvious way to do this that I'm quite likely to overlook .... Thank you !!! Quote Link to comment Share on other sites More sharing options...
acantor Posted February 17, 2015 Report Share Posted February 17, 2015 What shapes do you want to draw? If the curves can be described mathematically, this task might be doable with Macro Express. For example, y - ax^2 + bx + c is the equaltion for a parabola. When I need ellipses, I use the circle tool in PowerPoint.... Quote Link to comment Share on other sites More sharing options...
rberq Posted February 18, 2015 Report Share Posted February 18, 2015 How do you do the straight lines? I'm guessing you use the straight-line feature of the art program -- you have ME position the mouse to the beginning point, press and hold the mouse button, move the mouse to the end point of the line, and release the button -- or something akin to that technique. The hard part of that would be translating your x-y coordinates to pixel locations so ME can move the mouse properly. Same thing should be possible with the free hand drawing feature of the art program. As Alan says, have ME calculate the x-y coordinates of successive points on the curve, translate those to pixel locations, and move the mouse from pixel to pixel. Easier said than done, but I don't know how else you would do it except to feed appropriate parameters to the art program for whatever standard shapes the program supports. Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted February 26, 2015 Author Report Share Posted February 26, 2015 Thanks! rberq, this is how I draw lines of variable length. The formula suggestion Alan is very interesting .. <VARIABLE SET INTEGER Option="\x05" Destination="%X%" Minimum="%A%" Maximum="%B%"/><VARIABLE SET INTEGER Option="\x05" Destination="%Y%" Minimum=" %F%" Maximum="%G%"/><MOUSE SPEED Delay="250"/><MOUSE MOVE Option="\x01" X="%X%" Y="%Y%" _PROMPT="0x000A"/><MOUSE SPEED Delay="0"/><DELAY Flags="\x02" Time="100"/><MOUSE LEFT CLICK/><DELAY Flags="\x02" Time="1000"/><MOUSE LEFT BUTTON DOWN/><DELAY Flags="\x02" Time="100"/><VARIABLE SET INTEGER Option="\x05" Destination="%N10%" Minimum="20" Maximum="180"/><VARIABLE SET INTEGER Option="\x05" Destination="%N11%" Minimum="20" Maximum="180"/><MOUSE SPEED Delay="250"/><MOUSE MOVE Option="\x03" X="%N10%" Y="%N11%" _PROMPT="0x000A"/><MOUSE SPEED Delay="0"/><DELAY Flags="\x02" Time="100"/><MOUSE MOVE Option="\x03" X="0" Y="150" _PROMPT="0x000A"/><DELAY Flags="\x02" Time="200"/><MOUSE LEFT BUTTON UP/> Sorry I can't work out how to export my script as a text file, but basically its move to a random position, mouse down, move to a second random position, mouse up !! I'll have a play with the formula suggestion, but i'm going to have to increment the positions gradually to see a curve. Maybe an array? Thanks again ...... Quote Link to comment Share on other sites More sharing options...
terrypin Posted February 27, 2015 Report Share Posted February 27, 2015 Hi, More information will be needed to be confident of a suggested approach. First, are you trying to create something like this? I produced that with the following substantially modified version of your macro. // Set initial values of A, B, F and G. These define the rectangle enclosing the random start points for the straight line segments, using screen co-ordinates.Variable Set Integer %A% to 20Variable Set Integer %B% to 590Variable Set Integer %F% to 55Variable Set Integer %G% to 435// Draw 100 lines of random length (within specified limits) from randomly chosen start points within that rectangle.// NOTE 1: This may take the end point of a line beyond the specified painting rectangle, or even outside the target application.)// NOTE 2: Because the increments are all positive numbers, all lines will have a rightward and downward slant.Window Activate: - IrfanView // Activate the target window in a suitably configured graphics editing or painting application.Wait for Window Title: - IrfanViewMouse Speed: 1 millisecondsRepeat Start (Repeat 10 times)// Select a random start point. Variable Set Integer %X% to a random value between %A% and %B% Variable Set Integer %Y% to a random value between %F% and %G% Mouse Move: %X%, %Y% Relative to Screen Mouse Left Button Down Delay: 100 milliseconds Variable Set Integer %N10% to a random value between 10 and 100 Variable Set Integer %N11% to a random value between 5 and 80 Mouse Move: %N10%, %N11% Relative to Last Position Delay: 100 milliseconds Mouse Left Button UpEnd Repeat <COMMENT Value="Set initial values of A, B, F and G. These define the rectangle enclosing the random start points for the straight line segments, using screen co-ordinates."/> <VARIABLE SET INTEGER Option="\x00" Destination="%A%" Value="20"/> <VARIABLE SET INTEGER Option="\x00" Destination="%B%" Value="590"/> <VARIABLE SET INTEGER Option="\x00" Destination="%F%" Value="55"/> <VARIABLE SET INTEGER Option="\x00" Destination="%G%" Value="435"/> <COMMENT Value="Draw 100 lines of random length (within specified limits) from randomly chosen start points within that rectangle."/> <COMMENT Value="NOTE 1: This may take the end point of a line beyond the specified painting rectangle, or even outside the target application.)"/> <COMMENT Value="NOTE 2: Because the increments are all positive numbers, all lines will have a rightward and downward slant."/> <WINDOW ACTIVATE Title=" - IrfanView" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006" _COMMENT="Activate the target window in a suitably configured graphics editing or painting application."/> <WAIT FOR WINDOW TITLE Title=" - IrfanView" Partial="TRUE" Wildcards="FALSE" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/> <MOUSE SPEED Delay="1"/> <REPEAT START Start="1" Step="1" Count="10" Save="FALSE"/> <COMMENT Value="Select a random start point."/> <VARIABLE SET INTEGER Option="\x05" Destination="%X%" Minimum="%A%" Maximum="%B%"/> <VARIABLE SET INTEGER Option="\x05" Destination="%Y%" Minimum=" %F%" Maximum="%G%"/> <MOUSE MOVE Option="\x01" X="%X%" Y="%Y%" _PROMPT="0x000A"/> <MOUSE LEFT BUTTON DOWN/> <DELAY Flags="\x02" Time="100"/> <VARIABLE SET INTEGER Option="\x05" Destination="%N10%" Minimum="10" Maximum="100"/> <VARIABLE SET INTEGER Option="\x05" Destination="%N11%" Minimum="5" Maximum="80"/> <MOUSE MOVE Option="\x03" X="%N10%" Y="%N11%" _PROMPT="0x000A"/> <DELAY Flags="\x02" Time="100"/> <MOUSE LEFT BUTTON UP/> <END REPEAT/> Assuming that is roughly what you're planning to do but with random curves instead of lines, as Alan and rberg have said that depends on the details! What sort of curve segments do you want? Unlike straight lines, which can be defined by just two points, a curve could have an infinite number. Even a short one might need 50-100 to avoid looking too obviously like a set of straight line segments. Here are some 'curves' I've drawn free-hand to illustrate my point: A macro to do that would essentially be similar to the straight line version, with the 'random walk' consisting at its simplest of single pixel increments, both positive and negative. But if, as I suspect, you want 'friendly, smooth curves', which don't zig-zag all over the place, or loop back across themselves, then you'll need to apply an appropriate mathematical function as Alan suggested. Maybe segments of a circle, ellipse, parabola, hyperbola, exponential, logarithmic, etc,etc. Or a randomly selected mixture of several of these. A very different approach would be to design the macro for a graphics editor that has versatile vector curve drawing facilities. In mine, Paintshop Pro, I could first draw a straight line and then use its 'bezier curve' facility to drag an intermediate point to make a smooth curve. As they say, the devil is in the detail! --Terry, East Grinstead, UK PotterHarryLines.mex Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted February 27, 2015 Author Report Share Posted February 27, 2015 Hi Terry, Thanks for taking the time to make such a detailed and helpful reply ... I do have a working macro with more or less a similar structure to yours. I have produced random patterns of various lengths, but the idea of curves and parabolas is very appealing !! BUT it's the implementation that's the issue. I was never that clever at maths. I'll have a go at making my program produce a curve using a formula. That's the obvious first step, and I'll get back !! How do you export your script? Thanks Ian Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted February 27, 2015 Author Report Share Posted February 27, 2015 http://www.mathopenref.com/quadraticexplorer.html A nice little utility for selecting formulas for various curves !! Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 2, 2015 Report Share Posted March 2, 2015 How do you export your script? Hi Ian, 1. Select your macro in Macro Express Pro - Explorer 2. Right click > Export > Export Macro(s)... to save your macro as an MEX file. 3. Then, when composing your message here in the forum, ensure you use More Reply Options (bottom right corner) 4. Use the Attach Files steps that appear bottom left to locate your saved MEX file and include it in your post. Did you make any progress with adapting your macro to produce curves instead of lines? Perhaps if you could draw an example of what you want your result to look like, and post it, we could help further. -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted March 7, 2015 Author Report Share Posted March 7, 2015 Hi again Terry.. Lets just imagine I have drawn a rainbow filling the entire area of an a4 paper. This is my first trial curve. My idea here is to use excel data to populate my x and y coordinates. I have taken a look at one of cory's links to http://bluepointdesign.com/Macros/TabularData/Default.aspx This is what I need to figure out. The properties of my curve can be predefined in Excel, and I can maybe get the macro to pull the info in an array from excel. Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 7, 2015 Report Share Posted March 7, 2015 Hi again Terry.. Lets just imagine I have drawn a rainbow filling the entire area of an a4 paper. This is my first trial curve. What 'trial curve'? Did you intend to post a screenshot or drawing as I suggested? I see nothing here. My idea here is to use excel data to populate my x and y coordinates. I have taken a look at one of cory's links to http://bluepointdesign.com/Macros/TabularData/Default.aspx This is what I need to figure out. The properties of my curve can be predefined in Excel, and I can maybe get the macro to pull the info in an array from excel. You'll need to ask Cory about that then. -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted March 9, 2015 Author Report Share Posted March 9, 2015 Hi Terry I will post a question to Cory Thanks again for your help !! Ian Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 10, 2015 Report Share Posted March 10, 2015 Hi Terry I will post a question to Cory Thanks again for your help !! Ian And the answer to my question? Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted March 10, 2015 Author Report Share Posted March 10, 2015 No, I didn't attempt to upload a diagram of a curve Regards Ian Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.