none
Don't know how to do this.... RRS feed

  • Question

  • Hello again! I am going through the last 4 lessons, and i've hit a snag with the "show what you know" for Playing with shapes. I have the set up done so far (and i need to work on it some more...) And  my brain has hit a big block on how to do this... If i need to re-start on it, please tell me! Here is the code.

    'Build the flower!
    '------------INTERFACE----------------'
    'Window set up--Width,height,ect---
    GraphicsWindow.Width=500
    GraphicsWindow.Height=500
    'Set up with Graphicswindow.Contol (Container for the dragable shapes)
    GraphicsWindow.DrawRectangle(370,1,130,498)
    GraphicsWindow.DrawRectangle(370,1,130,100)
    GraphicsWindow.DrawRectangle(370,1,130,200)
    GraphicsWindow.DrawRectangle(370,1,130,300)
    GraphicsWindow.DrawRectangle(370,1,130,400)
    'Now for the opage flower--the tough part.(ish)Set the colors here!
    GraphicsWindow.BrushColor="Pink"
    pedal1=Shapes.AddEllipse(45,30)
    pedal2=Shapes.AddEllipse(45,30)
    pedal3=Shapes.AddEllipse(45,30)
    GraphicsWindow.BrushColor="Yellow"
    core=Shapes.AddEllipse(30,30)
    GraphicsWindow.BrushColor="Brown"
    stem1=Shapes.AddRectangle(10,70)
    'Set opacity
    Shapes.SetOpacity(pedal1,20)
    Shapes.SetOpacity(pedal2,20)
    Shapes.SetOpacity(pedal3,20)
    Shapes.SetOpacity(core,20)
    Shapes.SetOpacity(stem1,20)
    'Rotate the  pedals
    Shapes.Rotate(pedal1,60)
    Shapes.Rotate(pedal2,-60)
    Shapes.Rotate(pedal3,90)
    'Now, move the pedals and the rest.
    
    Shapes.Move(core,200,200)
    Shapes.Move(pedal1,180,190)
    Shapes.Move(pedal2,210,190)
    Shapes.Move(pedal3,195,215)
    Shapes.Move(stem1,212,250)
    
    'Drag-able shapes.
    GraphicsWindow.BrushColor="Pink"
    pedalA=Shapes.AddEllipse(45,30)
    pedalB=shapes.AddEllipse(45,30)
    pedalC=Shapes.AddEllipse(45,30)
    GraphicsWindow.BrushColor="Yellow"
    coreA=Shapes.AddEllipse(30,30)
    GraphicsWindow.BrushColor="Brown"
    stemA=Shapes.AddRectangle(10,70)
    'Rotate!
    Shapes.Rotate(pedalA,60)
    Shapes.Rotate(pedalB,-60)
    Shapes.Rotate(pedalC,90)
    'Move.
    Shapes.Move(pedalA,400,40)
    Shapes.Move(pedalB,400,140)
    Shapes.Move(pedalC,400,240)
    Shapes.Move(coreA,400,340)
    Shapes.Move(stemA,400,420)
    
    
    

    Also, please give me feedback on how i've done so far. Thanks!


    I am a 12 year old learning how to code using small basic.

    Wednesday, July 17, 2013 4:04 AM

