Features & Development

PGsketchmacros in addition to PGgraphmacros

PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
Number of replies: 10
I am suggesting a set of macros:

PGsketchmacros

which would be similar to PGgraphmacros

...except that it would be for sketches.

A mockup is done for electrical circuits:
A quick look is at http://www.teabun.ca/webwork2/sketch
Log in as guest
The assignment has the same problem assigned over and over.
Here is a good place to look at the randomization as the randomize button in the library browser does not work for this.

How should I put this:
I need to upload this before it stops working.

My demo has problems - Perl does not seem to behave as the books and forums suggest.
Arguement passing to methods has been odd:

sub load_caption_vocabulary{
shift;
%vocab = @_;
return;
}

when called by the object. Has perl changed? Do I need to specify a version??
In reply to Hedley Pinsent

Re: PGsketchmacros in addition to PGgraphmacros

by Michael Gage -
Hi Hedley,

Looks nice. How are you creating the .png image? 

I have some contributed code (working only outside webwork at the moment) which allows the use of tikz commands to construct diagrams in tex. Eventually I'd like to (or have someone else) incorporate this so it could be used in pg problems.  I don't know if that would be useful in creating these images.

I wonder if the library randomize button is not working or appears not to be working because the browser is caching the image and not updating it. Are problems without pictures not being randomized? 


I didn't understand the last comment about passing methods.  I don't believe that perl has changed in this regard. Could you explain more fully?  What goes wrong?  What does the calling function look like?

-- Mike
In reply to Michael Gage

Re: PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
Hi Mike,

Thanks for the encouragement; the latest files are attached - still in progress; some documentation is attached in the previous post.

To produce the images:
So far it is a cut and paste from PGgraphmacros - including the "Fixme"


The size of the image is determined at the end.
As such the plan is to store all the draw instructions in arrays @_x,@_y,@_flag prior to calling WWPlot.
I worry a little about the "processing footprint" here.

If there is a better way, I guess now is the time.
I have sorted out a number is fundamental issues since the last post.
As regards to the "randomize button", I think we should wait until the code is in better shape before we point fingers.

Thanks - hp


At the end of the pg file we have
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

$gr=$circuit->make_image();

BEGIN_TEXT

What is the effective resistance that the battery "sees"? $BR
\{ans_rule(8)\} $BR $BR
\{ image(insertGraph($gr), width=>400, height=>400) \}

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Where make_image is:
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV


sub make_image{

if(($_xmax-$_xmin)>($_ymax-$_ymin)){
($_xmin,$_xmax)= ($_xmin-$_border*($_xmax-$_xmin),$_xmax+$_border*($_xmax-$_xmin));
($_ymin,$_ymax)= ($_ymin-$_border*($_xmax-$_xmin),$_ymax+$_border*($_xmax-$_xmin));
$_pixels_x = $_pixels;
$_pixels_y = $_pixels *($_ymax-$_ymin)/($_xmax-$_xmin);
}
else{
($_ymin,$_ymax)= ($_ymin-$_border*($_ymax-$_ymin),$_ymax+$_border*($_ymax-$_ymin));
($_xmin,$_xmax)= ($_xmin-$_border*($_ymax-$_ymin),$_xmax+$_border*($_ymax-$_ymin));
$_pixels_y = $_pixels;
$_pixels_x = $_pixels *($_xmax-$_xmin)/($_ymax-$_ymin);
}


my $graphRef = new WWPlot($_pixels_x, $_pixels_y);


# select a name for this graph based on the user, the psvn and the problem
my $setName = $main::setNumber;
# replace dots, commmas and @ signs in set and user names to keep latex and html happy
# this should be abstracted and placed in PGalias.pm or PGcore.pm or perhaps PG.pm
#FIXME
$setName =~ s/Q/QQ/g;
$setName =~ s/\./-Q-/g;
my $studentLogin = $main::studentLogin;
$studentLogin =~ s/Q/QQ/g;
$studentLogin =~ s/\./-Q-/g;
$studentLogin =~ s/\,/-Q-/g;
$studentLogin =~ s/\@/-Q-/g;
my $imageName = "$studentLogin-$main::problemSeed-set${setName}prob${main::probNum}";
# $imageNum counts the number of graphs with this name which have been created since PGgraphmacros.pl was initiated.
my $imageNum = ++$main::images_created{$imageName};
# this provides a unique name for the graph -- it does not include an extension.
$graphRef->imageName("${imageName}image${imageNum}");

$graphRef->xmin($_xmin);
$graphRef->xmax($_xmax) ;
$graphRef->ymin($_ymin);
$graphRef->ymax($_ymax) ;


foreach (0..$#_x){

if ($_flag[$_] ==0){$graphRef->moveTo($_x[$_],$_y[$_])}
if ($_flag[$_] ==1){$graphRef->lineTo($_x[$_],$_y[$_],'black',1)}
}
return $graphRef;
}

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In reply to Hedley Pinsent

