JavaScript graphics library

zhaozj2021-02-16  45

JavaScript graphics library

Visualsw

In web development, when we need to draw some graphics on the web page, it is more difficult. In the recent development, you have encountered some need to draw graphics in the client, such as triangles, ellipses, etc. Fortunately, there is an internet, go to Google, huh, it's really a lot, just like this, I found a very good JavaScript DHTML graphics library, really good, I can't help but feel the professional, ^ _ ^, good , Let's take a look.

The old Walter Zorn's URL is http://www.walterzorn.com, very good JavaScript website, very strong.

This use is the web direct drawing function, to this address download

http://www.walterzorn.com/scripts/wz_jsgraphics.zip

Let's take a look at the effect:

Strong, huh, huh!

The help document on the page is very strong, don't use me to explain it.

I have made a little development above this, huh, everyone can develop new functions according to my own needs;

Added a method: straight line with arrows

First add some parameters:

/ *

============================================================================================================================================================================================================= ====================================

Function: Total line parameters with arrow

Author: Shen Wang

date:

2004/04/15

============================================================================================================================================================================================================= ====================

* /

Var linecolor = "# 000000";

Var linewidth = 3;

VAR arrowheadwidth = 5;

Var arrowheadangle = 15/180 * math.pi; // radians

Var arrowbegin = true;

Var arrownd = true;

/ *

============================================================================================================================================================================================================= ==================== * /

Then add a function of drawing the straight line, you can set the arrow, text, arrow angle, etc.

/ *

============================================================================================================================================================================================================= ====================

Function: Draw the straight line with arrow

Author: Shen Wang

date:

2004/04/15

============================================================================================================================================================================================================= ====================

* /

this.setarrowWidth = function (x)

{

Arrowheadwidth = x;

}

this.setarrowangle = function (x)

{

X = x> 90? 45: x;

X = x <0? 45: x;

Arrowheadangle = x * math.pi / 180;

}

this.SetLineWidth = function (x)

{

LINEWIDTH = X;

}

this.setLineColor = Function (x)

{

LineColor = X;

}

this.setarrowbegin = function (x)

{

Arrowbegin = x;

}

this.setarrowend = function (x)

{

Arrownd = x;

}

THIS.DRAWARROWHEADLINE = Function (beginx, beginy, endx, endy)