Answers

  • My opinion...

    You've done well. You've shown that you can code and manipulate the shapes required for this program.

    You could now look at this as having programmed the "details" that you want in this program.

    The snag you've hit is the "build" of your program. Normal when building more eventful and featured programs. The fun part. This will take you back over the things you've learnt so far and quite often you will have to go back and do a quick refresher on them. Referencing. Not too painful.

    To do this "build" you'll benefit from breaking the code up into smaller working parts (without all the detail). Test these smaller parts and get them working. Incremental Development.

    Tip: when I looked at this exercise I noticed one thing that you need to do is select a shape and move it. So I programmed that one task up. And got it working. Without all the detail, I can add this later.

    It's easier to get parts working in a few lines of code rather then trying to do this in 100 lines of code. So for now you could abandon the details and start building some of the parts you now know that you need for the program to work.

    Here's my build sample on this part:

    CreateGW()
    '-----------------------------------Declare some Variables-------------------------------------------------------------------------------
    'you can sort of work out what variables you want as you build your program, and work out the best name for them.
    target_X1 = 50
    target_Y1 = 60
    X1 = gw - 70 - 10 ' this is  =  gw - the width of the petal -  right offset. 
    Y1 = 10
    '-------------------------------------Declare Event Handlers----------------------------------------------------------------------------
    GraphicsWindow.MouseDown = MouseDown
    GraphicsWindow.MouseMove = MouseMove
    '=======================Main Program================================================
    AddAndPositionShapes()
    '--------------------------------------Event Handlers-------------------------------------------------------------------------------------
    Sub MouseDown
      pos_X = GraphicsWindow.MouseX
      pos_Y = GraphicsWindow.MouseY
      
      If pos_X > X1 And pos_X < X1 + 70 And pos_Y > Y1 And pos_Y < Y1 + 30 Then
        selected = "petal_1"
      EndIf
    EndSub
    Sub MouseMove
      x = GraphicsWindow.MouseX
      y = GraphicsWindow.MouseY
      
      If Mouse.IsLeftButtonDown And selected = "petal_1" Then
        Shapes.Move(petal_1, x, y)
      EndIf
    EndSub
    '---------------------------------------Subroutines-----------------------------------------------------------------------------------------
    Sub AddAndPositionShapes
      opaqPetal_1 = Shapes.AddEllipse(70,30)
      petal_1 = Shapes.AddEllipse(70,30)
      
      Shapes.Move(opaqPetal_1, target_X1, target_Y1)
      Shapes.Move(petal_1, X1, Y1)
    EndSub
    Sub CreateGW
      gw = 500
      gh = 300
      GraphicsWindow.Width = gw
      GraphicsWindow.Height = gh
    EndSub

    The next step could be building into this code the mouse up event.

    Here's some interesting reading on this:  http://www.cprogramming.com/tutorial/incremental_testing.html

    So I reckon you're totally on the right track in terms of learning i.e. you know how to use the objects. Now you're working out how to put them all together into one larger event driven program.

    So sure, you can start again. Or what I would do is open a new program and start building some of the functions that you want the program to do. Like the above sample. Once you start getting the parts working you can start adding in the details when you think your program is ready for it.

    With these larger programs that have multiple events, "start small - finish big". Get the parts working without all the details.

    And don't worry if you ditch some of your earlier code, you'll find coding it the next time is a lot easier and faster. Or copy it across.


    Thursday, July 18, 2013 12:29 AM
    Moderator
  • Hi 8bit. Back again. Hopefully with a simpler and clearer approach. So you could try to code this program by:

    1. Add just 2 shapes
    2. then add the mouse events: mouse down, mouse move, mouse up
    3. attach/use these events to the shapes: select the shape, move it, then on mouse up if it's in the same location as the other shape that's the shapes new position.
    4. once you have this working you can then add in all the other shapes

    This is basically a summary of the above sample I did.

    Martins sample above is a really good, it would be worth trying out that method. And just workout how to work the shapes into it. Copy his sample as is and run it. Very nice.

    Good luck. Bit by bit



    Thursday, July 18, 2013 10:48 AM
    Moderator

