Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
cycle-canvas
Advanced tools
A canvas driver for Cycle.js. Great for games or art.
Currently highly experimental. Expect major breaking changes.
$ npm install cycle-canvas --save
import {run} from '@cycle/core';
import {makeCanvasDriver, rect, text} from 'cycle-canvas';
import {Observable} from 'rx';
function main () {
return {
Canvas: Observable.just(
rect({
x: 10,
y: 10,
width: 160,
height: 100,
draw: [
{fill: 'purple'}
],
children: [
text({
x: 15,
y: 25,
value: 'Hello World!',
font: '18pt Arial',
draw: [
{fill: 'white'}
]
})
]
})
)
};
}
const drivers = {
Canvas: makeCanvasDriver(null, {width: 800, height: 600})
};
run(main, drivers);
Looks like this:
Also check out the flappy bird example.
You can find the source for flappy bird here.
##API
rect(params = {})
Draws a rectangle given an object containing drawing parameters.
x: number
The x axis for the starting point.y: number
The y axis for the starting point.width: number
The rectangles width.heigh: number
The rectangles height.draw: array
List of drawing operation objects.
fill: string
The color or style to use inside the rectangle. Default is black #000.stroke: string
The color or style to use as the stroke style. Default is black #000.clear: boolean
Sets all pixels in the rectangle to transparent.children: array
List of child drawing shapes or text. This property is optional.rect({
x: 10,
y: 10,
width: 100,
height: 100,
draw: [
{fill: 'purple'}
],
children: [
rect({
x: 20,
y: 20,
width: 50,
height: 50,
draw: [
{fill: 'blue'}
]
})
]
})
line(params = {})
Draws line(s) given an object containing drawing parameters.
x: number
The x axis for the starting point.y: number
The y axis for the starting point.style: object
The style properties.
lineWidth: number
The width of the line. Default is 1.lineCap: string
The end point of the line. Default is butt. Possible values are butt, round and square.lineJoin: string
The type of corner created when two lines meet. Default is miter. Possible values are miter, round and bevel.strokeStyle: string
The color or style to use as the stroke style. Default is black #000.lineDash: array
A list of numbers that specifies the line dash pattern.points: array
List of point objects that specify the x/y coordinates for each point.children: array
List of child drawing shapes or text. This property is optional.line({
x: 10,
y: 10,
style: {
lineWidth: 2,
lineCap: 'square',
strokeStyle: '#CCCCCC'
},
points: [
{x: 10, y: 10},
{x: 10, y: 20},
{x: 20, y: 10},
{x: 10, y: 10}
]
})
text(options = {})
Draws text given an object containing drawing parameters.
x: number
The x axis for the starting point.y: number
The y axis for the starting point.value: string
The text to draw.font: string
The text style. Uses same syntax as the CSS font property.draw: array
List of drawing operations objects.
fill: string
The color or style to fill the text. Default is black #000.stroke: string
The color or style to use as the stroke style. Default is black #000.children: array
List of child drawing shapes or text. This property is optional.text({
x: 10,
y: 10,
value: 'Hello World!',
font: '18pt Arial',
draw: [
{fill: 'white'}
]
})
##Transformations
Transformations are added as a list to the transformations
attribute to drawing shapes and text.
translate: {x: number, y: number}
Moves the canvas origin to a different point.
rect({
transformations: [
{translate: {x: 10, y: 10}}
],
x: 100,
y: 100,
width: 150,
height: 150,
draw: [
{fill: 'purple'}
]
})
rotate: number
Roate the canvas around the current origin.
rect({
transformations: [
{rotate: (20*Math.PI/180)}
],
x: 10,
y: 10,
width: 150,
height: 150,
draw: [
{fill: 'purple'}
]
})
scale: {x: number, y: number}
Scales the drawing bigger or smaller.
rect({
transformations: [
{scale: {x: 2, y: 2}},
],
x: 10,
y: 10,
width: 150,
height: 150,
draw: [
{fill: 'purple'}
]
})
Rotate aroung the point (100, 100) and draw a 50x50px box centered there:
rect({
transformations: [
{translate: {x: 100, y: 100}},
{rotate: (20*Math.PI/180)}
],
x: -25, // At this point, {x: 0, y: 0} is a point on position {x: 100, y: 100} of the canvas
y: -25,
width: 50,
height: 50,
draw: [
{fill: 'purple'}
]
})
FAQs
A canvas driver for Cycle.js
The npm package cycle-canvas receives a total of 7 weekly downloads. As such, cycle-canvas popularity was classified as not popular.
We found that cycle-canvas demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.