参考网站:http://dayu.pw/svgcontrol/

主要功能:手动可视化生成 SVG图片PATH路径。

效果如下:

代码如下:

 <!DOCTYPE html>
<!-- 参考:http://dayu.pw/svgcontrol/ -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SVG PATH路径生成</title>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<style>
body{
background: #ccc;
font-family: 'Microsoft YaHei';
color: #345;
}
.svg-inner{
width: 900px;
height: 600px;
margin: 0 auto;
background: #fff;
}
#svgMain{
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
box-shadow:0px 3px 13px #333333;
}
#svgMain circle{
cursor: pointer;
fill:rgba(200,200,200,1);stroke:rgba(200,200,200,1);stroke-width:3
}
#svgMain polyline{
fill:rgba(200,200,200,0);stroke:rgba(200,200,200,1);stroke-width:1
}
h1, h4{
text-align:center;
margin:10px;
}
</style> <h1>贝塞尔曲线控制</h1>
<h4>M200 250 C141.5 130 421.5 146 500 250</h4>
<div style="text-align:center; margin-bottom:10px;">
<label><input type="checkbox" id="chkZ" />闭合</label>
&nbsp;
<select id="selType">
<option value="M">M 移动</option>
<option value="L" selected>L 画线到</option>
<option value="H">H 水平绘制</option>
<option value="V">V 竖直绘制</option>
<option value="C">C 三次贝塞尔</option>
<option value="S">S 三次贝塞尔对称</option>
<option value="Q">Q 二次贝塞尔</option>
<option value="T">T 二次贝塞尔连续</option>
</select>
&nbsp; *双击可添加控制点
</div>
<div class="svg-inner">
<svg width="100%" height="100%" id="svgMain" xmlns="http://www.w3.org/2000/svg" version="1.1">
<polyline points=""></polyline>
<path d="" style="fill:rgba(0,0,0,0);stroke:#345;stroke-width:3"></path>
<circle data-type="M" cx="200" cy="250" r="5"></circle>
<circle data-type="C" cx="141.5" cy="130" r="5"></circle>
<circle data-type="C" cx="421.5" cy="146" r="5"></circle>
<circle data-type="C" cx="500" cy="250" r="5"></circle>
</svg>
</div> <script>
$(function(){
$('#svgMain').dblclick(function(e){
var cx = e.pageX-$(this).parent().offset().left;
var cy = e.pageY-$(this).parent().offset().top; var circle = document.createElementNS("http://www.w3.org/2000/svg","circle");
circle.setAttribute("cx", cx);
circle.setAttribute("cy", cy);
circle.setAttribute("r", 5);
circle.setAttribute("data-type", $('#selType').val());
$(this).append(circle);
setPoints($(circle));
setPolyline();
setPath();
}); $('#svgMain circle').each(function(){
setPoints($(this));
}); $('#chkZ').change(function(){
setPolyline();
setPath();
}); setPolyline();
setPath();
}); function setPoints(obj)
{
var mouseDown=false;
obj.mousedown(function(){
mouseDown=true;
});
obj.parent().mouseup(function(){
mouseDown=false;
});
obj.parent().mousemove(function(e){
e.preventDefault();
if(mouseDown)
{
obj.attr('cx',e.pageX-obj.parent().offset().left);
obj.attr('cy',e.pageY-obj.parent().offset().top);
setPolyline();
setPath();
}
});
} function setPolyline()
{
var points = '';
$('#svgMain circle').each(function(){ points += $(this).attr('cx') + ',' + $(this).attr('cy') + ' ';
}); $('#svgMain polyline').attr('points', points);
} function setPath()
{
var d = '';
var lastType = '';
$('#svgMain circle').each(function(){
var cx = $(this).attr('cx');
var cy = $(this).attr('cy');
var t = $(this).data('type');
if (lastType != t || t == 'M'){
d += t;
} if (t == 'H') {
d += cx + ' ';
} else if (t == 'V') {
d += cy + ' ';
} else {
d += cx + ' ' + cy + ' ';
} lastType = t;
}); if ($('#chkZ')[0].checked)
{
d += ' Z';
} $('h4').html(d);
$('#svgMain path').attr('d', d);
}
</script> </body></html>

