FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » having trouble using gd imageline in foreach loop
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: having trouble using gd imageline in foreach loop [message #172804 is a reply to message #172803] Thu, 03 March 2011 01:12 Go to previous messageGo to previous message
spambait is currently offline  spambait
Messages: 35
Registered: September 2010
Karma:
Member
In article <296f0959-18d8-4ec5-a4b8-094172863787(at)glegroupsg2000goo(dot)googlegroups(dot)com>, comp(dot)lang(dot)php(at)googlegroups(dot)com wrote:
> I am trying to take the first 15 numbers of the fibonacci sequence and use them
> to draw a squarish spiral.
> I have an array with the first 15 numbers $fibsequence.
> I am looping through this array so that a line correponding to the fibonacci
> value will be drawn. I am alternating "directions": north, south, east, west.
> I am starting from the center of the image.
>
> For some reason I am only getting one straight line going east instead of the
> four alternating directions.

Yeah, I bet you are.
>
> Here is my code:
[...]

And here is your bug.
> if($direction=="north"){ $x2 = $x1; $y2 = bcsub($y1,$fibvalue); $direction="west"; }

If $direction was "north" before executing that statement, what value does it
have now? And what will happen when you execute the next statement?

> if($direction=="west"){ $x2 = bcsub($x1,$fibvalue); $y2 = $y1; $direction="south"; }
> if($direction=="south"){ $x2 = $x1; $y2 = bcadd($y1,$fibvalue); $direction="east"; }
> if($direction=="east"){ $x2 = bcadd($x1,$fibvalue); $y2 = $y1; $direction="north"; }

No matter whether $direction was "north", "south", "east", or "west" *before*
executing this block of four statements, it's guaranteed to be "north" *after*
executing them.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: strange behaviour in assignment expr.
Next Topic: cookies and Firefox 3.6.15 - ugh
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 17:43:36 GMT 2024

Total time taken to generate the page: 0.04545 seconds