Correct handling of strokeWidth for vertical arcs

This commit is contained in:
walterhiggins 2013-02-03 20:19:58 +00:00
parent ca821a696a
commit 22add98d15
3 changed files with 96 additions and 66 deletions

View file

@ -254,9 +254,14 @@ var Drone = Drone || {
if (Drone.constructor == Function) if (Drone.constructor == Function)
return; return;
// /**
// Drone Constructor Create a new Drone for building.
// @constructor
@param {number} x
@param {number} y
@param {number} z
@param {number} dir - The direction the drone faces : 0 is east, 1 is south, 2 is west, 3 is north.
*/
Drone = function(x,y,z,dir) Drone = function(x,y,z,dir)
{ {
var usePlayerCoords = false; var usePlayerCoords = false;
@ -461,7 +466,11 @@ var Drone = Drone || {
}else{ }else{
door = 71; door = 71;
} }
return this.cuboid(door+':' + this.dir).up().cuboid(door+':8').right().cuboid(door+':9').down().cuboid(door+':' + this.dir).left(); return this
.box(door+':' + this.dir).up()
.box(door+':8').right()
.box(door+':9').down()
.box(door+':' + this.dir).left();
}; };
// player dirs: 0 = east, 1 = south, 2 = west, 3 = north // player dirs: 0 = east, 1 = south, 2 = west, 3 = north
// block dirs: 0 = east, 1 = west, 2 = south , 3 = north // block dirs: 0 = east, 1 = west, 2 = south , 3 = north
@ -670,6 +679,20 @@ var Drone = Drone || {
} }
*/ */
var _getStrokeDir = function(x,y){
var absY = Math.abs(y);
var absX = Math.abs(x);
var strokeDir = 0;
if (y > 0 && absY >= absX)
strokeDir = 0 ; //down
else if (y < 0 && absY >= absX)
strokeDir = 1 ; // up
else if (x > 0 && absX >= absY)
strokeDir = 2 ; // left
else if (x < 0 && absX >= absY)
strokeDir = 3 ; // right
return strokeDir;
};
/* /*
The daddy of all arc-related API calls - The daddy of all arc-related API calls -
if you're drawing anything that bends it ends up here. if you're drawing anything that bends it ends up here.
@ -717,73 +740,39 @@ var Drone = Drone || {
.back(y).left(x); .back(y).left(x);
} }
}else{ }else{
if (strokeWidth == 1) if (strokeWidth == 1){
gotoxy(x,y).cuboidX(params.blockType, gotoxy(x,y)
params.meta, .cuboidX(params.blockType,
world, params.meta,
1, // width world,
stack, // height 1, // width
strokeWidth // depth stack, // height
).move('center'); strokeWidth // depth
else{ )
var strokeDir; .move('center');
var absY = Math.abs(y); } else {
var absX = Math.abs(x); var strokeDir = _getStrokeDir(x,y);
if (y > 0 && absY >= absX) var width = 1, depth = 1;
strokeDir = 0 ; //down
else if (y < 0 && absY >= absX)
strokeDir = 1 ; // up
else if (x > 0 && absX >= absY)
strokeDir = 2 ; // left
else if (x < 0 && absX >= absY)
strokeDir = 3 ; // right
else
throw new Error("can't get strokeDir");
switch (strokeDir){ switch (strokeDir){
case 0: // down case 0: // down
gotoxy(x,y-(strokeWidth-1)) y = y-(strokeWidth-1);
.cuboidX(params.blockType, depth = strokeWidth;
params.meta,
world,
1, // width
stack, // height
strokeWidth // depth
).move('center');
break; break;
case 1: // up case 1: // up
gotoxy(x,y) depth = strokeWidth;
.cuboidX(params.blockType,
params.meta,
world,
1, // width
stack, // height
strokeWidth // depth
).move('center');
break; break;
case 2: // left case 2: // left
gotoxy(x-(strokeWidth-1),y) width = strokeWidth;
.cuboidX(params.blockType, x = x-(strokeWidth-1);
params.meta,
world,
strokeWidth, // width
stack, // height
1 // depth
).move('center');
break; break;
case 3: // right case 3: // right
gotoxy(x,y) width = strokeWidth;
.cuboidX(params.blockType,
params.meta,
world,
strokeWidth, // width
stack, // height
1 // depth
).move('center');
break; break;
} }
gotoxy(x,y)
.cuboidX(params.blockType, params.meta, world, width, stack, depth)
.move('center');
} }
} }
}; };
@ -814,7 +803,34 @@ var Drone = Drone || {
.down(y).left(x); .down(y).left(x);
} }
}else{ }else{
gotoxy(x,y).cuboidX(params.blockType,params.meta,world,strokeWidth,1,stack).move('center'); if (strokeWidth == 1){
gotoxy(x,y)
.cuboidX(params.blockType,params.meta,world,strokeWidth,1,stack)
.move('center');
}else{
var strokeDir = _getStrokeDir(x,y);
var width = 1, height = 1;
switch (strokeDir){
case 0: // down
y = y-(strokeWidth-1);
height = strokeWidth;
break;
case 1: // up
height = strokeWidth;
break;
case 2: // left
width = strokeWidth;
x = x-(strokeWidth-1);
break;
case 3: // right
width = strokeWidth;
break;
}
gotoxy(x,y)
.cuboidX(params.blockType, params.meta, world, width, height, stack)
.move('center');
}
} }
}; };
} }

View file

@ -4,7 +4,7 @@ load(__folder + "drone.js");
*/ */
Drone.extend('rainbow', function(radius){ Drone.extend('rainbow', function(radius){
if (typeof radius == "undefined") if (typeof radius == "undefined")
radius = 12; radius = 18;
this.chkpt('rainbow'); this.chkpt('rainbow');
this.down(radius); this.down(radius);
@ -13,7 +13,8 @@ Drone.extend('rainbow', function(radius){
blocks.wool.yellow, blocks.wool.yellow,
blocks.wool.lime, blocks.wool.lime,
blocks.wool.blue, blocks.wool.blue,
blocks.wool.purple]; blocks.wool.purple,
blocks.air];
for (var i = 0;i < colors.length; i++) { for (var i = 0;i < colors.length; i++) {

View file

@ -1,12 +1,25 @@
load (__folder + "drone.js"); load (__folder + "drone.js");
Drone.prototype.testStrokeWidth = function(){ Drone.prototype.testHorizontalStrokeWidth = function(){
this.arc({ this.arc({
blockType: 42, blockType: 42,
meta: 0, meta: 0,
radius: 8, radius: 8,
orientation: 'horizontal',
strokeWidth: 3, strokeWidth: 3,
quadrants: {topright:true}, quadrants: {topright:true,topleft:true,bottomleft:true,bottomright:true},
world: this._getWorld()
});
};
Drone.prototype.testVerticalStrokeWidth = function(){
this.arc({
blockType: 42,
meta: 0,
radius: 8,
orientation: 'vertical',
strokeWidth: 3,
quadrants: {topright:true,topleft:true,bottomleft:true,bottomright:true},
world: this._getWorld() world: this._getWorld()
}); });
}; };