clip-draw-star.js

total 0
used 0
limit 0
/* title: Clip Draw Star Example files: head point pointlist stage mouse dragging ../point_src/curve-extras.js ../point_src/split.js --- Collected from mozila as an example of a clipping path: [Mozila:Compositing](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Compositing) */ function draw(ctx) { // const ctx = document.getElementById("canvas").getContext("2d"); ctx.fillRect(0, 0, 150, 150); ctx.translate(75, 75); // Create a circular clipping path ctx.beginPath(); ctx.arc(0, 0, 50, 0, Math.PI * 2, true); ctx.clip(); // Draw background const linGrad = ctx.createLinearGradient(0, -75, 0, 75); linGrad.addColorStop(0, "#232256"); linGrad.addColorStop(1, "#143778"); ctx.fillStyle = linGrad; ctx.fillRect(-75, -75, 150, 150); generateStars(ctx); } function generateStars(ctx) { for (let j = 1; j < 50; j++) { ctx.save(); ctx.fillStyle = "#fff"; ctx.translate( 75 - Math.floor(Math.random() * 150), 75 - Math.floor(Math.random() * 150), ); drawStar(ctx, Math.floor(Math.random() * 4) + 2); ctx.restore(); } } function drawStar(ctx, r) { ctx.save(); ctx.beginPath(); ctx.moveTo(r, 0); for (let i = 0; i < 9; i++) { ctx.rotate(Math.PI / 5); if (i % 2 === 0) { ctx.lineTo((r / 0.525731) * 0.200811, 0); } else { ctx.lineTo(r, 0); } } ctx.closePath(); ctx.fill(); ctx.restore(); } class MainStage extends Stage { // canvas = document.getElementById('playspace'); canvas = 'playspace' mounted(){ // this.dragging.add(this.a, this.b) } draw(ctx){ this.clear(ctx) draw(ctx) } } stage = MainStage.go(/*{ loop: true }*/)
Run
Meta Data
title Clip Draw Star Example
imports ()
files ('head', 'point', 'pointlist', 'stage', 'mouse', 'dragging', '../point_src/curve-extras.js', '../point_src/split.js')
unused_keys ()
unknown_keys ()
filepath_exists True
path clip-draw-star.js
filepath clip-draw-star.js
clean_files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/compass.js', '../point_src/center.js', '../point_src/point-content.js', '../point_src/pointdraw.js', '../point_src/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.js', '../point_src/pointlistdraw.js', '../point_src/pointlistgradient.js', '../point_src/pointlistshape.js', '../point_src/pointlistgenerator.js', '../point_src/unpack.js', '../point_src/pointlist.js', '../point_src/pointlistpen.js', '../point_src/stage-resize.js', '../point_src/functions/resolve.js', '../point_src/stage.js', '../point_src/events.js', '../point_src/automouse.js', '../point_src/functions/clamp.js', '../point_src/distances.js', '../point_src/protractor.js', '../point_src/text/beta.js', '../point_src/dragging.js', '../point_src/curve-extras.js', '../point_src/split.js')
markdown {'html': '<p>Collected from mozila as an example of a clipping path:</p>\n<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Compositing">Mozila:Compositing</a></p>', 'content': 'title: Clip Draw Star Example\nfiles:\n head\n point\n pointlist\n stage\n mouse\n dragging\n ../point_src/curve-extras.js\n ../point_src/split.js\n---\n\nCollected from mozila as an example of a clipping path:\n\n[Mozila:Compositing](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Compositing)'}