Announcement

Collapse
No announcement yet.

Need some JavaScript help if possible

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need some JavaScript help if possible

    Hey guys! long time no see. I have been trying to wrap up a few more courses so I can finally graduate from college and just started a scripting class that is kicking my ass. I know a lot of you are computer savvy and may happen to know JavaScript. My assignment is to do a basic code for 4 different flags, Jamaica, Seychelles, Macedonia, Bahrain. I work in notepad++ but am brand new to this world and have no clue how to go about the assignment and troubleshoot. Is there anyone who could possibly give me some help if I sent them the code I have so far? It is a mess haha.
    Any help would be greatly appreciated!!!

    Hope to see you all in BF1 on a more fun note

    Recon

    #2
    Can't give you specifics but the best way to go about it for me would be...
    (sorry this is raw out of my head, so its a bit messy)

    Guessing the purpose is to get you thinking about storage and looping, because the data you need can be stored like that.
    (Know how many people I seen fail in my College days because they hard coded 'points' in to the program instead of using an array)
    So I'd have an array of bits with point arrays, so break the flag up into parts to draw.

    the black fill (dont need to map this)
    2x yellow stripes
    2x green triangles.
    OK how do you do those with out silly path calcs and stuff easy

    so you would have an array of

    {
    rot,
    lines = [
    [x,y],
    [x,y],
    [x,y],
    [x,y],
    [x,y],
    ],
    color,
    ]

    then use a set of loops to go over those steps.
    means you dont have a simple script and also you can adjust as needed, plus you can have multiple points in the line property not just 4 (bahrain)
    just need to step back and break them up into moves.

    so Jamiaca
    take the rectangle,
    fill green how you see fit (trust me)

    then using loops
    - rotate by rotate
    - new path
    - loop points
    -- draw a to b
    - close
    - fill


    So you would have this array (sorry i got lazy and just typed 1/2 it)
    [{
    rot: 0,
    lines: [],
    color: "#00ff00"
    },{
    //draw black triange
    rot: 59,
    lines: [
    [250,0],
    [250,290],
    [0,151]
    ],
    color: "#000000"
    },{
    //draw black triange on opposite side
    rot: 180,
    lines: [
    [250,0],
    [250,290],
    [0,151]
    ],
    color: "#000000"
    },{
    // draw yellow stripes
    [
    152,[
    [0,239],
    [0,272],
    [584,239],
    [584,272],
    (yellow)
    ],
    [
    119,[
    [0,239],
    [0,272],
    [584,239],
    [584,272],
    (yellow)
    ],
    //rotate back
    [-31,
    [],
    -1
    ],
    //draw circle (just an example)
    [0,
    [x,y,radius],
    (yellow)
    ]

    so your pseudo is:
    Code:
    flagsteps = (array above)
    for (i = 0; i < flagsteps .length; i++) begin
       flagstep = flagsteps[i]
       // Just rotate
       if color = -1 then
         canvas.rotate by flagstep.rot
       // Flood fill canvas
       else if flagstep.lines.length = 0 then
          canvas.fillcolor = flagstep.color
          canvas.fillrect(0, 0, canvas.width, canvas.height)
       // Lines and Circles
       else
          canvas.startpath
          // Just incase (you never know??, should never happen though
          if (flagstep.lines.length > 0) begin
                points = flagstep.lines[0]
                canvas.moveTo points[0] points[1]
                // Circle
                if points.length > 2 begin
                      //circle
                      canvas.arc(points[0],points[1],points[2],0,Math.PI*2,true) 
                // Funky shape, not just for squares!
                else
                      for (iline = 1; iline < flagstep.lines.length; iline++) begin
                            points = flagstep.lines[iline]
                            canvas.drawline from points[0] to points[1]
                      endfor
                endif
          endif
          canvas.endpath
          canvas.fillcolor = flagstep.color
          canvas.fill
       endif  
    endfor
    so what you have here is a looping code (you can use for them all i think)
    it has an array of 'parts' to make,
    an instruction set (the -1 color) to just rotate
    and it will fill the canvas on no lines.

    really you dont need the rotate/arc stuff if you are willing to plot it,
    but i thought you'd put that in there for you incase you want to use it for seychelles or mecedonia (to keep the centre distances)

    for a non fancy version you would just have a list of points to draw in an array like before and loop it similar to that.

    What the above is doing is providing a step by step guide, and you are just looping over each step and following it.
    the 3 value array in line[0] makes it draw an circle
    a -1 color just rotates
    and no lines will fill canvas

    nice thing is because you ahve not programmed in step by step you can tweak each one.
    rotating is a bit ott but to be honest, its easier to work with a canvas when you rotate it to work with.
    think of your dinner plate, you rotate it to get to the stuff at the back for ease.
    because the canvas API will draw a stright line anyway this causes it to be ott,
    but when you use rotate it allows you to get proportions right if you where to scale say, its a pain to repoint some shapes (and also keeps pretty numbers in your script)

    plus if you really want to get fancy you could array all 4 flags flagsteps into one and loop over those and draw them side by side.
    have like
    [{
    name: "placename",
    steps: ...
    canvasid: divFlag1
    },{
    name: "placename2",
    steps: ...
    canvasid: divFlag2
    },

    and loop that settings variables up etc




    I'm not insane. I'm just overwhelming!

    ·····••••• Support Cainslair. Donate here!•••••·····
    ·····••••• and get extra options! •••••·····

    Comment


      #3

      Comment


        #4
        Originally posted by goldenfooler View Post
        Lol know my Boss does that...
        Always breaks out the metaphorical popcorn when he throws a problem my way.




        I'm not insane. I'm just overwhelming!

        ·····••••• Support Cainslair. Donate here!•••••·····
        ·····••••• and get extra options! •••••·····

        Comment


          #5
          i am going to send this to my nephew and see if he can understand it.

          Comment


            #6
            Lemme know if he can, raw out my head stuffs pretty jumbled up...
            Though this ones pretty ok.

            Should see my written stuff for things I do... eventually even I cant make head nor tail of it.




            I'm not insane. I'm just overwhelming!

            ·····••••• Support Cainslair. Donate here!•••••·····
            ·····••••• and get extra options! •••••·····

            Comment


              #7
              Originally posted by Sirex View Post
              Lemme know if he can, raw out my head stuffs pretty jumbled up...
              Though this ones pretty ok.

              Should see my written stuff for things I do... eventually even I cant make head nor tail of it.
              wait you didn't write the bf code did you

              Comment


                #8
                Lol na i had it all would work

                I may have a very messy documentation/note style but I have alot of care and thought in what I code.

                Was actually told ive got a very unique but accutate and thought out coding style.
                So much so I helped my brother one time and his lecturer said "your brother gave you hints huh?"

                Can't really see it myself but i do code a little diff from most folk.
                I see stuff on the net and if I use it you can see its not mine in the code.

                Lectures used to tell me I had a knack for getting square pegs into round holes... in a good way.




                I'm not insane. I'm just overwhelming!

                ·····••••• Support Cainslair. Donate here!•••••·····
                ·····••••• and get extra options! •••••·····

                Comment

                Cain's Lair Forums Statistics

                Collapse

                Topics: 26,182   Posts: 269,814   Members: 6,176   Active Members: 2
                Welcome to our newest member, 28Farrell8.

                Today's Birthdays

                Collapse

                There are no members with birthdays today.

                Top Active Users

                Collapse

                There are no top active users.

                More Posts

                Collapse

                • Reply to 6 years
                  by Apache Warrior
                  6 Mar 2024, 08:29 AM
                • Reply to 6 years
                  by Sirex
                  I think there is like a magical time span when bikes become worth a fortune.

                  Yeah thought its now or never haha
                  Just hit 2.5K miles...
                  5 Mar 2024, 04:37 PM
                • Reply to Hey Guys...It's BrundleFly
                  by Sirex
                  Hey Brundle nice to see your post I remember you very well hows thing with you.

                  Not a busy place here these days but its still up and occasionally...
                  5 Mar 2024, 04:34 PM
                • Reply to Hell Let Loose
                  by Sirex
                  Hey nice to see you

                  Its not a busy place, least not as busy as it once was but you still get the odd message posted every few weeks...
                  5 Mar 2024, 04:31 PM
                • Reply to I had Open Heart Surgery!!
                  by Sirex
                  Wow its amazing how well the body can cope with things it deams normal.

                  Hope your recovering well and back to full steam.

                  OH...
                  5 Mar 2024, 04:28 PM
                Working...
                X