Skip to content

Commit

Permalink
isobox
Browse files Browse the repository at this point in the history
  • Loading branch information
bit101 committed Dec 24, 2015
1 parent f6cb58c commit 8f5f655
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 1 deletion.
97 changes: 97 additions & 0 deletions app/glc-min.js
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,92 @@ define('app/shapes/heart',[],function() {
}
});

define('app/shapes/isobox',[],function() {

return {
draw: function(context, t) {
var x = this.getNumber("x", t, 100),
y = this.getNumber("y", t, 100),
size = this.getNumber("size", t, 60),
h = this.getNumber("h", t, 40),
colorLeft = this.getColor("colorLeft", t, "#999999"),
colorRight = this.getColor("colorRight", t, "#cccccc"),
colorTop = this.getColor("colorTop", t, "#eeeeee");

context.translate(x, y);

if(h >= 0) {
context.fillStyle = colorLeft;
context.beginPath();
context.moveTo(-size / 2, 0);
context.lineTo(0, size / 4);
context.lineTo(0, size / 4 - h);
context.lineTo(-size / 2, -h);
context.lineTo(-size / 2, 0);
this.drawFillAndStroke(context, t, true, false);

context.fillStyle = colorRight;
context.beginPath();
context.moveTo(size / 2, 0);
context.lineTo(0, size / 4);
context.lineTo(0, size / 4 - h);
context.lineTo(size / 2, -h);
context.lineTo(size / 2, 0);
this.drawFillAndStroke(context, t, true, false);

context.fillStyle = colorTop;
context.beginPath();
context.moveTo(-size / 2, -h + 0.25);
context.lineTo(0, -size / 4 - h);
context.lineTo(size / 2, -h);
context.lineTo(0, size / 4 - h);
context.lineTo(-size / 2, -h);
this.drawFillAndStroke(context, t, true, false);
}
else {
// clip path
context.beginPath();
context.moveTo(-size / 2, 0);
context.lineTo(0, -size / 4);
context.lineTo(size / 2, 0);
context.lineTo(0, size / 4);
context.lineTo(-size / 2, 0);
context.clip();


context.fillStyle = colorRight;
context.beginPath();
context.moveTo(-size / 2, 0);
context.lineTo(0, -size / 4);
context.lineTo(0, -size / 4 -h);
context.lineTo(-size / 2, -h);
context.lineTo(-size / 2, 0);
this.drawFillAndStroke(context, t, true, false);

context.fillStyle = colorLeft;
context.beginPath();
context.moveTo(size / 2, 0);
context.lineTo(0, -size / 4);
context.lineTo(0, -size / 4 -h);
context.lineTo(size / 2, -h);
context.lineTo(size / 2, 0);
this.drawFillAndStroke(context, t, true, false);

context.fillStyle = colorTop;
context.beginPath();
context.moveTo(-size / 2, -h);
context.lineTo(0, -size / 4 - h);
context.lineTo(size / 2, -h);
context.lineTo(0, size / 4 - h);
context.lineTo(-size / 2, -h);
this.drawFillAndStroke(context, t, true, false);
}


}
}
});

