locked
Why do certain variables don't work. RRS feed

  • Question

  • Probably don't need new thread, but need straight forward answer, please leave the "script" jargon out.

    If i run this it works

    For i = 1 to 180       
        j=GraphicsWindow.getrandomcolor()
        GraphicsWindow.PenColor = (j)
        Turtle.Move(side)
        Turtle.Turn(angle)
        side = side + (math.pi* 0.31415)
      EndFor 

    But if I do this the color don't change

    For i = 1 to 180       
        j=j=120000   (or any amount enough to change a color)
        GraphicsWindow.PenColor = (j)
        Turtle.Move(side)
        Turtle.Turn(angle)
        side = side + (math.pi* 0.31415)
      EndFor

     

    Forget any other part of the example, but not sure how to just make it work without using a line like this to make j work.

    j=GraphicsWindow.getrandomcolor()

    What is the basic rules I am missing from the total picture of what smallBASIC is doing for certain commands-variables.

    I don't see any logical reason, same goes for GraphicsWindow.setpixel (x, y,(j)), only the random command made the variable change.I even printed the numbers for text screen and they are changing, but won't work. 

               

    Wednesday, February 16, 2011 7:05 PM

Answers

  • Got it. !

    j=GraphicsWindow.GetColorFromRGB((h), (i), (h))
        GraphicsWindow.pencolor = (j)

    now the pencolor can change according to any variable I assign.

    GraphicsWindow.Width = 1024
    GraphicsWindow.height = 768
    GraphicsWindow.Show()
    Turtle.penup()
    Turtle.Speed = 400
    Turtle.MoveTo(512,320)
    angle = 91
    Turtle.pendown()
    Turtle.hide()
    Squiral()
    Sub Squiral
     
      side = 0     
      For i = 1 to 255
        h=h+0.25   
        j=GraphicsWindow.GetColorFromRGB((h), (i), (h))
        GraphicsWindow.pencolor = (j)
        Turtle.Move(side)
        Turtle.Turn(angle)
        side = side + (math.pi* 0.31415)
      EndFor     
    EndSub

     

    from another user "squiral" but changed from me messing around.

    • Marked as answer by litdev Thursday, February 17, 2011 7:13 PM
    Wednesday, February 16, 2011 8:45 PM

All replies

  • In your first code, maybe you ca try brushcolor instead of pencolor. You can't use

    j=j=120000

    Change that to

    j=120000


    ~~AirWaves!!~~
    Wednesday, February 16, 2011 7:12 PM
  • Ok I just started with this "smallBASIC" but have done BASIC in the past (long time ago Atari home computer, VIC20 days)So I have to learn more and will look at the brushcolor, haven't done that yet.

    But I am adding for each loop so i need a j=j+(any number) but the line-pixels stays black.

     

    MY mistake. !!! should be j=j+120000

    Wednesday, February 16, 2011 7:47 PM
  • Ok I just started with this "smallBASIC" but have done BASIC in the past (long time ago Atari home computer, VIC20 days)So I have to learn more and will look at the brushcolor, haven't done that yet.

    But I am adding for each loop so i need a j=j+(any number) but the line-pixels stays black.

     

    MY mistake. !!! should be j=j+120000

    Wednesday, February 16, 2011 7:47 PM
  • Brushcolor seems to be just for shapes.
    Wednesday, February 16, 2011 8:29 PM
  • Got it. !

    j=GraphicsWindow.GetColorFromRGB((h), (i), (h))
        GraphicsWindow.pencolor = (j)

    now the pencolor can change according to any variable I assign.

    GraphicsWindow.Width = 1024
    GraphicsWindow.height = 768
    GraphicsWindow.Show()
    Turtle.penup()
    Turtle.Speed = 400
    Turtle.MoveTo(512,320)
    angle = 91
    Turtle.pendown()
    Turtle.hide()
    Squiral()
    Sub Squiral
     
      side = 0     
      For i = 1 to 255
        h=h+0.25   
        j=GraphicsWindow.GetColorFromRGB((h), (i), (h))
        GraphicsWindow.pencolor = (j)
        Turtle.Move(side)
        Turtle.Turn(angle)
        side = side + (math.pi* 0.31415)
      EndFor     
    EndSub

     

    from another user "squiral" but changed from me messing around.

    • Marked as answer by litdev Thursday, February 17, 2011 7:13 PM
    Wednesday, February 16, 2011 8:45 PM