Skip to content

Commit

Permalink
Make it possible to save creations
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhg committed Jun 24, 2018
1 parent cd99354 commit c4b047d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
9 changes: 3 additions & 6 deletions 1/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { any, compose, either, min, __ } from 'ramda'
import { any, compose, either, __ } from 'ramda'
import { padding } from '../common/bounds'
import { createCanvas } from '../common/canvas'
import { coordsDistance } from '../common/core'
import { createShapeFiller } from '../common/shapeFiller'

const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
const size = min(640, window.innerWidth)
const { canvas, context } = createCanvas()

document.body.appendChild(canvas)
canvas.width = size
canvas.height = size

const drawCircle = context => ({ coords, radius }) => {
context.beginPath()
Expand Down
8 changes: 2 additions & 6 deletions 2/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { min } from 'ramda'
import { padding } from '../common/bounds'
import { createCanvas } from '../common/canvas'
import { createShapeFiller } from '../common/shapeFiller'
import {
cannotGrow,
Expand All @@ -10,13 +10,9 @@ import {
squareArea,
} from '../common/squares'

const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
const size = min(640, window.innerWidth)
const { canvas, context } = createCanvas()

document.body.appendChild(canvas)
canvas.width = size
canvas.height = size

createShapeFiller({
backgroundColor: '#0b0b0b',
Expand Down
8 changes: 2 additions & 6 deletions 3/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { min } from 'ramda'
import { padding } from '../common/bounds'
import { createCanvas } from '../common/canvas'
import { createShapeFiller } from '../common/shapeFiller'
import {
cannotGrow,
Expand All @@ -10,13 +10,9 @@ import {
squareArea,
} from '../common/squares'

const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
const size = min(640, window.innerWidth)
const { canvas, context } = createCanvas()

document.body.appendChild(canvas)
canvas.width = size
canvas.height = size

createShapeFiller({
backgroundColor: '#ffffff',
Expand Down
19 changes: 19 additions & 0 deletions common/canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { min } from 'ramda'

export const createCanvas = () => {
const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
const size = min(640, window.innerWidth)

canvas.width = size
canvas.height = size

canvas.addEventListener('click', () => {
const link = document.createElement('a')
link.download = Date.now()
link.href = canvas.toDataURL()
link.click()
})

return { canvas, context }
}

0 comments on commit c4b047d

Please sign in to comment.