Sg2.9
help! code not working proper...
Recent RSS
help! code not working properly, maybe bug? or im an idiot
From:  Zach Gage
Date:  18. December 2006, 23:29

for the life of me i cant figure out why this wont work

you can pretty much ignore this whole part between the *'s, im just including it incase somehow my error is in there,
anyway, the problem is in the while loop at the bottom, it keeps drawing the lines in the same place (it draws 11), even though im clearly telling it to move the end point over.........

thanks in advance!

//********************

function onInit() {
size = .5;
startX = 0;
startY = 0;
boxSize = 20;
hop = 2;
}

function onOptions() {
size = Dialog.prompt("Random Scribbler:", [ { description: "Radius", value: size, width: 50} ])[0];
}

function onMouseDown(event) {
path = new Path();
path.moveTo(event.point);

}

function onMouseUp(event) {

//point = event.point;
startX = event.point.getX();
startY = event.point.getY();
point = new Point();
point2 = new Point();

p1ModX=0;
p1ModY=0;

p2ModX=0;
p2ModY=0;

point = new Point(startX,startY);
point2 = event.point;

point = point.add( (boxSize/2) ,0);

//p1
p1Side = Math.round(1 + Math.random() * (2 - 1));
p1Start = Math.round(0 + Math.random() * (boxSize - 0));

if(p1Side == 1) //top
{
point.setX(startX+p1Start);
point.setY(startY);
}
if(p1Side == 2) //left
{
point.setX(startX);
point.setY(startY-p1Start);
}

//p2
p2Side = Math.round(1 + Math.random() * (2 - 1));
p2Start = Math.round(0 + Math.random() * (boxSize - 0));

if(p2Side == 1) //right
{
point2.setX(startX+boxSize);
point2.setY(startY-p2Start);
}
if(p2Side == 2) //bottom
{
point2.setX(startX+p2Start);
point2.setY(startY-boxSize);
}

point3 = new Point();
point4 = new Point();
point3 = point;
point4 = point2;
test=10;

//********************

while( (point.getY() >= (startY-boxSize+hop)) && (point2.getX() >= (startX+hop)) && test >0)
{
//draw lines

point2.subtract(hop,0);
test--;
path = new Path();
path.moveTo(point);
path.lineTo(point2);
}

}

Re: help! code not working properly, maybe bug? or im an idiot
From:  Jürg Lehni
Date:  19. December 2006, 15:28

subtract does not modify the point itself, it returns a modified copy:

newPoint = point2.subtract(hop, 0);

I hope this helps.

Re: help! code not working properly, maybe bug? or im an idiot
From:  Zach Gage
Date:  24. December 2006, 02:59

oh awesome. thanks!

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Triangular 25.01.11