SVG PATH 生成器的更多相关文章

  1. 使用SVG Path绘图

    最近一个项目,需要做个Web版本的设计器,用来进行工厂流水线布局的设计. 项目中采用了SVG.JS来做,但是以前流水线是采用单纯的画线的方式实现.客户提出希望用不同的底纹表示不同的流水线,经过一番调查 ...

  2. SVG path

    在网页上画一图形,比如星星或波浪线,开始是想着图形软件画一个的,后来发现SVG这绘图程序的语言,感觉甚是可以,就发了些时间学了一下,在此做一简单分享和记录. 菜鸟上是这么介绍的(SVG 是使用 XML ...

  3. svg path 动画效果

    http://www.zhangxinxu.com/wordpress/2014/04/animateion-line-drawing-svg-path-%E5%8A%A8%E7%94%BB-%E8% ...

  4. svg path 解析

    <pre><svg width="100%" height="100%" version="1.1" xmlns=&quo ...

  5. SVG path d Attribute

    Scalable Vector Graphics (SVG) 1.1 (Second Edition) W3C Recommendation 16 August 2011 http://www.w3. ...

  6. SVG Path高级教程

    课程分为四个方面: 1. Path概述 2. 移动和直线命令 3. 弧线命令 4. 贝塞尔曲线命令 Path概述 <path> 标签用来定义路径,Path字符串是由命令及其参数组组成的字符 ...

  7. Svg path画线(不管是直线还是曲线)在一定情况下线条的宽度不一的情况(记录)

    在项目中涉及到svg: 使用path划线实现图表功能. 记录在实现的过程中发现的问题:path在小像素的情况下画出的线条宽度不一样.这是为什么呢? 以下是我做的猜想: 可以看图 在宽度给的很足的时候没 ...

  8. svg path中的贝塞尔曲线

    首先介绍以下什么是贝塞尔曲线 贝塞尔曲线又叫贝茨曲线(Bezier),由两个端点以及若干个控制点组成,只有两个端点在曲线上,控制点不在曲线上,只是控制曲线的走向. 控制点个数为0时,它是一条直线; 控 ...

  9. svg path详解

    svg的<path>标签具有强大的功能,主要包括以下命令 M(move to) 参数:x,y L(line to) 参数:x,y H 参数:x V 参数:y C S Q T Z 参考:

随机推荐

  1. Docker----与Asp.net core 的完美结合,在docker容器中创建Asp.Net Core 项目

    在腾讯云上买了一个小容量的服务器,搭建一个docker环境后,可以尝试做一些单系统做起来很麻烦的东西.譬如说,你在windows OS或UbuntuOS中,突然想玩CentOS了,你可以选择将电脑再装 ...

  2. PHP 递归几种方法

    一.利用静态变量的方法 <?php function call(){ static $i = 0; echo $i . ''; $i++; if($i<10){ call(); } } c ...

  3. java----GUI和接口回调

    GUI: 图形用户接口 import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java. ...

  4. 饮冰三年-人工智能-Python-28 企业官网(组合搜索)

    1 2:组合搜索 2.1 创建model类 from django.db import models class Direction(models.Model): """ ...

  5. jQuery概念

  6. 程序守护服务 Supervisor

    一.什么是Supervisor? Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启.它是通过fork ...

  7. java-数组排序--冒泡排序、鸡尾酒排序、地精排序

    冒泡排序 冒泡排序的思想是,让依次数组中相邻的数进行比较,如果前一个数比后一个数大,则两数进行交换,大的数就会象泡泡一样慢慢浮在水面上了 见图解 稳定性:稳定时间复杂度:O(n2) public st ...

  8. 10_27_unittest

    接口测试的本质 就是测试类里面的函数. 单元测试的本质  测试函数 代码级别 单元测试框架 unittest 接口  pytest  web 功能测试: 1.写用例 ----> TestCase ...

  9. resume

    源码链接(码云):https://gitee.com/tinqiao/level_17_software_engineering.git 截图效果: 源码: <!DOCTYPE html> ...

  10. Codeforces 126B. Password (KMP)

    <题目链接> 题目大意:给定一个字符串,从中找出一个前.中.后缀最长公共子串("中"代表着既不是前缀,也不是后缀的部分). 解题分析:本题依然是利用了KMP中next数 ...