Re: PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
Further work on the sketch macro - ATTACHED

A quick look is at http://www.teabun.ca/webwork2/sketch

ODS files uploaded separately to keep small

regards - hp
In reply to Hedley Pinsent

Re: PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
In reply to Hedley Pinsent

Re: PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
Further work on the sketch macro

A quick look is at http://www.teabun.ca/webwork2/sketch

This time
renamed "noun" : now "figure" The sketch has a number of figures
changed how angles are passed to "Caption"
added and fixed (most notably legacy-like methods: moveTo, lineTo etc)

The example to illustrate the new features is a measurement problem; it has a special problem in that "unexpected character" error sometimes occurs. This is possibly due to processing the raw student input.

Still at "concept" stage - I think. Randomize button never worked - must look into that I suppose.

Files are attached

see documentation sketchmacro.odt

regards - hp
In reply to Hedley Pinsent

Re: PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
Further to my efforts on sketching.

Should be backward compatable to things in last post.

1. Added feature to Import real-time data into the drawing.
This facilitates both the mixture problem and measurement problems; as such two versions of these exits.

2. Polar Coordinates

3. Arcs and circles

The attachment contains SketchMacro.odt which is the documentation. The sketch macro itself and the PG files are also attached.

A quick look is at http://www.teabun.ca/webwork2/sketch

I'm sure there are bugs

regards
hp
In reply to Hedley Pinsent

Re: PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
This has to do with drawing dynamic sketches for WeBWorK problems.

I am sharing my ongoing effort to produce a Sketch macro. Sketch is an upgraded version of sketch.

Attached.

Changed is:
1. Sketch is used instead of sketch: this is to avoid any collision with the previous version. However, they are essentially the same thing.
2.
($gr,$xpixels,$ypixels)=$Mysketch->make_image();
BEGIN_TEXT
\{ image(insertGraph($gr), width=>$xpixels, height=>$ypixels) \}
$PAR
END_TEXT
previously it was $gr = ...
I am amazed why the previous version worked at all.
3.
Arcs and cartesian entry of polar coordinates
space Az Xabcd would now be Az Xab Xcd
See documentation for details.

Fixed is:
Objects should now work

Added is:
space Y in addition to space X (see documentation)
arrowheads (space e and space E) ("")
space b and space B for bisecting ("")

Not done is:
dimension lines (technical drawings should have dimension lines)
......automatic perpendicular offsets??

3d - basic 3d would be wireframes (no hidden line elimination)

Regrets are: (on the change list)
Styles are clumsy: line styles and fills should have been labelled.
Nodes should also be labelled

Included files.
SketchMacro.odt - this is the documentation, a good first look.
(my demonstration server is down - I need to change my ISP)
also be careful if you copy from the documentation to the pg file: OpenOffice will have corrupted the quotation marks.

