/* * * JavaScript Windows ScriptingHost sample file * usage: cscript trySVG2msg.js * --8<--- do_LED.bat ---- rem rem rem :start cscript trySVG2_LED.js pause goto start ------------------- */ var stdin = WScript.StdIn; var stdout = WScript.StdOut; /*************************************************** ****************************************************/ header = '<svg width="640" height="900" xmlns="http://www.w3.org/2000/svg"><g>' footer = '</g></svg>' footer = '<text xml:space="preserve" y="10" x="320" text-anchor="middle" stroke-width="0" stroke-linejoin="null" stroke-linecap="null" \n'+ ' stroke="#000000" fill="#000000" font-size="12" font-family="Sans-serif" id="svg_label_a" >Generate Three Phase Sine Waves to give clipped RGB values'+ '</text> \n'+ '<text xml:space="preserve" y="30" x="320" text-anchor="middle" stroke-width="0" stroke-linejoin="null" stroke-linecap="null" \n'+ ' stroke="#000000" fill="#000000" font-size="12" font-family="Sans-serif" id="svg_label_a" >'+ ' This is based on a Wireless World article by N Darwood in November 1982.'+ '</text> \n'+ '<text xml:space="preserve" y="50" x="320" text-anchor="middle" stroke-width="0" stroke-linejoin="null" stroke-linecap="null" \n'+ ' stroke="#000000" fill="#000000" font-size="12" font-family="Sans-serif" id="svg_label" >blinkt</text> \n'+ '</g>\n'+ '<script type="text/ecmascript">\n<![CDATA[\n'+ 'var id=1 \n'+ 'var clr = ""\n'+ 'var A,B,C,n \n'+ ' \n'+ ' A=0\n'+ ' //B=0.866 \n'+ ' B=2.5 \n'+ ' C=-B \n'+ ' n=0.01 \n'+ ' \n'+ ' A=A+n*(B-C) \n'+ ' B=B+n*(C-A) \n'+ ' C=C+n*(A-B) \n'+ ' \n'+ 'function plot_ts(){ \n'+ ' svgElement = document.getElementById( "svg_up_"+id ); \n'+ ' //svgElement.setAttributeNS( null, "fill", "#AA0" ); \n'+ ' \n'+ ' A=A+n*(B-C) \n'+ ' B=B+n*(C-A) \n'+ ' C=C+n*(A-B) \n'+ " var rgb = 'rgb(' + ((128+A*120)&-1) + ',' + ((128+B*120)&-1) + ',' + ((128+C*120)&-1)+' )' \n"+ ' //rgb = "rgb(255,255,128)" \n'+ " //var rgb = 'rgb(' + ((128+A*120)&-1) + ',' + ((128+B*120)&-1) + ',' + ((128+C*120)&-1)+' )' \n"+ ' //rgb = "rgb(100%,100%,50%)" \n'+ " var rgb = 'rgb(' + ((50+A*50)&-1) + '%,' + ((50+B*50)&-1) + '%,' + ((50+C*50)&-1)+'% )' \n"+ ' if( svgElement ){ \n'+ ' svgElement.setAttributeNS( \n'+ ' null, \n'+ ' "fill", \n'+ ' rgb \n'+ ' ); \n'+ ' // Generate Three Phase to give an RGB value \n'+ ' // This is based on a Wireless World article by N Darwood in November 1982. \n'+ ' id++ \n'+ ' } else { \n'+ ' id=1 \n'+ ' } \n'+ ' svgElement = document.getElementById( "svg_label" ); \n'+ ' //obj8.setAttributeNS(null,"textContent", "textString" ); \n'+ ' svgElement.textContent= rgb \n'+ '} \n'+ 'window.setInterval("plot_ts()",100); \n'+ ' \n'+ ']]></script>\n'+ '</svg>' rect = '<rect height="100.48" width="260.67" y="195.22" x="244.85" stroke-width="1.5" stroke="#000" opacity="0.5" fill="#7fff00" id="svg_68"/>' /* SVG Path - <path> The <path> element is used to define a path. The following commands are available for path data: 筆 = moveto 畢 = lineto 菱 = horizontal lineto 彪 = vertical lineto 匹 = curveto 百 = smooth curveto 媛 = quadratic B騷ier curve 謬 = smooth quadratic B騷ier curveto 柊 = elliptical Arc 瓢 = closepath Note: All of the commands above can also be expressed with lower letters. Capital letters means absolutely positioned, lower cases means relatively positioned. */ src=100 dst=200 message="AtoB" colour = "#ff3f00" lineNum = 0 line = 100 path4 ='' id2=1 /* ******************************** SEC: x Functions to plot **********************************/ path = '<path d="m66.34665,193.77779c-1.63545,103.43126 253.72461,-88.90665 147.05779,-90.5067c-106.66684,-1.60004 137.36858,185.88452 137.38658,84.05342c0.01801,-101.8311 -284.4621,129.27995 -138.98665,124.42653c145.47548,-4.85342 -143.82227,-221.40435 -145.45772,-117.97325z" stroke-width="5" stroke="#000000" fill="#ff0000" opacity="0.5" id="svg_1"/>' path2 = '<path d="m100,100c-1.63545,103.43126 253.72461,-88.90665 147.05779,-90.5067c-106.66684,-1.60004 137.36858,185.88452 137.38658,84.05342c0.01801,-101.8311 -284.4621,129.27995 -138.98665,124.42653c145.47548,-4.85342 -143.82227,-221.40435 -145.45772,-117.97325z" stroke-width="5" stroke="#000000" fill="#ff0000" opacity="0.5" id="svg_1"/>' path3 = '<path d="m100,100" stroke-width="5" stroke="#000000" fill="#ff0000" id="svg_1"/>' //path4 = '' path5 = '<path d="M100,100h5M100,200h5M100,300h5" stroke-width="5" stroke="#000000" fill="#ffff00" id="svg_1"/>' /* write a function to generate the path */ /* * * A grid has horizontal vertical, minor and major axis, six lines. * Graph Paper has Minor and Major. Do it at 10,100 * */ maxX = 640 maxY = 480 function grid(){ var tempStr = '<path d="' /* this function draws a 100x100 grid */ for ( x = 0 ; x < ( maxX+1 ) ; x+= 10 ){ tempStr+="M"+x+",0v"+maxY } for ( x = 0 ; x < ( maxX+1 ) ; x+= 100 ){ tempStr+="M"+x+",0v"+maxY } /* do again for another pitch */ for ( y = 0 ; y < ( maxY+1 ) ; y+= 10 ){ tempStr+="M0,"+y+"h"+maxX } for ( y = 0 ; y < ( maxY+1 ) ; y+= 100 ){ tempStr+="M0,"+y+"h"+maxX } tempStr+='"' /* tidy up */ tempStr+=' stroke-width="1" stroke="#000000" fill="#ffff00" opacity="0.15" />' return tempStr } /* write a function to generate the path */ function d1(){ path4 = '<path d="M100,200h100v10h100v-10h100v10h100v-10h100v10h100v-10h100v10h100v-10h100v10h100v-10h100v10h100v-10l90 90" '+ 'stroke-width="2" stroke="#00007f" fill="#ff0000" opacity="0.5" id="svg_1"/>' } var opStr = header+"\n"+ grid_circles()+ //grid_circles_1_3()+ footer+ "\n" fso = new ActiveXObject("Scripting.FileSystemObject"); function writeFile(){ var ForReading = 1, ForWriting = 2; stdout.WriteLine( "outputting image " ); // Open the file for output. var fop = fso.OpenTextFile(".\\tryCscriptSVG_LED.svg", ForWriting, true); if ( fop ) { fop.WriteLine( opStr ); } if ( fop ) { fop.close(); } } // writeFile() //https://msdn.microsoft.com/en-us/library/64cdz8ax(v=vs.84).aspx function process(){ while (!stdin.AtEndOfStream){ var ipStr ; ipStr = stdin.ReadLine(); // ipA = ipStr.split( " " ); ipA = ipStr.split( / +/ ); stdout.WriteLine( "fd( " + ipA[ 2 ] + "," + ipA[4] + ");" ); } } // <ellipse ry="7" rx="7" id="svg_up" cy="40" cx="595" stroke-linecap="null" stroke-linejoin="null" stroke-width="3" stroke="#000000" fill="#777"/> function grid_circles(){ var A,B,C,n var mr,mi,mt,ar,ai,r, f,rad; rad = 2.0 * Math.PI * 0.2 mr=0.5 mi=0.0 r=1.01 ar=r*Math.sin( rad ) ai=r*Math.cos( rad ) // Generate Three Phase to give an RGB value // This is based on a Wireless World article by N Darwood in November 1982. n=0.2 A=0 //B=0.866 B=3 C=-B var maxX = 200 var tempStr = '' /* this function draws a 100x100 grid */ for ( x = 30 ; x < ( maxX+1 ) ; x+= 1 ){ mt= mr*ar-mi*ai mi= mr*ai+mi*ar mr=mt // Generate Three Phase to give an RGB value // This is based on a Wireless World article by N Darwood in November 1982. A=A+n*(B-C) B=B+n*(C-A) C=C+n*(A-B) tempStr += '<ellipse ry="15" rx="15" id="svg_up_'+id2+'" \n'+ ' cx="'+ ( 320 + (mr*75.0)&-1) + '"'+ ' cy="'+ ( 250 + (mi*75.0)&-1) + '"'+ ' stroke-linecap="null" stroke-linejoin="null" stroke-width="2" stroke="#000000" \n'+ ' fill="rgb(' + ((128+A*120)&-1) + ',' + ((128+B*120)&-1) + ',' + ((128+C*120)&-1)+' )" />\n' id2++ } return tempStr } function grid_circles_1_3(){ var A,B,C,n var A2,B2,C2,n2 var mr,mi,mt, ar,ai,r, f,rad; var m2r,m2i,m2t,a2r,a2i,tmp2, f,rad2; rad = 2.0 * Math.PI * 0.01 rad2 = 2.0 * Math.PI * 0.04 mr=1.5 mi=0.0 m2r=1.5 m2i=0.0 r=1.002 ar=r*Math.cos( rad ) ai=r*Math.sin( rad ) a2r=r*Math.cos( rad2 ) a2i=r*Math.sin( rad2 ) // Generate Three Phase to give an RGB value // This is based on a Wireless World article by N Darwood in November 1982. n=0.05 A=0 //B=0.866 B=3 C=-B n2= n/3 A2= 0 //B2=0.866 B2= B/2 C2=-B var maxX = 200 var tempStr = '' /* this function draws a 100x100 grid */ for ( x = 30 ; x < ( maxX+1 ) ; x+= 1 ){ mt= mr*ar-mi*ai mi= mr*ai+mi*ar mr=mt m2t= m2r*a2r-m2i*a2i m2i= m2r*a2i+m2i*a2r m2r=m2t // Generate Three Phase to give an RGB value // This is based on a Wireless World article by N Darwood in November 1982. A=A+n*(B-C) B=B+n*(C-A) C=C+n*(A-B) A2=A2+n2*(B2-C2) B2=B2+n2*(C2-A2) C2=C2+n2*(A2-B2) tempStr += '<ellipse ry="15" rx="15" id="svg_up_'+id2+'" \n'+ ' cx="'+ ( 300 + ((mr+m2r)*75.0)&-1) + '"'+ ' cy="'+ ( 300 + ((mi+m2i)*75.0)&-1) + '"'+ ' stroke-linecap="null" stroke-linejoin="null" stroke-width="2" stroke="#000000" \n'+ ' fill="rgb(' + ((128+(A+A2)*120)&-1) + ',' + ((128+(B+B2)*120)&-1) + ',' + ((128+(C+C2)*120)&-1)+' )" />\n' id2++ } return tempStr } //process reads StdIo but does nothing //process(); writeFile(); /* program to write circuit. Grid:- */ /* <svg width="521" height="392" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <!-- Created with SVG-edit - https://github.com/SVG-Edit/svgedit--> <g> <title>Layer 1</title> <rect height="323.64" width="449.09" y="34.985" x="36.14" stroke-width="5" stroke="#000000" fill="#ff7f00" opacity="0.5" id="svg_1"/> <ellipse ry="31.815" rx="33.185" cy="34.99" cx="35.685" stroke-width="5" stroke="#000000" fill="#ffff00" opacity="0.5" id="svg_2"/> <ellipse ry="31.815" rx="33.185" cy="357.935" cx="485.68" stroke-width="5" stroke="#000000" fill="#ffff00" opacity="0.5" id="svg_3"/> <ellipse ry="31.815" rx="33.185" cy="34.315" cx="485.69" stroke-width="5" stroke="#000000" fill="#ffff00" opacity="0.5" id="svg_4"/> </g> </svg> <svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <!-- Created with SVG-edit - https://github.com/SVG-Edit/svgedit--> <g> <title>Layer 1</title> <rect height="323.64" width="449.09" y="74.075" x="104.32" stroke-width="5" stroke="#000000" fill="#ff7f00" opacity="0.5" id="svg_1"/> <ellipse ry="31.815" rx="33.185" cy="72.27" cx="102.045" stroke-width="5" stroke="#000000" fill="#ffff00" opacity="0.5" id="svg_2"/> <ellipse ry="31.815" rx="33.185" cy="398.845" cx="552.95" stroke-width="5" stroke="#000000" fill="#ffff00" opacity="0.5" id="svg_3"/> <ellipse ry="31.815" rx="33.185" cy="73.405" cx="553.87" stroke-width="5" stroke="#000000" fill="#ffff00" opacity="0.5" id="svg_4"/> </g> </svg> */ /* var id=1 var clr = "" var A,B,C,n A=0 //B=0.866 B=3 C=-B n=0.4 A=A+n*(B-C) B=B+n*(C-A) C=C+n*(A-B) function plot_ts(){ svgElement = document.getElementById( "svg_up_"+id ); //svgElement.setAttributeNS( null, "fill", "#AA0" ); A=A+n*(B-C) B=B+n*(C-A) C=C+n*(A-B) var rgb = 'rgb(' + ((128+A*120)&-1) + ',' + ((128+B*120)&-1) + ',' + ((128+C*120)&-1)+' )' //rgb = "rgb(255,255,128)" svgElement.setAttributeNS( null, "fill", rgb ); // Generate Three Phase to give an RGB value // This is based on a Wireless World article by N Darwood in November 1982. id++ if ( id == 171 ){ id=1 } } window.setInterval("plot_ts()",100); */