Fun with Draw.

Recommended Posts

I have started a fun project that involves the Draw. functions.

I've always been curious about it, now I'm reading and re-reading to understand it. :)

Just a few canvas questions.

It looks as if my frame is the same settings as my pen...When I use Draw.FrameRect(DC, Position), it uses

the defined pen settings...

Can I have multiple Pen colors/settings?

Would I need to place a seperate SetPen() above FrameRect() and place it at the top of the sequence, then re-define my pen later above the new line to draw?

How would I make knob components stay with-in the canvas positions?

What I did was use the length from the center of the canvas in both directions in the range of the knob settings.

i.e. -142 to 142 = X var, -192 to 192 = Y var.

It seems to work fine like this, just wondering if there is another way about it.

How would I make a slider components range from positive to negative on a vertical slider?

My vertical "Y" slider is working as it should, just when you move the slider, my pen in the canvas moves opposite.

i.e. up is down and down is up.

Also, I'm attempting to "draw" a continuous line in my canvas, simaliar to the Etch-A-Sketch.

I'm guessing I need a few for() loops for the x and y axis', and a variable to add/subtract from.

for(private.x=knobX, x != knobx, x++)

draw.lineto(dc, line)


Something that uses the movement of my X,Y as the trigger for the for()?

And lastly, line markers in the canvas sequence would be nice! (DF6?)

Been working on it in my free time the last few days.

Check it out! :)


Link to comment
Share on other sites

Very cool! When you get it cleaned up, maybe you'll let us distribute it as a sample with DAQFactory. As you can tell by the lunar lander sample, we like the more whimsical stuff.

Pens: yes you can have as many pens as your memory allows (which alas is limited by windows Resources, not memory, but I doubt you'll hit the limit). DAQFactory automatically recycles the pens, so if you create a black pen, then a red pen, then go back to a black pen, it uses the same black pen, it doesn't create a new one. And yes, just put the SetPen() before each framerect.

Knobs: your solution seems reasonable, but doesn't allow for easy resize. You could set the knob range from within the canvas control since all controls have a position variable that would tell you the width and height.

Slider: there is a checkbox on the main property page of the slider called "Reverse Scale" that will flip it for you

Continuous line: ok, this requires you to rethink how you are doing this. What you need to do is create an array that contains the x and y coords for every segment of the line. This should actually be a 2D array so that you can use the Draw.PolyLine (see the docs on polyline), otherwise looping through and doing LineTo() for every segment will make it real slow as the image gets more complicated. So, the knobs/sliders build the array and the canvas just works on that array. I don't want to give it all away, but hopefully that will get you started.

Line numbers: although not along the left side, the main DF status bar actually shows the line/col of your cursor even when in the canvas properties editor

Link to comment
Share on other sites

I must've looked right over the "Reverse Scale" check box 100 times and didn't see it. :)

About the knobs, I was thinking that resizing would be a small hassle, but not to bad.

So probably something like -

Component.LeftKnob.RangeMax = Position[0][0]
Component.LeftKnob.RangeMin = Position[1][0]
Component.RightKnob.RangeMax = Position[0][1]
Component.RightKnob.RangeMin = Position[1][1]

Thanks for the continuous line hint!

Link to comment
Share on other sites

:blink::huh: Oh man, my mind is in a twist!

I have made 2 arrays that increment on the knob/sliders +-0.5 movement and the arrays are filling as they should. (although i think my array loops aren't the best)

Just when I pass them to the actual line to draw, the made array doesn't update as I think it should.

Should the line to be drawn always be arranged in an array similar to this? -

LineToDraw = {{120, 97},{121,98}}

If there is no X or Y movement on one axis, the value becomes zero and I dont think the data is crossing through correctly.

When I increment my arrays, and there is no movement on the other axis, the array starts to look like this. -

LineToDraw = {{120, 97},{121,98}, {125, 0.000}, {126.75, 0.000}}

How do I manipulate the final array to keep it like so? (keeping the 4 values in the double curly braces instead of adding into the curly braces and then adding a second set of 4 on curly braces?) -

LineToDraw = {{120, 97}, {121, 98}}, {{125, 99}, {125, 100}}

Possibly my "rough draft" .ctl file will show what I'm talking about. :P


Link to comment
Share on other sites

You should always be working in absolute coords, so you should only get 0 when you are at the 0 coord (which I think you put in the center). What I'd do (or try) is have two global variables for the current X and Y knob positions:

global xknob = 0

global yknob = 0

These are what the knobs would change. Then I'd have yet another global with the array of positions for the long line that is our drawing:

global xyLine = {{0,0}}

Note how I initialized it to the center, and in the 2nd dimension. Now I'd have a sequence that runs continuously at idle thread priority (0). It would look at the current knob positions and if they've changed, add them to xyLine:

private xy
private lastrow
while (1)
   lastrow = numrows(xyLine) - 1
   if ((xknob != xyLine[lastrow][0]) || (yknob != xyLine[lastrow][1]))
	  xy[0][0] = xknob
	  xy[0][1] = yknob

I don't remember what the fastest knob update is, maybe 30 times a second, so a delay of 0.03 might be better.

Finally, just do Draw.PolyLine(dc, xyLine) in the canvas. (I think that is the function, I'm doing it from memory, but it should be obvious when you type Draw. and get the list.

To clear the canvas, just set xyLine back to {{0,0}}, and xknob and yknob to 0.

A couple limitations with what I've done, but both are true to the original etch-a-sketch:

1) you can only draw in one color

2) you can't lift the pen up

Link to comment
Share on other sites

  • 2 months later...

I wonder why the canvas seems to operate more "smoothly" in a pop-up window?

Easier to refresh a pop-up than the whole document?

I have a few more ideas for the EtchASketch, but they seem near impossible in my mind.

i.e. - How would you draw a circle? :P Better yet, just a diagonal line? :)

You would have to control both knobs independently at the same time!

Ugh, my brain is singed. :D


Link to comment
Share on other sites


This topic is now archived and is closed to further replies.