All replies

  • This is a tip to handle the mouse routines

    GraphicsWindow.MouseMove = OnMouseMove
    GraphicsWindow.MouseDown = OnMouseDown
    GraphicsWindow.MouseUp = OnMouseUp

    BrushColor = GraphicsWindow.BrushColor
    LoopMouse = 1
    While LoopMouse = 1
      'Sample End by Mouse-Position 0:0
      If MX = 0 And MY = 0 Then
        LoopMouse = 0
      EndIf
      'Show Mouse Result for debugging
      GraphicsWindow.BrushColor = GraphicsWindow.BackgroundColor
      GraphicsWindow.FillRectangle(GraphicsWindow.Width - 60,1,60,30)
      GraphicsWindow.BrushColor = BrushColor
      GraphicsWindow.DrawText(GraphicsWindow.Width - 59, 2, MX + ":" + MY)
      If MouseDown = 1 Then
        GraphicsWindow.DrawText(GraphicsWindow.Width - 59, 17, "M. down")
      EndIf
      Program.Delay(30)
     
      'Your Code to pick a shape by mouse down and lost the shape by mouse up
      '...
    EndWhile
    Program.End()

    Sub OnMouseMove
      MX = GraphicsWindow.MouseX
      MY = GraphicsWindow.MouseY
    EndSub

    Sub OnMouseDown
      MouseDown = 1
    EndSub

    Sub OnMouseUp
      MouseDown = 0
    EndSub


    Best Regards Martin

    Wednesday, July 17, 2013 8:42 PM
  • My opinion...

    You've done well. You've shown that you can code and manipulate the shapes required for this program.

    You could now look at this as having programmed the "details" that you want in this program.

    The snag you've hit is the "build" of your program. Normal when building more eventful and featured programs. The fun part. This will take you back over the things you've learnt so far and quite often you will have to go back and do a quick refresher on them. Referencing. Not too painful.

    To do this "build" you'll benefit from breaking the code up into smaller working parts (without all the detail). Test these smaller parts and get them working. Incremental Development.

    Tip: when I looked at this exercise I noticed one thing that you need to do is select a shape and move it. So I programmed that one task up. And got it working. Without all the detail, I can add this later.

    It's easier to get parts working in a few lines of code rather then trying to do this in 100 lines of code. So for now you could abandon the details and start building some of the parts you now know that you need for the program to work.

    Here's my build sample on this part:

    CreateGW()
    '-----------------------------------Declare some Variables-------------------------------------------------------------------------------
    'you can sort of work out what variables you want as you build your program, and work out the best name for them.
    target_X1 = 50
    target_Y1 = 60
    X1 = gw - 70 - 10 ' this is  =  gw - the width of the petal -  right offset. 
    Y1 = 10
    '-------------------------------------Declare Event Handlers----------------------------------------------------------------------------
    GraphicsWindow.MouseDown = MouseDown
    GraphicsWindow.MouseMove = MouseMove
    '=======================Main Program================================================
    AddAndPositionShapes()
    '--------------------------------------Event Handlers-------------------------------------------------------------------------------------
    Sub MouseDown
      pos_X = GraphicsWindow.MouseX
      pos_Y = GraphicsWindow.MouseY
      
      If pos_X > X1 And pos_X < X1 + 70 And pos_Y > Y1 And pos_Y < Y1 + 30 Then
        selected = "petal_1"
      EndIf
    EndSub
    Sub MouseMove
      x = GraphicsWindow.MouseX
      y = GraphicsWindow.MouseY
      
      If Mouse.IsLeftButtonDown And selected = "petal_1" Then
        Shapes.Move(petal_1, x, y)
      EndIf
    EndSub
    '---------------------------------------Subroutines-----------------------------------------------------------------------------------------
    Sub AddAndPositionShapes
      opaqPetal_1 = Shapes.AddEllipse(70,30)
      petal_1 = Shapes.AddEllipse(70,30)
      
      Shapes.Move(opaqPetal_1, target_X1, target_Y1)
      Shapes.Move(petal_1, X1, Y1)
    EndSub
    Sub CreateGW
      gw = 500
      gh = 300
      GraphicsWindow.Width = gw
      GraphicsWindow.Height = gh
    EndSub

    The next step could be building into this code the mouse up event.

    Here's some interesting reading on this:  http://www.cprogramming.com/tutorial/incremental_testing.html

    So I reckon you're totally on the right track in terms of learning i.e. you know how to use the objects. Now you're working out how to put them all together into one larger event driven program.

    So sure, you can start again. Or what I would do is open a new program and start building some of the functions that you want the program to do. Like the above sample. Once you start getting the parts working you can start adding in the details when you think your program is ready for it.

    With these larger programs that have multiple events, "start small - finish big". Get the parts working without all the details.

    And don't worry if you ditch some of your earlier code, you'll find coding it the next time is a lot easier and faster. Or copy it across.


    Thursday, July 18, 2013 12:29 AM
    Moderator
  • Hi 8bit. Back again. Hopefully with a simpler and clearer approach. So you could try to code this program by:

    1. Add just 2 shapes
    2. then add the mouse events: mouse down, mouse move, mouse up
    3. attach/use these events to the shapes: select the shape, move it, then on mouse up if it's in the same location as the other shape that's the shapes new position.
    4. once you have this working you can then add in all the other shapes

    This is basically a summary of the above sample I did.

    Martins sample above is a really good, it would be worth trying out that method. And just workout how to work the shapes into it. Copy his sample as is and run it. Very nice.

    Good luck. Bit by bit



    Thursday, July 18, 2013 10:48 AM
    Moderator
  • Thank you for your help. c: I will try again at it right now! and i'll try and use your samples to help me.

    I am a 13 year old who loves coding, and is eager to learn more about it!

    Thursday, July 18, 2013 7:28 PM
  • My opinion...

    You've done well. You've shown that you can code and manipulate the shapes required for this program.

    You could now look at this as having programmed the "details" that you want in this program.

    The snag you've hit is the "build" of your program. Normal when building more eventful and featured programs. The fun part. This will take you back over the things you've learnt so far and quite often you will have to go back and do a quick refresher on them. Referencing. Not too painful.

    To do this "build" you'll benefit from breaking the code up into smaller working parts (without all the detail). Test these smaller parts and get them working. Incremental Development.

    Tip: when I looked at this exercise I noticed one thing that you need to do is select a shape and move it. So I programmed that one task up. And got it working. Without all the detail, I can add this later.

    It's easier to get parts working in a few lines of code rather then trying to do this in 100 lines of code. So for now you could abandon the details and start building some of the parts you now know that you need for the program to work.

    Here's my build sample on this part:

    CreateGW()
    '-----------------------------------Declare some Variables-------------------------------------------------------------------------------
    'you can sort of work out what variables you want as you build your program, and work out the best name for them.
    target_X1 = 50
    target_Y1 = 60
    X1 = gw - 70 - 10 ' this is  =  gw - the width of the petal -  right offset. 
    Y1 = 10
    '-------------------------------------Declare Event Handlers----------------------------------------------------------------------------
    GraphicsWindow.MouseDown = MouseDown
    GraphicsWindow.MouseMove = MouseMove
    '=======================Main Program================================================
    AddAndPositionShapes()
    '--------------------------------------Event Handlers-------------------------------------------------------------------------------------
    Sub MouseDown
      pos_X = GraphicsWindow.MouseX
      pos_Y = GraphicsWindow.MouseY
      
      If pos_X > X1 And pos_X < X1 + 70 And pos_Y > Y1 And pos_Y < Y1 + 30 Then
        selected = "petal_1"
      EndIf
    EndSub
    Sub MouseMove
      x = GraphicsWindow.MouseX
      y = GraphicsWindow.MouseY
      
      If Mouse.IsLeftButtonDown And selected = "petal_1" Then
        Shapes.Move(petal_1, x, y)
      EndIf
    EndSub
    '---------------------------------------Subroutines-----------------------------------------------------------------------------------------
    Sub AddAndPositionShapes
      opaqPetal_1 = Shapes.AddEllipse(70,30)
      petal_1 = Shapes.AddEllipse(70,30)
      
      Shapes.Move(opaqPetal_1, target_X1, target_Y1)
      Shapes.Move(petal_1, X1, Y1)
    EndSub
    Sub CreateGW
      gw = 500
      gh = 300
      GraphicsWindow.Width = gw
      GraphicsWindow.Height = gh
    EndSub

    The next step could be building into this code the mouse up event.

    Here's some interesting reading on this:  http://www.cprogramming.com/tutorial/incremental_testing.html

    So I reckon you're totally on the right track in terms of learning i.e. you know how to use the objects. Now you're working out how to put them all together into one larger event driven program.

    So sure, you can start again. Or what I would do is open a new program and start building some of the functions that you want the program to do. Like the above sample. Once you start getting the parts working you can start adding in the details when you think your program is ready for it.

    With these larger programs that have multiple events, "start small - finish big". Get the parts working without all the details.

    And don't worry if you ditch some of your earlier code, you'll find coding it the next time is a lot easier and faster. Or copy it across.



    This solution could become a TechNet Wiki article and enter the July Small Basic Guru contest: http://social.technet.microsoft.com/wiki/contents/articles/18211.technet-guru-contributions-july-2013.aspx

     

    Great job!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Tuesday, July 23, 2013 6:39 AM
    Owner
  • Hi Ed and thanks.

    As a sincere fan and beneficiary of wiki learning I'd be glad to participate with an article. I'll start with this thread.

    Out of all the wikis the one thing I like the most about TechNet wiki is that it's so readable.

    I can't say if it will ready for July 31 but we'll see what happens.


    Tuesday, July 23, 2013 11:52 AM
    Moderator
  •  Thank you for the help everyone! I have manage to finish it. It's very rough, but it does meet the requirements of the lesson 4.1 show what you know. :3 I am so glad i finished it! Import it if you want to look at it and play it.

    Thanks again!!!!!!!

    import: WNX705


    I am a 13 year old who loves coding, and is eager to learn more about it!

    Saturday, July 27, 2013 4:34 AM
  • Way to go 8bit. That runs perfectly.

    Saturday, July 27, 2013 6:34 AM
    Moderator
  • Hi Ed and thanks.

    As a sincere fan and beneficiary of wiki learning I'd be glad to participate with an article. I'll start with this thread.

    Out of all the wikis the one thing I like the most about TechNet wiki is that it's so readable.

    I can't say if it will ready for July 31 but we'll see what happens.


    How about August? =^)

    Thanks Jibba Jabba!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Monday, August 5, 2013 6:40 AM
    Owner
  • I should be able to do this by then.

    I'm working on the duck shoot challenge atm and having some success with it. I think it will make a good sample along with some parts of a solution to the show what you know exercise in 4.1

    I think this build in parts concept really starts to become relevant in ch 4.1

    Thanks

    Monday, August 5, 2013 10:23 AM
    Moderator