// Author: Jidong Xiao
// first we need to create a stage
var stage = new Konva.Stage({
container: 'container', // id of container
width: 2000,
height: 1000
});
// Create a layer
var layer = new Konva.Layer();
stage.add(layer);
// Create a function to draw nodes
function drawNode(x, y, label) {
var circle = new Konva.Circle({
x: x,
y: y,
id: 'node_'+label,
radius: 40,
fill: 'lightgray',
stroke: 'black',
strokeWidth: 1
});
layer.add(circle);
var text = new Konva.Text({
x: x-5,
y: y-10,
id: 'node_text_'+label,
text: label,
fontSize: 20,
fontFamily: 'Calibri',
fill: 'black'
});
layer.add(text);
}
// Draw lines connecting nodes
var line1 = new Konva.Line({
points: [645, 100, 520, 180],
//points: [650, 100, 450, 200, 650, 100, 850, 200],
stroke: 'black',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'
});
var line2 = new Konva.Line({
points: [655, 100, 780, 180],
stroke: 'black',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'
});
var arrow1 = new Konva.Arrow({
points: [925, 200, 1150, 200],
pointerLength: 10,
pointerWidth: 10,
id: "arrow1",
fill: 'green',
stroke: 'green',
strokeWidth: 5,
});
var line3 = new Konva.Line({
//points: [450, 200, 350, 300, 450, 200, 550, 300],
points: [495, 200, 378, 272],
stroke: 'black',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'
});
var line4 = new Konva.Line({
points: [505, 200, 572, 272],
stroke: 'black',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'
});
var line5 = new Konva.Line({
// points: [850, 200, 750, 300, 850, 200, 950, 300],
points: [795, 200, 700, 300],
stroke: 'black',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'
});
var arrow2 = new Konva.Arrow({
points: [1000, 300, 1150, 300],
pointerLength: 10,
pointerWidth: 10,
id: "arrow2",
fill: 'green',
stroke: 'green',
strokeWidth: 5,
});
var line6 = new Konva.Line({
// points: [350, 300, 300, 400, 350, 300, 400, 400],
points: [345, 300, 200, 400],
stroke: 'black',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'
});
var line7 = new Konva.Line({
points: [705, 300, 800, 400],
stroke: 'black',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'
});
var line8 = new Konva.Line({
points: [805, 200, 916, 276],
stroke: 'black',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'
});
var line9 = new Konva.Line({
points: [950, 300, 900, 400, 950, 300, 1000, 400],
stroke: 'black',
strokeWidth: 1,
lineCap: 'round',
lineJoin: 'round'
});
var arrow3 = new Konva.Arrow({
points: [1050, 400, 1150, 400],
pointerLength: 10,
pointerWidth: 10,
id: "arrow3",
fill: 'green',
stroke: 'green',
strokeWidth: 5,
});
// Create a dotted line
var dottedLine = new Konva.Line({
points: [300, 400, 200, 600],
stroke: 'black',
strokeWidth: 2,
dash: [5, 5]
});
var dottedLine2 = new Konva.Line({
points: [1000, 400, 1050, 600],
stroke: 'black',
strokeWidth: 2,
dash: [5, 5]
});
var arrow4 = new Konva.Arrow({
points: [1070, 600, 1150, 600],
pointerLength: 10,
pointerWidth: 10,
id: "arrow4",
fill: 'green',
stroke: 'green',
strokeWidth: 5,
});
var messageBox = new Konva.Rect({
x: 150,
y: 650,
width: 800,
height: 60,
fill: 'lightblue',
stroke: 'black',
strokeWidth: 4
});
var arrow = new Konva.Arrow({
x: messageBox.x() + messageBox.width() / 2,
y: messageBox.y(),
points: [0, 0, 0, -150],
pointerLength: 20,
pointerWidth: 20,
fill: 'black',
stroke: 'black',
strokeWidth: 4
});
var messageText = new Konva.Text({
x: messageBox.x() + 10,
y: messageBox.y() + 20,
text: 'In summary, T(n) = (2^0+2^1+2^2+2^3+...+2^(n-2)) * C = O(2^(n-1)) = O((2^n)/2) = O(2^n)',
fontSize: 20,
fontFamily: 'Calibri',
fill: 'black'
});
function makeBuffer(xstart,ystart,bufferSize,w,h) {
for(let i=0;i