[Mountain Flower Grove] Flower Text Box


#1

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.


Official Flower Grove Topic
Official Flower Grove Topic
#2

Wow awesome! This is great!


#3

Thanx @Wiilli! ^^

New UPDATE: New version of code:

  • Added numbers and some symbols
  • Option to color each character

Merry Christmas!


#4

Wow, this is pretty amazing! Nice!

Anything we can do to make the flower-drawing mechanic work better and let you do other things that ended up being frustrating to do while you were working on this?


#5

Nice idea! But why not store the letters as vectors? For example:

A = [ (0, 0, False), (0.5, 1, True), (1, 0, True), (0, 0.25, False), (1, 0.25, True) ]

Obviously, the arcs would need to be substituted by shorter straights, or managed some other way, but that would make the code much shorter and easier to add new letters/symbols.

I’ll probably try to make it myself :wink:


#6

Great idea! I only made 4 letters, plus a heart, but I had the same thought. I made my functions so you could set size and x,y center for each character. My heart function is as follows:

this.drawHeart = function(x,y,size) {
    this.setFlowerColor("red");
    var angle = 0;
    this.toggleFlowers(false);
    while (angle <= Math.PI * 1) {
        var newX = x + size + (size * Math.cos(angle));
        var newY = y + size + (size * Math.sin(angle));
        this.moveXY(newX, newY);
        this.toggleFlowers(true);
        angle += 0.2;
    }
    angle = 0;
    while (angle <= Math.PI * 1) {
        newX = x - size + (size * Math.cos(angle));
        newY = y + size + (size * Math.sin(angle));
        this.moveXY(newX, newY);
        this.toggleFlowers(true);
        angle += 0.2;
    }
    this.moveXY(x, y - size * 2);
    this.moveXY(x + size*2, y + size + (size * Math.sin(angle)));
    this.toggleFlowers(false);
};

And the final result was to show my wife:


#7

In the spirit of “release early, release often”, here is my go at the same thing in python, with a “vectorized” fontset. Thanks @MiniGru for the inspiration! :smile:

I used the forest flower grove level to test

Message Flower Box redux in python
# TEXT TO WRITE
text = "five wixen"

#self.setFlowerColor("red")
# options: "random" (default), "pink", "red", "blue", "purple", "yellow" or "white"

# settings
start = Vector(10, 90)
fontHeight  = 20
fontWidth   = fontHeight * 1/2
fontSpacing = fontWidth  * 1/4
lineSpacing = fontHeight * 1/5

# vector fontset - INCOMPLETE
fontSet = {
    # font format:
    # "letter": [ (nextPosX, nextPosY, draw), ... ]
    # note: 'draw' is optional, if it's not defined, the last value is used (= unchanged)
    "A": [ (0, 0, 0), (1/2, 1, 1), (1, 0, 1), (5/6, 1/3, 0), (1/6, 1/3, 1) ],
    "B": [ (0, 0, 0), (0, 1, 1), (3/4, 1, 1), (1, 5/6, 1), (1, 4/6, 1),  (5/6, 1/2, 1), (0, 1/2, 1), (5/6, 1/2, 0), (1, 2/6, 1), (1, 1/6, 1), (5/6, 0, 1), (0, 0, 1) ],
#   'lazy' format example:
#    "B": [(0, 0, 0), (0, 1, 1), (3/4, 1), (1, 5/6), (1, 4/6), (5/6, 1/2), (0, 1/2), (5/6, 1/2, 0), (1, 2/6, 1), (1, 1/6), (5/6, 0), (0, 0)],
#    "C": [ (, , ) ],
#    "D": [ (, , ) ],
    "E": [ (1, 0, 0), (0, 0, 1), (0, 1, 1), (1, 1, 1), (0, 1/2, 0), (3/4, 1/2, 1) ],
    "F": [ (0, 0, 0), (0, 1, 1), (1, 1, 1), (0, 1/2, 0), (3/4, 1/2, 1) ],
#    "G": [ (, , ) ],
    "H": [ (0, 0, 0), (0, 1, 1), (0, 1/2, 0), (1, 1/2, 1), (1, 1, 0), (1, 0, 1) ],
    "I": [ (0, 0, 0), (0, 1, 1) ],
#    "J": [ (, , ) ],
    "K": [ (0, 0, 0), (0, 1, 1), (0, 1/2, 0), (1, 1, 1), (0, 1/2, 0), (1, 0, 1) ],
    "L": [ (0, 1, 0), (0, 0, 1), (1, 0, 1) ],
    "M": [ (0, 0, 0), (0, 1, 1), (1/2, 1/2, 1), (1, 1, 1), (1, 0, 1)],
    "N": [ (0, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 1) ],
#    "O": [ (, , ) ],
#    "P": [ (, , ) ],
#    "Q": [ (, , ) ],
#    "R": [ (, , ) ],
#    "S": [ (, , ) ],
    "T": [ (0, 1, 0), (1, 1, 1), (1/2, 1, 0), (1/2, 0, 1) ],
#    "U": [ (, , ) ],
    "V": [ (0, 1, 0), (1/2, 0, 1), (1, 1, 0) ],
    "W": [ (0, 1, 0), (1/3, 0, 1), (2/3, 1/2, 1), (1, 0, 1), (4/3, 1, 1) ],
    "X": [ (0, 0, 0), (1, 1, 1), (0, 1, 0), (1, 0, 1) ],
    "Y": [ (0, 1, 0), (1/2, 1/2, 1), (1, 1, 1), (1/2, 1/2, 0), (1/2, 0, 1) ],
    "Z": [ (0, 1, 0), (1, 1, 1), (0, 0, 1), (1, 0, 1) ],
    " ": [ (1, 0, 0) ]
    }

# make text uppercase
text = text.toUpperCase()              # workaround for 'text.upper()'

self.toggleFlowers(False)              # turn off flowers at start


# draw a letter
def writeLetter(char):
    if char not in fontSet:
        self.say("Letter " + char + " is not defined!")
        return
    
    corner = Vector(self.pos.x, baseLine)
    maxWidth = 0
    
    for point in fontSet[char]:
        #self.say(point)
#        # turn flowers on/off
#        self.toggleFlowers(point[2])
        if len(point) > 2:
            if point[2]:    # == 1
                self.toggleFlowers(True)
            else:           # == 0
                self.toggleFlowers(False)
        
        # draw next segment
        self.moveXY(corner.x + point[0] * fontWidth, corner.y + point[1] * fontHeight)
        # proportional font support
        if point[0] > maxWidth:
            maxWidth = point[0]
    
    self.toggleFlowers(False)
    self.moveXY(corner.x + maxWidth * fontWidth + fontSpacing, corner.y)


#### main() ####
self.say("I will write: " + text)

self.moveXY(start.x, start.y)          # move to starting position
baseLine = start.y

for i in range(len(text)):
    self.say(text[i])
    writeLetter(text[i])

Usage:

  • copy and paste into a flower grove level
  • update the text to write
  • update settings (optional)
  • run the code

Supported characters:

  • A-Z, with most rounded characters missing (C, S, O, etc.)
  • “B” is defined using lines instead of arcs, as a test

Todo:

  • simple arc drawing (using vectors?)
  • multiline support
  • code cleanup