{

THIS.SETCOLOR (LINECOLOR);

THIS.SETSTROKE (LINEWIDTH);

VAR DX, DY;

Dx = math.abs (beginx-endx); DY = math.abs (beginy-end);

Var lineslope; // linear slope (radians)

LineSlope = Math.atan (DX / DY);

/ / Seeking the coordinates of the middle distance

VAR TMPLINE;

Tmpline = (linewidth arrowheadwidth) / (2 * math.sin (arrowheadangle);

// Time in the starting point

Var begincenterx;

Var begincentery;

// Test

Var EndCenterx;

VAR EndCentery;

IF (arrowbegin)

{

// Draw a starting point triangle

// begin

Begincenterx = Beginx TMPLINE * MATH.SIN (LINESLOPE);

Begincenter = Beginy Tmpline * Math.cos (LINESLOPE);

/ / Define the three vertices of the starting triangle

Var Beginx1, Beginy1;

Var beginx2, beginy2;

Var Beginx3, Beginy3;

Beginx1 = beginx;

Beginy1 = beginy;

Beginx2 = beginx-tmpline * math.sin (arrowheadangle-lineselope);

Beginy2 = Beginy TMPLINE * MATH.COS (arrowheadangle-linelope);

Beginx3 = Beginx TMPLINE * MATH.SIN (ArrowHeadangle Lineslope);

Beginy3 = Beginy TMPLINE * MATH.COS (arrowheadangle lineslope);

Var XbeginPoints = New Array (Beginx1, Beginx2, Beginx3);

VAR YbeginPoints = New Array (Beginy1, Beginy2, Beginy3);

This.FillPolygon (XbeginPoints, Ybeginpoints);

// end

}

Else

{

Begincenterx = beginx;

Begincenter = beginy;

}

IF (arrownd)

{

// Draw a final point triangle

// begin

EndCenterx = ENDX-TMPLINE * MATH.SIN (LINESLOPE);

EndCentery = endy-tmpline * Math.cos (LINESLOPE);

/ / Define three vertices of the end point triangle

Var ENDX1, Endy1;

Var ENDX2, Endy2;

Var ENDX3, Endy3;

ENDX1 = ENDX;

Endy1 = endy;

ENDX2 = ENDX-TMPLINE * MATH.SIN (arrowheadangle lineslope);

Endy2 = endy-tmpline * Math.cos (arrowheadangle lineslope);

ENDX3 = ENDX TMPLINE * MATH.SIN (arrowheadangle-linelope);

Endy3 = endy-tmpline * math.cos (arrowheadangle-linelope);

VAR Xendpoints = New Array (ENDX1, ENDX2, ENDX3);

Var YendPoints = New Array (Endy1, Endy2, Endy3);

This.FillPolygon (Xendpoints, YendPoints);

// end

}

Else

{

EndCenterx = ENDX;

EndCentery = endy;

}

// Draw the center line

This.drawline (Begincenterx, Begincentery, Endcenterx, EndCentery);

}

THIS.DRAWFLOWLINE = Function (Beginx, Beginy, Endx, Endy, Begintext, EndText)

{

Var Textx;

Var Texty;

THIS.DRAWARROWHEADLINE (Beginx, Beginy, Endx, Endy);

Textx = beginx 20;

Texty = Beginy;

THIS.DRAWSTRING (Begintext, Textx, Texty);

}

Let's take a look at the effect:

Test code:

DHTML JavaScript Tooltips </ Title></p> <p><script language = "JavaScript" src = "./ graphics.js"> </ script></p> <p><script language = "javascript"></p> <p>VAR JG = new jsgraphics ();</p> <p>Jg.setarrowwidth (4);</p> <p>Jg.setarrowangle (20);</p> <p>Jg.setLineWidth (2);</p> <p>Jg.setLineColor ("Blue");</p> <p>Jg.drawflowline (10, 10, 200, 200, "line1");</p> <p>Jg.setLineColor ("red");</p> <p>Jg.setarrowbegin (false);</p> <p>Jg.drawflowline (110, 10, 300, 200, "Line2", "End");</p> <p>Jg.setLineColor ("Green");</p> <p>Jg.setarrowbegin (TRUE);</p> <p>Jg.setarrowend (false);</p> <p>Jg.drawflowline (210, 10, 400, 200, "" "," line3 ");</p> <p>Jg.setarrowend (TRUE);</p> <p>Jg.setarrowangle (15);</p> <p>Jg.drawflowline (310, 10, 500, 200, "," line4 ");</p> <p>Jg.setarrowangle (30);</p> <p>Jg.drawflowline (410, 10, 600, 200, "" "," line5 ");</p> <p>Jg.setLineWidth (10)</p> <p>Jg.drawflowline (410, 10, 600, 200, "" "," line5 ");</p> <p>Jg.setstroke (10)</p> <p>Jg.drawline (10, 300, 400, 500);</p> <p>Jg.paint ();</p> <p></ script></p> <p><meta http-equiv = "expires" Content = "0"></p> <p></ HEAD></p> <p><body></p> <p></ body></p> <p></ Html></p> <p>It can be seen that the effect is still very good, just there is a problem, because when the line is drawn, the internal implementation is implemented in the width of the line. After all the lines are width, it will be unmetled at the head, such as Fig.</p> <p>This old brother is really stronger, and there are other class libraries.</p> <p>For example: the stuff in the stories can be placed casually, the picture is zooming, hiding, etc., New is dragged by me. Tips, huh, huh, more than I have a strong function in the article:</p> <p>There is also stronger, online function drawing graphics, haha!</p> <p>It feels like a CS program.</p> <p>Best, such a good winter winter is free, GNU:</p> <p>This Program is Free Software;</p> <p>You can redistribute it and / or modify it Under the Terms of the</p> <p>GNU General Public License As Published by The Free Software Foundation;</p> <p>Either Version 2 of the license, or (at Your Option) Any Later Version.</p> <p>This Program is Distributed in the Hope That IT Will Be Useful,</p> <p>But without Any warranty;</p> <p>WITHOUT Even The Implied Warranty of Merchantability Or Fitness for a Particular Purpose.</p> <p>See the gnu general public license</p> <p>At http://www.gnu.org/copyleft/gpl.html for more details.</p> <p>Ok, huh, let's take a look!</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-25149.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="25149" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.047</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'cxY28bETcd3eQdlbPSDfvrocUO6GJIYlCdPadugw_2BLQ_2FKPPp2DrmUI75_2BZMoPrQPUGR7zueeFqIPGu8Hx40_2Beg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>