Different behavor between IDE and Standalone Application.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
uhellstr
Posts: 3
Joined: Sat Jul 21, 2012 9:13 am

Different behavor between IDE and Standalone Application.

Post by uhellstr » Fri Jan 04, 2013 1:06 pm

Hi everyone,

Environment:
OSX 10.8.2 (Mountain Lion)
LiveCode 5.5.3 (Personal Edition)


I have started to learn LiveCode and written a couple of simple stacks and done a couple of tutorials and I really enjoy the voyage so far.

Problem:

In my current project I'm trying to implement a basic version of the Logo scripting language in LiveCode to get hang of more in-depth textmanipulation and the
drawing capacity of LiveCode. I have implemented commands like forward, rotate left , rotate right, penup,pendown, pencolor, background colors, repeat etc
and it works quite nice sofar even though there is alot to do when it comes down to optimize the code.

The thing I have really trouble with all the time was to implement a routine for drawing a Circle. It has been some hard lessons on the way but also some valueble knowledge on
how things works in LiveCode.

In Logo you can draw a circle using the following command

Code: Select all

repeat 360 [forward 1 right turn 1]
After some struggling with "The Unit-Circle" and angles, radians, sin and cos and reading up on how this works and finding out the algorithms I finally got something
that works fine inside LiveCode IDE. I can draw something that "is-not-a-perfect-circle" but quite near.

However, when I compile my code and run it as a standalone application. The "not-so-perfect circle" is more like a "hexagon" then a circle. I have struggled with this for hours
trying to understand what is going on but now I need to know wether or not I am to blame or, if this is some kind of bug in LiveCode. I think it has to something with how
sin,cos or pi somehow works different after compiling the code.

I have included sample-code below that can be used to reproduce my problem + a image that shows the difference between running the code in IDE and as Standalone Application.

The code to be used to reproduce the behavor:

Code: Select all

#############################################
# This testcase shows a strange behavor 
# between drawing in compile-free environment
# and when do the drawing in compiled version
# To use this code you need.
# 
# Testcase setup on OSX 10.8.2 using LiveCode version 5.5.3
#
#  1. A mainstack with 1 card using dimensions 400x400
#     This code to paste on stack-level
#  2. A button on the bottom of the card called "Start"
#     that calls drawCircle
#  3. A button on the bottom of the card called "Clear
#     that calls clearScreen
#  
#  To reproduce the behavor
#  1. Save stack as standalone application
#  2. Run the code inside LiveCode and check the circle
#  3. Start the standalone application side by side of LiveCode
#  4. Again run the code and see the difference on how the circle
#     looks like in the compiled product.
#############################################

global cAngle,cLoc

############################################
# Convert a circle degree (angle) to radians
# since LiveCode sin() and cos() requires 
# radians rather then degrees.
############################################
function toRadians pAngle
   return ((pAngle*pi)/180)
end toRadians

#############################################
# Calculate delta between start and end point
#############################################
function deltaX pDist,pAngle
   return (pDist*cos(toRadians(pAngle)))*-1
end deltaX

function deltaY pDist,pAngle
   return (pDist*sin(toRadians(pAngle)))
end deltaY

#########################################
# ClearScreen
#########################################
on clearScreen
   lock screen
   lock messages
   repeat until the number of images is 0 on card 1
      delete image 1 of card 1
   end repeat
   unlock messages
   unlock screen
end clearScreen

#######################################################
# Rotate grades to "The Unit Circle" where 90 deegre
# is to the north and not to the west. In LiveCode
# we have 0 (360) degrees to the north
#######################################################
function unitCircle p_angle
   # works ok
   if (p_angle >=0 and p_angle <= 90) then
      put p_angle - 90 into c_angle
   else
      put p_angle - 90 into c_angle
   end if
   return c_angle
end unitCircle


###########################################
# Print out debuginfo on angle and Location
###########################################
on pDebug
  put cAngle into field "Angle" on card 1
  put round(word 1 of cLoc) & "," & round(word 2 of cLoc) into field "Location" on card 1
end pDebug


############################################
# Draw information on to canvas
############################################
on drawLine p_cLoc,p_eLoc
      set pencolor to "black"
      set penheight to 2
      set penwidth to 2
      put word 1 of p_cLoc into x_start
      put word 2 of p_cLoc into y_start
      put word 1 of p_eLoc into x_end
      put word 2 of p_eLoc into y_end
      choose line tool
      drag from x_start,y_start to x_end,y_end
      choose browse tool
      pDebug
end drawLine

########################################
# Turn x degree to the right
########################################
on rightTurn tCommand
   if cAngle = 0 then
     put 360 into cAngle
  end if
  put cAngle - word 2 of tCommand into cAngle
  pDebug
end rightTurn

############################################
# moveForward calculates start and endpoint
# for drawing.
#############################################
on moveForward tCommand
   put word 2 of tCommand into tDistance
   -- save current position into variables t_x0,t_y0
   put word 1 of cLoc into t_x0
   put word 2 of cLoc into t_y0
   -- Calculate the delta beteen current and new position
   -- Convert the Circle so that 90 deegrees points to the north
   put unitCircle (cAngle) into l_Angle
   -- Calculate the delta for the unit circle
   put deltaX (tDistance,l_Angle) into t_deltax
   put deltaY (tDistance,l_Angle) into t_deltay
   -- Calculate the new x,y position with help of delta
   put t_x0 + t_deltax into t_xpos
   put t_y0 + t_deltay into t_ypos
   put t_xpos & " " & t_ypos into theNewLoc
   -- Call drawline to draw to the new location
   drawLine cLoc,theNewLoc
   -- Put the new location into current location
   put theNewLoc into cLoc
