Alexander Deplov

Draw rects and circles

Draw rects and circles

Code

var bg = new Path.Rectangle({
    size: view.bounds,
    fillColor: 'black'
})

var tempRect

function createSmallP(point, color){
  var circle = new Path.Circle({
    radius: 4,
    fillColor: color,
    center: point
  })
}

var line = new Path.Line({
  from: [0,0],
  to: [0, 0],
  strokeColor: 'blue'
})

function onMouseDrag(event) {
	var point = event.point
	var downPoint = event.downPoint

  if (tempRect)
    tempRect.remove()

  tempRect = new Path.Rectangle({
    from: point,
    to: downPoint,
    strokeColor: 'green'
  })

  line.segments[0].point = point
  line.segments[1].point = downPoint

  line.opacity = 1

}


function onMouseUp(event) {
	var point = event.point
	var downPoint = event.downPoint
  createRect(point, downPoint)

  line.tweenTo({
    'opacity': 0
  }, 300)

}

function createRect(start, end){
  var path = new Path.Rectangle({
    from: start,
    to: end,
    strokeColor: new Color.random,
    strokeWidth: 3
  })

  var circle = new Path.Circle({
    radius: 20,
    strokeColor: Color.random(),
    center: view.center
  })
  circle.fitBounds(path.bounds)
}

function createPoint(coordinate, fillColor){
	var path = new Path.Circle({
		radius: 15,
		fillColor: fillColor,
		center: coordinate
	})
}