define('app/shapes/line',[],function() {

return {
Expand Down Expand Up @@ -1397,6 +1483,7 @@ define('app/renderlist',[
"app/shapes/gear",
"app/shapes/grid",
"app/shapes/heart",
"app/shapes/isobox",
"app/shapes/line",
"app/shapes/oval",
"app/shapes/path",
Expand All @@ -1423,6 +1510,7 @@ define('app/renderlist',[
Gear,
Grid,
Heart,
Isobox,
Line,
Oval,
Path,
Expand Down Expand Up @@ -1525,6 +1613,10 @@ define('app/renderlist',[
return add(Shape.create(Heart, props));
}

function addIsobox(props) {
return add(Shape.create(Isobox, props));
}

function addLine(props) {
return add(Shape.create(Line, props));
}
Expand Down Expand Up @@ -1620,6 +1712,7 @@ define('app/renderlist',[
addGear: addGear,
addGrid: addGrid,
addHeart: addHeart,
addIsobox: addIsobox,
addLine: addLine,
addOval: addOval,
addPath: addPath,
Expand Down Expand Up @@ -1982,6 +2075,7 @@ define('app/controller',[],function() {
size: size
};
});

define('app/styles',[],function() {
var defaultStyles = {
backgroundColor: "#ffffff",
Expand Down Expand Up @@ -14731,6 +14825,9 @@ define('app/ui/toolbar',[],function() {
fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.addEventListener("change", controller.chooseFile);
fileInput.addEventListener("click", function() {
this.value = null;
})
}

function addListeners() {
Expand Down
Binary file added docs/images/2.23.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions docs/objects.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h1>GIF Loop Coder (GLC) Documentation</h1>
<li><a href="#gear">Gear</a></li>
<li><a href="#grid">Grid</a></li>
<li><a href="#heart">Heart</a></li>
<li><a href="#isobox">Isobox</a></li>
<li><a href="#line">Line</a></li>
<li><a href="#oval">Oval</a></li>
<li><a href="#path">Path</a></li>
Expand Down Expand Up @@ -330,6 +331,48 @@ <h3><a name="heart"></a>Heart</a></h3>
</div>


<!-- ================================================================================== -->
<h3><a name="isobox"></a>Isobox</a></h3>
<!-- ================================================================================== -->
<div class="subsection">

<p>An isometric box object is created with:</p>

<div class="code"><pre><code>
glc.renderList.addIsobox(properties);
</code></pre></div>

<p>This draws an isometric box.</p>

<img src="images/2.23.gif">

<p>In addition to the standard style properties described in the next section, this method can accept the following properties. Defaults are listed in parentheses. All of these properties are animatable.</p>

<div class="code"><pre><code>
x (100) The x position of the isobox.
y (100) The y position of the isobox.
size (60) The size of the isobox.
h (40) The height of the isobox.
colorTop (#eeeeee) The color of the top of the isobox.
colorLeft (#999999) The color of the left side of the isobox.
colorRight (#cccccc) The color of the right side of the isobox.
stroke (false) Whether the object will be stroked.
fill (true) Whether the object will be filled.
</code></pre></div>

<p>Note: a good way to assign colors to the faces is to use <code>color.hsv()</code> with the same hue but differing values. For example:</p>

<div class="code"><pre><code>
list.addIsobox({
colorTop: color.hsv(40, 1, 1), // bright
colorRight: color.hsv(40, 1, 0.75), // darker
colorLeft: color.hsv(40, 1, 0.5) // darkest
});
</code></pre></div>

</div>



<!-- ================================================================================== -->
<h3><a name="line"></a>Line</a></h3>
Expand Down
45 changes: 45 additions & 0 deletions examples/isometricgrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function onGLC(glc) {
glc.loop();
glc.size(360, 275);
// glc.setDuration(5);
// glc.setFPS(20);
// glc.setMode('single');
// glc.setEasing(false);
var list = glc.renderList,
width = glc.w,
height = glc.h,
color = glc.color;

list.addIsobox({
x: width / 2,
y: 290,
size: 340,
h: 100,
colorTop: color.hsv(45, 1, 1),
colorRight: color.hsv(45, 1, 0.8),
colorLeft: color.hsv(45, 1, 0.5)
});

var tileWidth = 60,
tileHeight = tileWidth / 2;

for(var y = 0; y < 5; y++) {
for(var x = 0; x < 5; x++) {
var xpos = width / 2 + (x - y) * tileWidth / 2,
ypos = 130 + (x + y) * tileHeight / 2,
hue = 30 + Math.random() * 30;
list.addIsobox({
x: xpos,
y: ypos,
size: tileWidth,
h: [0, 100],
phase: (x - y) / 20,
colorTop: color.hsv(hue, 1, 1),
colorLeft: color.hsv(hue, 1, 0.5),
colorRight: color.hsv(hue, 1, 0.75),
});
}
}


}
2 changes: 1 addition & 1 deletion src/app/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,4 @@ define(function() {
openFile: openFile,
size: size
};
});
});
7 changes: 7 additions & 0 deletions src/app/renderlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define([
"app/shapes/gear",
"app/shapes/grid",
"app/shapes/heart",
"app/shapes/isobox",
"app/shapes/line",
"app/shapes/oval",
"app/shapes/path",
Expand All @@ -38,6 +39,7 @@ define([
Gear,
Grid,
Heart,
Isobox,
Line,
Oval,
Path,
Expand Down Expand Up @@ -140,6 +142,10 @@ define([
return add(Shape.create(Heart, props));
}

function addIsobox(props) {
return add(Shape.create(Isobox, props));
}

function addLine(props) {
return add(Shape.create(Line, props));
}
Expand Down Expand Up @@ -235,6 +241,7 @@ define([
addGear: addGear,
addGrid: addGrid,
addHeart: addHeart,
addIsobox: addIsobox,
addLine: addLine,
addOval: addOval,
addPath: addPath,
Expand Down
85 changes: 85 additions & 0 deletions src/app/shapes/isobox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
define(function() {

return {
draw: function(context, t) {
var x = this.getNumber("x", t, 100),
y = this.getNumber("y", t, 100),
size = this.getNumber("size", t, 60),
h = this.getNumber("h", t, 40),
colorLeft = this.getColor("colorLeft", t, "#999999"),
colorRight = this.getColor("colorRight", t, "#cccccc"),
colorTop = this.getColor("colorTop", t, "#eeeeee");

context.translate(x, y);

if(h >= 0) {
context.fillStyle = colorLeft;
context.beginPath();
context.moveTo(-size / 2, 0);
context.lineTo(0, size / 4);
context.lineTo(0, size / 4 - h);
context.lineTo(-size / 2, -h);
context.lineTo(-size / 2, 0);
this.drawFillAndStroke(context, t, true, false);

context.fillStyle = colorRight;
context.beginPath();
context.moveTo(size / 2, 0);
context.lineTo(0, size / 4);
context.lineTo(0, size / 4 - h);
context.lineTo(size / 2, -h);
context.lineTo(size / 2, 0);
this.drawFillAndStroke(context, t, true, false);

context.fillStyle = colorTop;
context.beginPath();
context.moveTo(-size / 2, -h + 0.25);
context.lineTo(0, -size / 4 - h);
context.lineTo(size / 2, -h);
context.lineTo(0, size / 4 - h);
context.lineTo(-size / 2, -h);
this.drawFillAndStroke(context, t, true, false);
}
else {
// clip path
context.beginPath();
context.moveTo(-size / 2, 0);
context.lineTo(0, -size / 4);
context.lineTo(size / 2, 0);
context.lineTo(0, size / 4);
context.lineTo(-size / 2, 0);
context.clip();


context.fillStyle = colorRight;
context.beginPath();
context.moveTo(-size / 2, 0);
context.lineTo(0, -size / 4);
context.lineTo(0, -size / 4 -h);
context.lineTo(-size / 2, -h);
context.lineTo(-size / 2, 0);
this.drawFillAndStroke(context, t, true, false);

context.fillStyle = colorLeft;
context.beginPath();
context.moveTo(size / 2, 0);
context.lineTo(0, -size / 4);
context.lineTo(0, -size / 4 -h);
context.lineTo(size / 2, -h);
context.lineTo(size / 2, 0);
this.drawFillAndStroke(context, t, true, false);

context.fillStyle = colorTop;
context.beginPath();
context.moveTo(-size / 2, -h);
context.lineTo(0, -size / 4 - h);
context.lineTo(size / 2, -h);
context.lineTo(0, size / 4 - h);
context.lineTo(-size / 2, -h);
this.drawFillAndStroke(context, t, true, false);
}


}
}
});
3 changes: 3 additions & 0 deletions src/app/ui/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ define(function() {
fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.addEventListener("change", controller.chooseFile);
fileInput.addEventListener("click", function() {
this.value = null;
})
}

function addListeners() {
Expand Down
Loading

0 comments on commit 8f5f655

Please sign in to comment.