Sketch.pl - this is the macro itself; place it in the macros directory

alphabet.pg - this is a resource; if you look inside it also has some greek and some math symbols.
(I could have done a better job here in that I possibly did not get all of them from the original Hershey set)
Note on theta - the Hershey theta and the textbook pi are very different; you will possibly see the one that I modified.

arc_length_radians.pg and sector_area_degrees.pg
These are two examples. There are others but these are written with all the features under my fingertips.



Hope this post provides some insight into the issues here.

Regards
HP

In reply to Hedley Pinsent

Re: PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
Attached are examples of problems using the Sketch.pl macro.

You will need to use the version of Sketch.pl found there as it is the only version containing "load_caption_vocabulary_123()". This works the same way as "load_caption_vocabulary()" except that the former will automatically load enough vocabulary to sketch a perl-styled number: this would be the digits,the decimal, e,+ and - signs.

It was noted that most sketches would require digits in addition to several characters: for example for a problem using metres and degrees we would have:

$ARC->load_caption_vocabulary_123(
"*","SQN[Z[ RQFOGNINKOMQNSNUMVKVIUGSFQF",# degree symbol
m=>"SQG[a[ RGMG[ RGQJNLMOMQNRQR[ RRQUNWMZM\N]Q][",
);

You should put Sketch.pl in your macros directory. The locations of the problem files depends on how you are organizing your work.

As this would be the only addition to the documentation, no work has been done on the documentation.

I just finished "polishing" these up so there has been no testing of these particular versions. Typically there has been very little testing on previous versions (6 to 30 students). There has been no testing on measurement.pg.
In reply to Hedley Pinsent

Re: PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
A 3d extension of the Sketch macro.

Attached (4 files)
documentation: 1 file in two formats: openOffice and pdf
Sketch3D.pl: the macro
measurement_volume.pg - the particular problem file

It's a problem where a student determines density.

Hope you enjoy.

Hedley
In reply to Hedley Pinsent

Re: PGsketchmacros in addition to PGgraphmacros

by Hedley Pinsent -
Changes in PERL -> changes in Sketch.pl and Sketch3D.pl

amended files are attached

Addresses errors like:

Experimental shift on scalar is now forbidden at [TMPL]/macros/Sketch.pl line 144, at EOF
Experimental shift on scalar is now forbidden at [TMPL]/macros/Sketch.pl line 145, at EOF
Experimental unshift on scalar is now forbidden at [TMPL]/macros/Sketch.pl line 638, at EOF
Experimental unshift on scalar is now forbidden at [TMPL]/macros/Sketch.pl line 639, at EOF
Experimental shift on scalar is now forbidden at [TMPL]/macros/Sketch.pl line 644, at EOF
Experimental shift on scalar is now forbidden at [TMPL]/macros/Sketch.pl line 645, at EOF
Experimental push on scalar is now forbidden at [TMPL]/macros/Sketch.pl line 1210, at EOF
Experimental pop on scalar is now forbidden at [TMPL]/macros/Sketch.pl line 1214, at EOF
Experimental push on scalar is now forbidden at [TMPL]/macros/Sketch.pl line 1215, at EOF

Changed code like:


${$T->{Line_width}} = shift ${$T->{drawing_styles}}{L_w};
${$T->{line_width}} =shift ${$T->{drawing_styles}}{l_w};
${$T->{Line_type}} = shift ${$T->{drawing_styles}}{L_t};
${$T->{line_type}} =shift ${$T->{drawing_styles}}{l_t};

to:
${$T->{Line_width}} = shift @{$T->{drawing_styles}{L_w}};
${$T->{line_width}} =shift @{$T->{drawing_styles}{l_w}};
${$T->{Line_type}} = shift @{$T->{drawing_styles}{L_t}};
${$T->{line_type}} =shift @{$T->{drawing_styles}{l_t}};

Hope I have not created any extraneous issues??

Hedley