mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
35 lines
1.1 KiB
HTML
35 lines
1.1 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<title>Stars</title>
|
||
|
<link rel="stylesheet" href="../css/style.css">
|
||
|
<script type="text/javascript" src="../../dist/paper.js"></script>
|
||
|
<script type="text/javascript" src="../../src/svg/ExportSVG.js"></script>
|
||
|
<script type="text/paperscript" canvas="canvas">
|
||
|
function onMouseDown(event) {
|
||
|
var hue = Math.random() * 360;
|
||
|
project.currentStyle.fillColor = new HsbColor(hue, 1, 1);
|
||
|
}
|
||
|
|
||
|
function onMouseDrag(event) {
|
||
|
var delta = event.point - event.downPoint;
|
||
|
var radius = delta.length;
|
||
|
var points = 5 + Math.round(radius / 50);
|
||
|
var position = event.downPoint;
|
||
|
var path = new Path.Star(position, points, radius / 2, radius);
|
||
|
var svg = new ExportSVG();
|
||
|
var svgout = svg.exportPath(path);
|
||
|
console.log(svgout);
|
||
|
path.rotate(delta.angle);
|
||
|
// Remove the path automatically before the next mouse drag
|
||
|
// event:
|
||
|
path.removeOnDrag();
|
||
|
}
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<canvas id="canvas" resize></canvas>
|
||
|
</body>
|
||
|
</html>
|