grid-example.js

total 0
used 0
limit 0
/* title: Grid Example categories: grid raw files: head point pointlist mouse stage ../point_src/math.js ../point_src/extras.js stroke --- A grid of points can be built through _shaping_ and existing list of points. This example doesn't use a stage, opting for a draw _canvas_ drawing, but utilising polypoint functions. pointList = PointList.generate.list(100, 0) To set the position of the grid generator, we can just edit the first point: pointList[0].set(50, 50) Then reshape internally pointList.shape.grid(pointSpread, rowCount) */ const canvas = document.getElementById('playspace'); const ctx = canvas.getContext('2d'); Point.mouse.mount(canvas) // var t = 0; // let spinSpeed = 2 let pointSpread = 55 /* Distance between points */ let rowCount = 10 /* How many items per row within the grid */ const pointList = PointList.generate.list(100, 0) /* To set the position of the grid generator, we can just edit the first point. */ pointList[0].set(50, 50) /* Then reshape internally */ pointList.shape.grid(pointSpread, rowCount) pointList.forEach(p=>{ p.radius=10 p.rotation = Math.random() * 360 }) const update = function() { ctx.beginPath() drawGrid() } const drawGrid = function(){ /* set the position of the polygon point */ // pointList[0].set(Point.mouse.position) // pointList.draw.pointLine(ctx) quickStroke('red', 1) // t = (t + 1) % 360 let mousePoint = Point.mouse.position /* Draw each point; wrapping the _draw_ call_ with our own functionality.*/ pointList.pen.points(ctx, (item,f)=>{ ctx.beginPath(); // item._rotationDegrees = item.UP + (t * spinSpeed) % 360 // item.rotation += spinSpeed item.lookAt(mousePoint) f(item) item.project().draw.lineTo(ctx, item) // item.project().draw.line(ctx, 1); quickStroke('pink', 1) }) // pointList[0].pen.ngon(ctx, 5, 90) } function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); update() requestAnimationFrame(draw); } let rect = canvas.getBoundingClientRect() ctx.canvas.width = rect.width; ctx.canvas.height = rect.height; draw()
Run
Meta Data
title Grid Example
imports ()
files ('head', 'point', 'pointlist', 'mouse', 'stage', '../point_src/math.js', '../point_src/extras.js', 'stroke')
unused_keys ()
unknown_keys ('categories',)
categories ['', 'grid', 'raw']
filepath_exists True
path grid-example.js
filepath grid-example.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/events.js', '../point_src/automouse.js', '../point_src/stage-resize.js', '../point_src/functions/resolve.js', '../point_src/stage.js', '../point_src/math.js', '../point_src/extras.js', '../point_src/setunset.js', '../point_src/stroke.js')
markdown {'html': "<hr />\n<p>A grid of points can be built through <em>shaping</em> and existing list of points.</p>\n<p>This example doesn't use a stage, opting for a draw <em>canvas</em> drawing, but utilising\npolypoint functions.</p>\n<pre><code>pointList = PointList.generate.list(100, 0)\n</code></pre>\n<p>To set the position of the grid generator, we can just edit the first point:</p>\n<pre><code>pointList[0].set(50, 50)\n</code></pre>\n<p>Then reshape internally</p>\n<pre><code>pointList.shape.grid(pointSpread, rowCount)\n</code></pre>", 'content': "title: Grid Example\ncategories:\n grid\n raw\nfiles:\n head\n point\n pointlist\n mouse\n stage\n ../point_src/math.js\n ../point_src/extras.js\n stroke\n\n---\n\nA grid of points can be built through _shaping_ and existing list of points.\n\nThis example doesn't use a stage, opting for a draw _canvas_ drawing, but utilising\npolypoint functions.\n\n pointList = PointList.generate.list(100, 0)\n\nTo set the position of the grid generator, we can just edit the first point:\n\n pointList[0].set(50, 50)\n\nThen reshape internally\n\n pointList.shape.grid(pointSpread, rowCount)"}