end moveForward

#############################################
# drawCircle : Draws a cirlce on the canvas
#              using logocommands forward
#              and rotate.
#############################################
on drawCircle
   put "199 202" into cLoc
   put 360 into cAngle
   pDebug
   repeat with step= 360 down to 0
      put step into cAngle
      put "fd 1" into cForward
      moveForward cForward
      put "rt 1" into cRightTurn
      rightTurn cRightTurn
   end repeat
end drawCircle 
This is the difference I see between the IDE and the Standalone Application.

Kindly Rgds
/Ulf
Attachments
Testcase.jpeg
Image showing difference between IDE and compiled application

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Different behavor between IDE and Standalone Application

Post by Klaus » Fri Jan 04, 2013 2:03 pm

Hi Ulf,

1. wecome to the forum! :D

2. I still have no clear idea what your app is supposed to do, but the painting tools in
Livecode are unfortunately still 8 (EIGHT) BIT!, so this MUST look shitty :D
Can't you use a drawing tool (oval etc.) instead?

They are antialiased and can be nicely rotated with "set the angle of grc X top 45".


Best

Klaus

uhellstr
Posts: 3
Joined: Sat Jul 21, 2012 9:13 am

Re: Different behavor between IDE and Standalone Application

Post by uhellstr » Fri Jan 04, 2013 2:35 pm

Klaus,

Thank's for the reply. The app i'm building is an implementation of a teaching language called Logo. In Logo you build your squares, triangles and circles by commanding a turtle. So you can say to the turtle "point north then draw a line 90 steps, turn right draw a line 90 step , turn right and draw a line 90 steps, turn right and draw a line 90 steps" Those steps would produce a square on your canvas. Now to produce a circle there is no command circle in basic Logo. It is a tedius jobb of moving one step at a time drawing a pixel, then rotate an angle and so forth. It would be like "Repeat the following 360 times [move the turtle one step forward, rotate 1 degree to the right]". This will produce a circle.

So what my testcase does is taking part of my code that I use to produce a circle using the Logo language. Using a oval in Livecode might be possible if i could find a way of translate the command sequence "repeat 360 [fd rt 1]" into some radius of an oval in livecode. But right now what i use is the drag command to draw a line from one point to another 360 times to produces something that is , YES, a very crude , but still a circle and this is true to the original implementations of Logo that I have as foundation for my own code. Using an oval would be much faster ofcause then my current code and might be preferable but it do not explain the problem I see with huge difference between how the circle is drawn within the IDE and how it is drawn when I compiled the code.

I Just realized that (how-stupid-can-one-be) I actually can upload the Teststack (This is not my app just some testcode to demonstrate the problem I see) so here it is.

Kindly Rgds
/Ulf
Attachments
Testcase.livecode.zip
Testcase
(3.05 KiB) Downloaded 189 times

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Different behavor between IDE and Standalone Application

Post by Klaus » Fri Jan 04, 2013 2:46 pm

Hi Ulf,

ah, yes, Logo, I never "got" this turtle metaphore at all :D
But I am sure you can use a graphic and set its "startangle" and "arcangle" property according to your needs to "fake" the LOGO stuff!

No idea why it is looking more shitty in a standalone than in the IDE?!
But since I don't like both looks, I don't really care... 8)

Best

Klaus

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Different behavor between IDE and Standalone Application

Post by dave_probertGA6e24 » Fri Jan 04, 2013 3:02 pm

Hi (and Welcome),

In the IDE on my Mac I get the Jaggy lines version when testing your code. Haven't bothered with a stand-alone yet!

Something I noticed - the unitCircle function repeats the same line for both parts of the if statement "put p_angle - 90 into c_angle", but that is not the cause of the problem.

It looks to me like the "drag" command is not too happy with decimal values - though I can't see why, and not always!

I replaced the drawline handler with this (along with a graphic called "foo" on the card) and it shows the circle correctly (as long as the round's are in place):

Code: Select all

############################################
# Draw information on to canvas
############################################
on drawLine p_cLoc,p_eLoc
/*   
   set pencolor to "black"
   set penheight to 2
   set penwidth to 2
*/   
   put round(word 1 of p_cLoc) into x_start
   put round(word 2 of p_cLoc) into y_start
   put round(word 1 of p_eLoc) into x_end
   put round(word 2 of p_eLoc) into y_end
  // new bit 
   put the points of grc "foo" into fff
   put cr&x_end&","&y_end after fff
   set the points of grc "foo" to fff
   /*
   choose "line" tool
   drag from x_start,y_start to x_end,y_end
   choose "browse" tool
  */
end drawLine
So the code for the circle is fine, but there is something wrong in how the drawing of pixels works (via drag)

Apart from that I can't seem to get it to work.

Hope that helps a bit,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Different behavor between IDE and Standalone Application

Post by jacque » Fri Jan 04, 2013 10:12 pm

Jim Hurley, a long-time LiveCode users and mathematician, created a complete Turtle Graphics library for LiveCode. He could probably help. Here is a link to some historical messages from the mailing list:

http://runtime-revolution.278305.n4.nab ... e+graphics

You could probably email him, he's friendly. Or join the mailing list and ask there, since I don't think he reads these forums. You can join the list here: http://lists.runrev.com/mailman/listinfo/use-livecode/
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply