Status: [FINISHED]
Version: 1.0
In the post [Official Flower Grove Topic] I said I would upload the code, but in the end I decided to create a post explaining how it goes with the code.
You’re going to need the “Ring of Flowers” and have unlocked the level “Mountain Flower Grove”.
Message Flower Box Code v1.0 **NEW!!!**
// Message Flower Box v1.0
// By Mini Gru
// Write your message with flowers.
// Set your text in "textToWrite" var and pick up a color for each character.
// Advance Config: Text size, text spacing, text area and number of cols and rows.
// Characters suported:
// A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
// " ", ".", ",", ?, !, -, +
// Characters in pogress:
// Ñ, Ç
// < , >, ;, :, =, /, *, _, ', "(", ")"
// BASIC CONFIG //
var textToWrite = "MESSAGE FLOWER BOX V1.0"; // Text to write with flowers.
var charColors = ["pink", "blue", "random", "purple", "red"]; // Flowers Colors. Can be only one color or you can define a loop of colors. Colors: "random", "pink", "red", "blue", "purple", "yellow", or "white".
// ADV CONFIG //
// Text Size. Character width is calculated ([textSize] * [charWidthRatio]).
var textSize = 8; // Default: 8.
var charWidthRatio = 0.65; // Default: 0.65.
// Text Area. Calc the text area with coords corners "A" and "B"
var cornerA = {"x": 153, "y": 123}; // Default for Flower Grove Level: {"x": 153, "y": 123}.
var cornerB = {"x": 16, "y": 23}; // Default for Flower Grove Level: {"x": 16, "y": 23}.
// Number of Cols and Rows
var displayCols = 10; // Default: 10.
var displayRows = 3; // Default: 3.
// Character Spacing
var hSpacing = 0; // Default: 0.
var vSpacing = 5; // Default: 5.
// FUNCTIONS //
// drawCharacter function: Writes the [character] at given [X] and [Y] coords whith "n" size (height)
this.drawCharacter = function(character, x, y, size, color){
var vSize = size;
var hSize = size * charWidthRatio;
var vHalfSize = vSize / 2;
var hHalfSize = hSize / 2;
var vQuarterSize = vSize / 4;
var hQuarterSize = hSize / 4;
var angle = 0;
this.toggleFlowers(false);
this.setFlowerColor(color);
// "A" character
if(character == "A"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x, y + vHalfSize);
this.moveXY(x + hHalfSize, y - vHalfSize);
this.toggleFlowers(false);
this.moveXY(x - (hHalfSize), y - (vHalfSize/2));
this.toggleFlowers(true);
this.moveXY(x + (hHalfSize), y - (vHalfSize/2));
}
// "B" character
else if(character == "B"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.moveXY(x, y + vHalfSize);
angle = Math.PI / 2;
while (angle >= -(Math.PI/2)){
newX = x + ((hHalfSize/2) * Math.cos(angle));
newY = (y + (vHalfSize/2)) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
this.moveXY(x - hHalfSize, y);
this.toggleFlowers(false);
this.moveXY(x, y);
this.toggleFlowers(true);
angle = Math.PI / 2;
while (angle >= -(Math.PI/2)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = (y - (vHalfSize/2)) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
this.moveXY(x - hHalfSize, y - vHalfSize);
}
// "C" character
else if(character == "C"){
angle = Math.PI / 4;
this.moveXY(x + ((hHalfSize/2) * Math.cos(angle)), (y + (vHalfSize/2)) + ((vHalfSize/2) * Math.sin(angle)));
this.toggleFlowers(true);
while (angle <= ((3 * Math.PI)/2) + (Math.PI/4) ){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + ((vHalfSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
}
// "D" character
else if(character == "D"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.moveXY(x, y + vHalfSize);
angle = Math.PI / 2;
while (angle >= -(Math.PI/2)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + ((vHalfSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
this.moveXY(x - hHalfSize, y - vHalfSize);
}
// "E" character
else if(character == "E"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.toggleFlowers(false);
this.moveXY(x - hHalfSize, y);
this.toggleFlowers(true);
this.moveXY(x, y);
this.toggleFlowers(false);
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "F" character
else if(character == "F"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.toggleFlowers(false);
this.moveXY(x - hHalfSize, y);
this.toggleFlowers(true);
this.moveXY(x, y);
}
// "G" character
else if(character == "G"){
angle = Math.PI / 2;
this.moveXY(x + hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x, y + vHalfSize);
while (angle <= 3 * Math.PI / 2){
var newX = x + (hHalfSize * Math.cos(angle));
var newY = y + (vHalfSize * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.2;
}
this.moveXY(x + hHalfSize, y - vHalfSize);
this.moveXY(x + hHalfSize, y);
this.moveXY(x, y);
}
// "H" character
else if(character == "H"){
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(false);
this.moveXY(x - hHalfSize, y);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y);
this.toggleFlowers(false);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "I" character
else if(character == "I"){
this.moveXY(x - hQuarterSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hQuarterSize, y - vHalfSize);
this.toggleFlowers(false);
this.moveXY(x, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x, y + vHalfSize);
this.toggleFlowers(false);
this.moveXY(x - hQuarterSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hQuarterSize, y + vHalfSize);
}
// "J" character
else if(character == "J"){
this.moveXY(x - hHalfSize, y);
angle = Math.PI;
this.moveXY(x + (hHalfSize * Math.cos(angle)), y + (vHalfSize * Math.sin(angle)));
this.toggleFlowers(true);
while (angle <= 2 * Math.PI ){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + ((vHalfSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
this.moveXY(x + hHalfSize, y + vHalfSize);
}
// "K" character
else if(character == "K"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(false);
this.moveXY(x - hHalfSize, y);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.toggleFlowers(false);
this.moveXY(x - hHalfSize, y);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "L" character
else if(character == "L"){
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y - vHalfSize);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "M" character
else if(character == "M"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.moveXY(x, y);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "N" character
else if(character == "N"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.moveXY(x + hHalfSize, y - vHalfSize);
this.moveXY(x + hHalfSize, y + vHalfSize);
}
// "O" character
else if(character == "O"){
angle = 0;
this.moveXY(x + ((hHalfSize) * Math.cos(angle)), y + ((vHalfSize) * Math.sin(angle)));
this.toggleFlowers(true);
while (angle <= (2 * Math.PI)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + ((vHalfSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
}
// "P" character
else if(character == "P"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.moveXY(x, y + vHalfSize);
angle = Math.PI / 2;
while (angle >= -(Math.PI/2)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
this.moveXY(x - hHalfSize, y);
}
// "Q" character
else if(character == "Q"){
angle = 0;
this.moveXY(x + ((hHalfSize) * Math.cos(angle)), y + ((vHalfSize) * Math.sin(angle)));
this.toggleFlowers(true);
while (angle <= (2 * Math.PI)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + ((vHalfSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
this.toggleFlowers(false);
this.moveXY(x + hQuarterSize, y - vQuarterSize);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "R" character
else if(character == "R"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.moveXY(x, y + vHalfSize);
angle = Math.PI / 2;
while (angle >= -(Math.PI/2)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
this.moveXY(x - hHalfSize, y);
this.toggleFlowers(false);
this.moveXY(x, y);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "S" character
else if(character == "S"){
angle = 0;
this.moveXY(x + ((hHalfSize) * Math.cos(angle)), y + (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle)));
this.toggleFlowers(true);
while (angle <= (3 * Math.PI)/2){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
angle = Math.PI / 2;
while (angle >= -(Math.PI)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y - (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
}
// "T" character
else if(character == "T"){
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.toggleFlowers(false);
this.moveXY(x, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x, y - vHalfSize);
}
// "U" character
else if(character == "U"){
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y - (vHalfSize/2));
angle = Math.PI;
while (angle <= 2 * Math.PI){
newX = x + (hHalfSize * Math.cos(angle));
newY = (y - (vHalfSize/2)) + (vHalfSize/2 * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.2;
}
this.moveXY(x + hHalfSize , y + vHalfSize);
}
// "V" character
else if(character == "V"){
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x, y - vHalfSize);
this.moveXY(x + hHalfSize, y + vHalfSize);
}
// "W" character
else if(character == "W"){
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hQuarterSize, y - vHalfSize);
this.moveXY(x, y);
this.moveXY(x + hQuarterSize, y - vHalfSize);
this.moveXY(x + hHalfSize, y + vHalfSize);
}
// "X" character
else if(character == "X"){
this.moveXY(x - hHalfSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.toggleFlowers(false);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "Y" character
else if(character == "Y"){
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x, y);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.toggleFlowers(false);
this.moveXY(x, y);
this.toggleFlowers(true);
this.moveXY(x, y - vHalfSize);
}
// "Z" character
else if(character == "Z"){
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.moveXY(x - hHalfSize, y - vHalfSize);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "1" character
else if(character == "1"){
this.moveXY(x - hHalfSize, y);
this.toggleFlowers(true);
this.moveXY(x, y + vHalfSize);
this.moveXY(x, y - vHalfSize);
}
// "2" character
else if(character == "2"){
angle = Math.PI;
this.moveXY(x + ((hHalfSize) * Math.cos(angle)), y + (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle)));
this.toggleFlowers(true);
while (angle >= 0){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
this.moveXY(x - hHalfSize, y - vHalfSize);
this.moveXY(x + hHalfSize, y - vHalfSize);
}
// "3" character
else if(character == "3"){
angle = Math.PI;
this.moveXY(x + ((hHalfSize) * Math.cos(angle)), y + (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle)));
this.toggleFlowers(true);
while (angle >= -(Math.PI/2)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
angle = Math.PI/2;
while (angle >= -(Math.PI)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y - (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
}
// "4" character
else if(character == "4"){
this.moveXY(x + hQuarterSize, y - vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hQuarterSize, y + vHalfSize);
this.moveXY(x - hHalfSize, y - vQuarterSize/2);
this.moveXY(x + hHalfSize, y - vQuarterSize/2);
}
// "5" character
else if(character == "5"){
this.moveXY(x + hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x - hHalfSize, y + vHalfSize);
this.moveXY(x - hHalfSize, y + (vQuarterSize/2));
this.moveXY(x, y + (vQuarterSize/2));
angle = Math.PI / 2;
while (angle >= -(Math.PI)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y - (vQuarterSize - (vQuarterSize/4)) + ((vQuarterSize + (vQuarterSize/4)) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
}
// "6" character
else if(character == "6"){
this.moveXY(x - hHalfSize, y - vQuarterSize);
this.toggleFlowers(true);
angle = Math.PI;
while (angle >= -(Math.PI)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y - (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
this.moveXY(x - hHalfSize, y + vQuarterSize);
angle = Math.PI;
while (angle >= 0){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + (vHalfSize/2) + ((vHalfSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
}
// "7" character
else if(character == "7"){
this.moveXY(x - hHalfSize, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x + hHalfSize, y + vHalfSize);
this.moveXY(x, y - vHalfSize);
}
// "8" character
else if(character == "8"){
angle = -(Math.PI/2);
this.moveXY(x, y);
this.toggleFlowers(true);
while (angle <= (3*Math.PI)/2){
newX = x + ((hQuarterSize + hQuarterSize/2) * Math.cos(angle));
newY = y + (vQuarterSize) + ((vQuarterSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
angle = Math.PI/2;
while (angle <= (2*Math.PI)+(Math.PI/2)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y - (vQuarterSize) + ((vQuarterSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
}
// "9" character
else if(character == "9"){
this.moveXY(x + hHalfSize, y + vQuarterSize);
this.toggleFlowers(true);
angle = 0;
while (angle <= 2*Math.PI){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + (vQuarterSize) + ((vQuarterSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
this.moveXY(x + hHalfSize, y - vQuarterSize);
angle = 0;
while (angle >= -(Math.PI)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y - (vQuarterSize) + ((vQuarterSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
}
// "0" character
else if(character == "0"){
angle = 0;
this.moveXY(x + ((hHalfSize) * Math.cos(angle)), y + ((vHalfSize) * Math.sin(angle)));
this.toggleFlowers(true);
while (angle <= (2 * Math.PI)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + ((vHalfSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
angle = (Math.PI/4);
this.moveXY(x + ((hHalfSize) * Math.cos(angle)), y + ((vHalfSize) * Math.sin(angle)));
angle = (Math.PI/4)+(Math.PI);
this.moveXY(x + ((hHalfSize) * Math.cos(angle)), y + ((vHalfSize) * Math.sin(angle)));
}
// "+" character
else if(character == "+"){
this.moveXY(x - vQuarterSize, y);
this.toggleFlowers(true);
this.moveXY(x + vQuarterSize, y);
this.toggleFlowers(false);
this.moveXY(x, y + vQuarterSize);
this.toggleFlowers(true);
this.moveXY(x, y - vQuarterSize);
}
// "-" character
else if(character == "-"){
this.moveXY(x - vQuarterSize, y);
this.toggleFlowers(true);
this.moveXY(x + vQuarterSize, y);
}
// "?" character
else if(character == "?"){
this.moveXY(x - hHalfSize, y + vQuarterSize);
this.toggleFlowers(true);
angle = Math.PI;
while(angle >= -(Math.PI/2)){
newX = x + ((hHalfSize) * Math.cos(angle));
newY = y + (vQuarterSize) + ((vQuarterSize) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
this.moveXY(x, y - vQuarterSize);
this.toggleFlowers(false);
this.moveXY(x, y - (vQuarterSize + vQuarterSize/2));
this.toggleFlowers(true);
this.moveXY(x, y - vHalfSize);
}
// "!" character
else if(character == "!"){
this.moveXY(x, y + vHalfSize);
this.toggleFlowers(true);
this.moveXY(x, y - vQuarterSize);
this.toggleFlowers(false);
this.moveXY(x, y - (vQuarterSize + vQuarterSize/2));
this.toggleFlowers(true);
this.moveXY(x, y - vHalfSize);
}
// "." character
else if(character == "."){
this.moveXY(x, y - vHalfSize);
this.toggleFlowers(true);
angle = -(Math.PI/2);
while(angle <= (3*Math.PI/2)){
newX = x + ((vQuarterSize/4) * Math.cos(angle));
newY = y - (vHalfSize - vQuarterSize/4) + ((vQuarterSize/4) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
}
// "," character
else if(character == ","){
angle = Math.PI/2;
this.moveXY(x, y - (vQuarterSize + vQuarterSize/4))
this.toggleFlowers(true);
while(angle <= (2*Math.PI) + (Math.PI/2)){
newX = x + ((vQuarterSize/4) * Math.cos(angle));
newY = y - (vQuarterSize + vQuarterSize/4) + ((vQuarterSize/4) * Math.sin(angle));
this.moveXY(newX, newY);
angle += 0.1;
}
angle = Math.PI/2;
while(angle >= -(Math.PI/2)){
newX = x + ((vQuarterSize/4) * Math.cos(angle));
newY = y - (vQuarterSize + vQuarterSize/2) + ((vQuarterSize/2) * Math.sin(angle));
this.moveXY(newX, newY);
angle -= 0.1;
}
}
else {
this.say("ERROR, I CAN'T WRITE THAT CHARACTER!");
}
this.toggleFlowers(false);
};
// printText function: Splits the text into an array, and prints each character.
this.printText = function(text){
var splTxt = text.split("");
for(var i=0;i<splTxt.length;i++){
var charToDraw = splTxt[i];
// If character position x it's greater than the space calculated, go to the next row and set initial position for x.
if(charPosX > ((firstCharPosX) + (textSize*(displayCols-1)))){
charPosY -= (textSize + vSpacing);
charPosX = firstCharPosX;
}
// If it is a space " ", increment char x position and continue.
if(charToDraw == " "){
charPosX += textSize;
continue;
} else {
// drawCharacter Function, givin the character to draw, the XY postion, and text size.
var charColor = charColors[i % charColors.length];
this.drawCharacter(charToDraw, charPosX, charPosY, textSize, charColor);
}
charPosX += textSize;
}
this.moveXY(charPosX, charPosY);
};
// Text Area Definition //
if(cornerA.x > cornerB.x){
var maxWidth = cornerA.x - cornerB.x;
} else {
maxWidth = cornerB.x - cornerA.x;
}
if(cornerA.y > cornerB.y){
var maxHeight = cornerA.y - cornerB.y;
} else {
maxHeight = cornerB.y - cornerA.y;
}
var widthNeeded = (textSize*displayCols)+(hSpacing*(displayCols-1));
var heightNeeded = (textSize*displayRows)+(vSpacing*(displayRows-1));
// VERIFICATION //
var errorMsg = [];
var charError = false;
var sizeError = false;
var colorError = false;
var validated = false;
var charList = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", " ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "+", "-", "?", "!", ".", ","];
var colorList = ["random", "pink", "red", "blue", "purple", "yellow", "white"]
var splitText = textToWrite.split("");
// Character verification
for(var k=0;k<splitText.length;k++){
if(charList.indexOf(splitText[k]) == -1){
errorMsg.push("ERROR, I can't write the character: " + splitText[k]);
charError = true;
}
}
// Color verification
for(var c=0;c<charColors.length;c++){
if(colorList.indexOf(charColors[c]) == -1){
errorMsg.push("ERROR, color " + charColors[c] + " dosn't exist. Pick up another color.");
colorError = true;
}
}
// Width and Height verification
if(widthNeeded > maxWidth){
errorMsg.push("ERROR, the calculated width needed is greater than text area. Change the text size or total cols.");
sizeError = true;
}
if(heightNeeded > maxHeight){
errorMsg.push("ERROR, the calculated height needed is greater than text area. Change the text size or total rows.");
sizeError = true;
}
// Validate if there is no error
if(!charError && !sizeError && !colorError){
validated = true;
var centerDisplayX = cornerB.x + (maxWidth/2);
var centerDisplayY = cornerB.y + (maxHeight/2);
var firstCharPosX = centerDisplayX - ((widthNeeded/2)-((textSize * charWidthRatio ) /2));
var firstCharPosY = centerDisplayY + ((heightNeeded/2) - (textSize/2));
var charPosX = firstCharPosX;
var charPosY = firstCharPosY;
}
// PRINT TEXT //
// If text is validated, print text.
if(validated){
this.printText(textToWrite);
} else {
this.say("We've got problems, my lord:");
for(var m=0;m<errorMsg.length;m++){
this.say(errorMsg[m]);
this.wait(1);
}
}
this.say("Finish, my lord.");
The code is quite simple, but long as the character drawing function is very long.
Quick Installation:
1.- Copy the code.
2.- Past it in Mountain Flower Grove level.
3.- Write your text in the basic configuration.
4.- Choose the text color.
5.- Run the code!
In “ADV CONFIGURATION” you can modify the text size, height/width proportion, text spacing, text area and number of cols and rows.
The code checks the data entered in “ADV CONFIGURATION” and returns the errors if any.
Supported characters:
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
1, 2, 3, 4, 5, 6, 7, 8, 9, 0
" ", “.”, ?, !, -, +
Character in progress:
Ñ, Ç
< , >, ;, :, =, /, *, _, ', “(”, “)”
To-Do List:
* Option to color each character from an array, givin a sequence of colors.
- Add new characters (in progress)
- An option to put all the text in a flower box
- Clean the code (like always…)
Any idea, correction and/or contribution is appreciated.
See you around!
ChangeLog v1.0
*First completed version.
*Option to color each character from an array, givin a sequence of colors.
*Added numbers and some symbols: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 , “.”, “,”, ?, !, -, +
ChangeLog v0.3
*First public realease.
*Supported characters: A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, " ".
*Text area definition.
*Text size and text spacing options.
More screenshots
1# UPTADE (24 Dec 2015): New version of code. See changelog.