{"id":924,"date":"2021-02-26T15:47:00","date_gmt":"2021-02-26T06:47:00","guid":{"rendered":"http:\/\/ringo-apple-web.com\/?p=924"},"modified":"2021-03-03T17:37:34","modified_gmt":"2021-03-03T08:37:34","slug":"%e3%82%b7%e3%83%b3%e3%83%97%e3%83%ab%e3%82%b9%e3%82%bf%e3%83%b3%e3%83%97","status":"publish","type":"post","link":"http:\/\/ringo-apple-web.com\/?p=924","title":{"rendered":"\u30b7\u30f3\u30d7\u30eb\u30b9\u30bf\u30f3\u30d7"},"content":{"rendered":"\n<p>if\u6587\u3068switch\u6587\u306e\u5fa9\u7fd2<\/p>\n\n\n\n<p>\u30af\u30ea\u30c3\u30af\u3057\u305f\u5834\u6240\u306b\u5186\u306a\u3069\u306e\u56f3\u5f62\u3092\u63cf\u3044\u3066\u307f\u3088\u3046<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n\t&lt;meta charset=&quot;utf-8&quot;&gt;\n\t&lt;title&gt;\u30b7\u30f3\u30d7\u30eb\u30b9\u30bf\u30f3\u30d7&lt;\/title&gt;\n\t&lt;script&gt;\n\t\tlet canvas,context; \/\/\u30ad\u30e3\u30f3\u30d0\u30b9\n\t\tconst r = 60;\n\n\t\tconst init = () =&gt; {\n\t\t\t\/\/\u30ad\u30e3\u30f3\u30d0\u30b9\u306e\u53d6\u5f97\n\t\t\tcanvas = document.getElementById(&quot;canvas&quot;);\n\t\t\tcontext = canvas.getContext(&quot;2d&quot;);\n\t\t}\n\n\t\tconst draw = event =&gt; {\n\t\t\t\/\/\u30de\u30a6\u30b9\u30ab\u30fc\u30bd\u30eb\u4f4d\u7f6e\u306e\u53d6\u5f97\n\t\t\tconst rect = event.target.getBoundingClientRect();\n\t\t\tconst x = event.clientX - rect.left;\n\t\t\tconst y = event.clientY - rect.top;\n\t\t\t\/\/\u30b9\u30bf\u30f3\u30d7\u3092\u63cf\u753b\n\t\t\tconst shape = document.getElementById(&quot;shape&quot;).value;\n\t\t\tcontext.fillStyle = document.getElementById(&quot;color&quot;).value;\n\t\t\tif (shape == &quot;circle&quot;) {\n\t\t\t\t\/\/\u5186\u3092\u63cf\u753b\n\t\t\t\tcontext.beginPath();\n\t\t\t\tcontext.arc(x,y,r,0,Math.PI*2);\n\t\t\t\tcontext.fill();\n\t\t\t} else if (shape == &quot;rect&quot;) {\n\t\t\t\t\/\/\u6b63\u65b9\u5f62\u3092\u63cf\u753b\n\t\t\t\tcontext.fillRect(x-r,y-r,r*2,r*2);\n\t\t\t} else if (shape == &quot;triangle&quot;) {\n\t\t\t\t\/\/\u4e09\u89d2\u5f62\u3092\u63cf\u753b\n\t\t\t\tdrawPolygon(3,x,y);\n\t\t\t} else if (shape == &quot;pentagon&quot;) {\n\t\t\t\t\/\/\u4e94\u89d2\u5f62\u3092\u63cf\u753b\n\t\t\t\tdrawPolygon(5,x,y);\n\t\t\t}\n\t\t}\n\n\t\tconst drawPolygon = (n,x,y) =&gt; {\n\t\t\t\/\/\u6b63n\u89d2\u5f62\u306e\u63cf\u753b\n\t\t\tcontext.beginPath();\n\t\t\tfor (let i=0; i&lt;n; i++) {\n\t\t\t\tconst angle = i\/n * Math.PI*2 - Math.PI\/2;\n\t\t\t\tconst tx = x + r * Math.cos(angle);\n\t\t\t\tconst ty = y + r * Math.sin(angle);\n\t\t\t\tif (i==0) {\n\t\t\t\t\tcontext.moveTo(tx,ty);\n\t\t\t\t} else {\n\t\t\t\t\tcontext.lineTo(tx,ty);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontext.fill();\n\t\t}\n\n\t\tconst clearCanvas = () =&gt; {\n\t\t\t\/\/\u30ad\u30e3\u30f3\u30d0\u30b9\u306e\u30af\u30ea\u30a2\n\t\t\tcontext.clearRect(0,0,canvas.width,canvas.height);\n\t\t}\n\t&lt;\/script&gt;\n\t&lt;style&gt;\n\t\tcanvas {border: thin solid #000000;}\n\t&lt;\/style&gt;\n\t&lt;body onload=&quot;init()&quot;&gt;\n\t&lt;p&gt;\u30b7\u30f3\u30d7\u30eb\u30b9\u30bf\u30f3\u30d7&lt;\/p&gt;\n\t&lt;input type=&quot;button&quot; value=&quot;\u30af\u30ea\u30a2&quot; onclick=&quot;clearCanvas()&quot;&gt;\n\t\u30b9\u30bf\u30f3\u30d7\u306e\u7a2e\u985e:&lt;select id=&quot;shape&quot;&gt;\n\t&lt;option value=&quot;circle&quot;&gt;\u5186\n\t&lt;option value=&quot;rect&quot;&gt;\u6b63\u65b9\u5f62\n\t&lt;option value=&quot;triangle&quot;&gt;\u4e09\u89d2\u5f62\n\t&lt;option value=&quot;pentagon&quot;&gt;\u3054\u89d2\u5f62\n\t&lt;\/select&gt;\n\t\u8272:&lt;input type=&quot;color&quot; id=&quot;color&quot; value=&quot;#6699FF&quot;&gt;\n\t&lt;hr&gt;\n\t&lt;canvas id=&quot;canvas&quot; width=&quot;800&quot; height=&quot;600&quot; onclick=&quot;draw(event)&quot;&gt;&lt;\/canvas&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n\n\n\t&lt;\/body&gt;<\/code><\/pre><\/div>\n\n\n\n<p><a href=\"http:\/\/ringo-apple-web.com\/html\/simple_stamp1.html\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/ringo-apple-web.com\/html\/simple_stamp1.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>if\u6587\u3068switch\u6587\u306e\u5fa9\u7fd2 \u30af\u30ea\u30c3\u30af\u3057\u305f\u5834\u6240\u306b\u5186\u306a\u3069\u306e\u56f3\u5f62\u3092\u63cf\u3044\u3066\u307f\u3088\u3046 http:\/\/ringo-apple-web.com\/html\/simple_stamp1.html<\/p>\n","protected":false},"author":1,"featured_media":383,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[25],"tags":[],"_links":{"self":[{"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=\/wp\/v2\/posts\/924"}],"collection":[{"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=924"}],"version-history":[{"count":3,"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=\/wp\/v2\/posts\/924\/revisions"}],"predecessor-version":[{"id":930,"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=\/wp\/v2\/posts\/924\/revisions\/930"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=\/wp\/v2\/media\/383"}],"wp:attachment":[{"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=924"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ringo-apple-web.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}