ij-macro-programming-workshop

Previous            Solution            Next

Exercise 12.02 - Define a macro set with keyboard shortcuts for each macro

Aim:

Write a macro set that contains the following macros and a keyboard shortcut for each of the macros:

Install the macros and use the keyboard shotcuts to run them. To install the macros copy the content of the file into the Text-Editor that you can open from Plugins>New>Text Window... and use the menu Macros>Install Macros of this editor. When installed they will appear under Plugins>Macros

var _X = 0;
var _Y = 0;
var _ANGLE = 0;
var _RADIUS = 20;
var _DELAY = 20;

Your code starts after this line




















Your code ends before this line

function initializeTurtle() {
	_X = getWidth() / 2;
	_Y = getHeight() / 2;
	moveTo(_X, _Y);
	makeOval(_X - (_RADIUS / 2), _Y - (_RADIUS / 2), _RADIUS, _RADIUS);
	Roi.setFillColor("green");
}

function forward(step) {
	_X += step * cos(_ANGLE * PI / 180);
	_Y += step * sin(_ANGLE * PI / 180);
	lineTo(_X, _Y);
	Roi.move(_X - (_RADIUS / 2), _Y - (_RADIUS / 2));
	wait(_DELAY);
}

function right(delta) {
	_ANGLE += delta % 360;
}

function left(delta) {
	_ANGLE -= delta % 360;
}

function spiral(side, angle, inc, count) {
	forward(side);
	right(angle);
	if (count>0) spiral(side, angle + inc, inc, count-1);
}

function dragon(size, sign, level) {
	if (level==0) forward(size);
	else {
		dragon(size, 1, level - 1);
		left(90 * sign);
		dragon(size, -1, level - 1);
	}
}

function myCurve(side, step) {
// Your code starts after this line
// Your code ends before this line
}

Previous            Solution            Next