Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Проверка рисования на холсте PaperJS</title>
- <script type="text/javascript" scr="dist/paper-core.min.js"></script>
- <script src="http://paperjs.org/assets/js/paper.js"></script>
- <script
- src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
- integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs="
- crossorigin="anonymous"></script>
- <style type="text/css">
- html,
- body {
- height: 100%;
- }
- /* Scale canvas with resize attribute to full size */
- canvas[resize] {
- width: 100%;
- height: 100%;
- }
- .color_item{
- border: 1px solid black;
- border-collapse: collapse;
- }
- </style>
- <!--
- <script>
- function clearAll(){
- var canv = document.getElementById("canvas-1");
- //paper.setup("canvas-1");
- var path = new paper.Path();
- path.strokeColor = 'black';
- var pointOne = new paper.Point(100, 20);
- var pointTwo = new paper.Point(-100, 100);
- var pointThree = new paper.Point(300, 30);
- path.moveTo(pointOne);
- path.lineTo(pointOne.add(pointTwo));
- path.lineTo(pointTwo.add(pointThree));
- path.lineTo(pointOne.add(pointThree));
- path.closed = true;
- //paper.view.draw();
- console.log(paper);
- //paper.view.clear();
- }
- </script>
- -->
- <script type="text/paperscript" canvas="canvas-1">
- function print(text){
- console.log(text);
- }
- var path;
- var items = [];
- var deleted_items = [];
- var strokeColor = 'orange';
- var strokeWidth = '2';
- var strokeColor2 = 'red';
- var strokeWidth2 = '20';
- var textItem = new PointText({
- content: 'Click and drag to draw a line.',
- point: new Point(20, 30),
- fillColor: strokeColor,
- });
- function clearAll(){
- project.activeLayer.removeChildren();
- }
- function onMouseDown(event) {
- print(event.event.button);
- if (event.event.button == 2){
- sw = strokeWidth2;
- sc = strokeColor2;
- }
- else {
- sw = strokeWidth;
- sc = strokeColor;
- }
- print(sw,sc);
- if (path) {
- path.selected = false;
- }
- path = new Path({
- segments: [event.point],
- strokeColor: sc,
- strokeWidth: sw,
- strokeCap:'round',
- });
- }
- function onMouseDrag(event) {
- path.add(event.point);
- }
- function onMouseUp(event) {
- //~ alert(event.count);
- var segmentCount = path.segments.length;
- path.simplify(3);
- items[items.length] = path;
- //~ console.log(path);
- }
- function onKeyDown(event) {
- if (event.event.ctrlKey && (event.key == "z" || event.key == "я" ) ) {
- if (items.length > 0){
- deleted_items[deleted_items.length] = items[items.length-1];
- items[items.length-1].visible = false;
- items.pop();
- }
- }
- if (event.event.ctrlKey && event.key == "y") {
- if (deleted_items.length > 0){
- items[items.length] = deleted_items[deleted_items.length-1];
- items[items.length-1].visible = true;
- deleted_items.pop();
- }
- }
- }
- function change_strokewidth(value){
- strokeWidth = value;
- }
- function change_strokecolor(value){
- strokeColor = value;
- }
- function change_strokewidth2(value){
- strokeWidth2 = value;
- }
- function change_strokecolor2(value){
- strokeColor2 = value;
- }
- document.getElementById('clearbutton').onclick = clearAll;
- document.getElementById('strokewidth').onchange = function() {
- change_strokewidth(document.getElementById('strokewidth').value);
- }
- document.getElementById('strokewidth2').onchange = function() {
- change_strokewidth2(document.getElementById('strokewidth2').value);
- }
- var color_list = document.getElementsByName('strokecolor');
- for (var i=0; i<color_list.length;i++){
- color_list[i].onclick = function(){
- change_strokecolor(this.style.backgroundColor);
- }
- }
- var color_list = document.getElementsByName('strokecolor2');
- for (var i=0; i<color_list.length;i++){
- color_list[i].onclick = function(){
- change_strokecolor2(this.style.backgroundColor);
- }
- }
- </script>
- <script>
- $(document).ready(function() {
- canv = document.getElementById('canvas-1');
- canv.addEventListener('contextmenu', e => {
- e.preventDefault();
- });
- });
- </script>
- </head>
- <body>
- <input type="button" value = "clear" id="clearbutton">
- <div>
- leftButton
- <input type="range" value = "2" id="strokewidth" minvalue="1" maxvalue="20">
- <table>
- <tr>
- <td class = "color_item" name="strokecolor" style="background-color:#ffffff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#ffbf00" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#ffff00" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#bfff00" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#80ff00" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#40ff00" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#00ff00" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#00ff40" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#00ff80" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#00ffbf" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#00ffff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#00bfff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#0080ff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#0040ff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#0000ff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#4000ff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#8000ff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#bf00ff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#ff00ff" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#ff00bf" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#ff0080" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#ff0040" >   </td>
- <td class = "color_item" name="strokecolor" style="background-color:#ff0000" >   </td>
- </table>
- </div>
- <div>
- rightButton
- <input type="range" value = "2" id="strokewidth2" minvalue="1" maxvalue="20">
- <table>
- <tr>
- <td class = "color_item" name="strokecolor2" style="background-color:#ffffff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#ffbf00" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#ffff00" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#bfff00" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#80ff00" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#40ff00" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#00ff00" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#00ff40" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#00ff80" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#00ffbf" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#00ffff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#00bfff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#0080ff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#0040ff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#0000ff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#4000ff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#8000ff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#bf00ff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#ff00ff" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#ff00bf" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#ff0080" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#ff0040" >   </td>
- <td class = "color_item" name="strokecolor2" style="background-color:#ff0000" >   </td>
- </table>
- </div>
- <canvas id="canvas-1" resize></canvas>
- </body>
- </html>
Add Comment
Please, Sign In to add comment