'use strict';

function draw_logic(){
    for(var vertex in vertices){
        canvas_buffer.fillStyle = vertices[vertex]['color'];
        canvas_buffer.fillRect(
          vertices[vertex]['x'],
          vertices[vertex]['y'],
          vertices[vertex]['width'],
          vertices[vertex]['height']
        );
    }
}

function logic(){
    for(var vertex in vertices){
        vertices[vertex]['rotation'] += rotation_rate * (25 - vertices[vertex]['layer']);
        if(vertices[vertex]['rotation'] >= math_tau){
            vertices[vertex]['rotation'] -= math_tau;
        }else if(vertices[vertex]['rotation'] < 0){
            vertices[vertex]['rotation'] += math_tau;
        }

        vertices[vertex]['x'] = canvas_x_five + vertices[vertex]['layer'] * 10 * Math.cos(vertices[vertex]['rotation']);
        vertices[vertex]['y'] = canvas_y_five + vertices[vertex]['layer'] * 10 * Math.sin(vertices[vertex]['rotation']);
    }

    core_ui_update({
      'ids': {
        'rotation': rotation_rate_display,
      },
    });
}

function repo_init(){
    core_repo_init({
      'keybinds': {
        65: {
          'todo': function(){
              rotate(-.001);
          },
        },
        68: {
          'todo': function(){
              rotate(.001);
          },
        },
      },
      'title': 'QjnyYap.htm',
      'ui': '<input id=ui-rotation>Rotation',
    });
    canvas_init();

    var loop_counter = 23;
    do{
        var inner_counter = loop_counter;
        do{
            vertices.push({
              'color': '#' + core_random_hex(),
              'height': 10,
              'layer': loop_counter + 1,
              'rotation': inner_counter,
              'width': 10,
              'x': 0,
              'y': 0,
            });
        }while(inner_counter--);
    }while(loop_counter--);

    rotate(.005);
}

function resize_logic(){
    canvas_x_five = canvas_x - 5;
    canvas_y_five = canvas_y - 5;
}

function rotate(amount){
    rotation_rate += amount;
    rotation_rate_display = (rotation_rate * 1000).toFixed(0);
}

var canvas_x_five = 0;
var canvas_y_five = 0;
var rotation_rate = 0;
var rotation_rate_display = '';
var vertices = [];

@@ -43,32 +43,37 @@
 for(var 
-vertex in ver
+entity in core_enti
 ti
-c
 es)%7B%0A   
@@ -103,31 +103,36 @@
 Style = 
-vertices%5Bvertex
+core_entities%5Bentity
 %5D%5B'color
@@ -173,39 +173,44 @@
 (%0A          
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'x'%5D,%0A    
@@ -211,39 +211,44 @@
 ,%0A          
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'y'%5D,%0A    
@@ -253,31 +253,36 @@
         
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'width
@@ -295,31 +295,36 @@
         
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'heigh
@@ -381,52 +381,62 @@
 var 
-vertex in vertices)%7B%0A        vertices%5Bvertex
+entity in core_entities)%7B%0A        core_entities%5Bentity
 %5D%5B'r
@@ -470,31 +470,36 @@
 * (25 - 
-vertices%5Bvertex
+core_entities%5Bentity
 %5D%5B'layer
@@ -510,39 +510,44 @@
 %0A        if(
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'rotation'
@@ -570,39 +570,44 @@
             
-vertices%5Bvertex
+core_entities%5Bentity
 %5D%5B'rotation'
@@ -638,31 +638,36 @@
 else if(
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'rotat
@@ -690,31 +690,36 @@
         
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'rotat
@@ -756,31 +756,36 @@
         
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'x'%5D =
@@ -797,39 +797,44 @@
 as_x_five + 
-vertices%5Bvertex
+core_entities%5Bentity
 %5D%5B'layer'%5D *
@@ -848,31 +848,36 @@
 ath.cos(
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'rotat
@@ -892,31 +892,36 @@
         
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'y'%5D =
@@ -937,31 +937,36 @@
 _five + 
-vertices%5Bvertex
+core_entities%5Bentity
 %5D%5B'layer
@@ -988,23 +988,28 @@
 sin(
-ver
+core_enti
 ti
-c
 es%5B
-vertex
+entity
 %5D%5B'r
@@ -1600,22 +1600,57 @@
     
-vertices.push(
+core_entity_create(%7B%0A              'properties': 
 %7B%0A  
@@ -1661,16 +1661,18 @@
         
+ 
+ 
 'color':
@@ -1711,16 +1711,18 @@
         
+  
 'height'
@@ -1723,24 +1723,26 @@
 eight': 10,%0A
+  
             
@@ -1776,32 +1776,34 @@
 ,%0A              
+  
 'rotation': inne
@@ -1827,16 +1827,18 @@
         
+  
 'width':
@@ -1856,16 +1856,18 @@
         
+ 
+ 
 'x': 0,%0A
@@ -1884,16 +1884,18 @@
     
+  
 'y': 0,%0A
     
@@ -1886,24 +1886,41 @@
     'y': 0,%0A
+              %7D,%0A
             
@@ -2327,23 +2327,4 @@
 '';%0A
-var vertices = %5B%5D;%0A

converted to entities