• This topic has 33 replies, 12 voices, and was last updated 9 years ago by IA.
Viewing 34 posts - 1 through 34 (of 34 total)
  • coding bods – part II (if you still have patience!)
  • makecoldplayhistory
    Free Member

    Still in Java / processing.

    I need to

    “adapt the code so only one circle at a time is shown each in successive frames. What happens when the frame rate is increased, decreased. How about when the number of circles is changed?”

    The code I began with is

    int nbr_circles = 2;
    void setup() {
    size(600, 600);

    smooth();
    background(255);
    }

    void draw() {
    background(255);
    float cx = width/2.0;
    float cy = height/2.0;
    fill(0);
    //float x, y; //
    for (int i = 0; i < nbr_circles; i++)
    {
    float angle = i * TWO_PI / nbr_circles;
    float x = cx + 110.0 * cos(angle);
    float y = cy + 110.0 * sin(angle);
    ellipse(x, y, 20, 20);
    }
    }

    void mousePressed() {

    if (mouseButton == LEFT) {
    if (nbr_circles < 20)
    nbr_circles = nbr_circles + 1;

    } else if (mouseButton == RIGHT) {
    if (nbr_circles > 2)
    nbr_circles = nbr_circles – 1;

    }
    }

    The code I have adapted it to so far is below. Am I on the right lines? Completely off-track (again)?

    int nbr_circles = 1;
    void setup() {
    size(600, 600);
    smooth();
    background(255);

    }

    void draw() {
    float cx = width/2.0;
    float cy = height/2.0;
    fill(0);
    //float x, y; //
    float angle = i * TWO_PI / nbr_circles;
    float x = cx + 110.0 * cos(angle);
    float y = cy + 110.0 * sin(angle);
    ellipse(x, y, 20, 20);

    for (int i = nbr_circles; i nbr_circles + 10; i++)
    {
    translate (width/2.0, height/2.0);
    rotate (radians(36));

    }
    }

    Massive thanks to anyone who’s still willing to help.

    makecoldplayhistory
    Free Member

    I’ve got to this which rotates the circle but it rotates it about x = 0, y = 0 (I think).

    Where’s it going wrong?

    int nbr_circles = 1;
    float rValue = 0;
    void setup() {
    size(600, 600);
    smooth();
    background(255);
    frameRate (2) ;
    }

    void draw() {
    rValue = rValue + 36;
    background(255);
    rotate(radians(rValue));
    float cx = width/2.0;
    float cy = height/2.0;
    fill(0);
    //float x, y; //
    for (int i = 0; i < nbr_circles; i++)
    {
    float angle = i * TWO_PI / nbr_circles;
    float x = cx + 110.0 * cos(angle);
    float y = cy + 110.0 * sin(angle);
    ellipse(x, y, 20, 20);
    }
    }

    makecoldplayhistory
    Free Member

    Update:

    So, I’ve managed to get the circles rotating about the centre, but not in the way I want.

    All of the circles rotate about the centre.

    int nbr_circles = 10;
    float rValue = 0;
    void setup() {
    size(600, 600);
    smooth();
    background(255);
    frameRate (10) ;
    }

    void draw() {
    rValue = rValue + 36;
    background(255);
    translate (width/2, height/2);
    rotate(radians(rValue));
    float cx = width/2.0;
    float cy = height/2.0;
    fill(0);
    //float x, y; //
    for (int i = 0; i < nbr_circles; i++)
    {
    float angle = i * TWO_PI / nbr_circles;
    float x = cx + 110.0 * cos(angle);
    float y = cy + 110.0 * sin(angle);
    ellipse(x, y, 20, 20);
    }
    }

    void mousePressed() {

    if (mouseButton == LEFT) {
    if (nbr_circles < 20)
    nbr_circles = nbr_circles + 1;

    } else if (mouseButton == RIGHT) {
    if (nbr_circles > 2)
    nbr_circles = nbr_circles – 1;

    }

    }

    http://sketchpad.cc/xOSZASMFJB

    lemonysam
    Free Member

    Why are you rotating? I can’t see anything that asks for that. What you’re doing draws the circles sequentially already, you just need to add some sort of delay to that happening.

    makecoldplayhistory
    Free Member

    What I need is for the first circle to appear, then the second, then the third. I’ve spent a day (9 1/2 hours and counting) trying to get one result of the for loop to show in each frame, but can’t.

    The rotation is a different approach. I thought, I can set the circles to 1 and then rotate one of them 36 deg each time, it is the same effect.

    Even though it’s not doing what it should, it’s the first time today I’ve actually achieved anything (and learnt a little about rotation).

    Can you give me any pointers as to how to change the code so I can get one result per frame?

    whatnobeer
    Free Member

    Yeah, you shouldn’t be rotating anything.

    Have you ever seen those led strips with a red light that runs up and down the strip? It looks like there’s a moving light, but of course its just the different leds being turned on and off in sequence. That’s sort of effect they want, but with circles.

    Imagine you have 360 circles, each one 1 degree apart. To have the effect of a single circle rotating you want to draw circle 1 and nothing else. Then clear the screen ans draw circle 2. Keep going for ever and you’ll have what looks like a rotating circle.

    You’ve got code that draws any number of circles. Look at the example for the draw method and see how to use a global variable. That global variable is essentially your ‘i’ in your old loop.

    https://processing.org/reference/draw_.html – read that. Copy the code and see it working. You should be able to see what you need to change to draw one circle in one frame and a different circle in the next.

    bamboo
    Free Member

    I haven’t read your previous thread to the very end, but it appeared to me that you gave up on that task eventually, and now you need to use that piece of code as a starting point, you are running into further difficulty – especially if it has taken you a day on this latest task and you are still none the wiser.

    I would suggest (if you haven’t already) going back to the first assignment, fully understanding how the different loops work, and then starting again with a fresh set of eyes. What they are asking you to do shouldn’t be that difficult if you understand the code, at the moment I get the impression you are stabbing about in the dark with it

    Apologies if this sounds harsh, it isn’t meant to be!

    makecoldplayhistory
    Free Member

    Bamboo.

    I wrote the code for the previous question in the end. I understand what it does and how it does it. It was a learning process but I learnt and managed. The code at the top of my first post here is code that I’ve written.

    I know exactly what I need to do. I need to draw each result in a new frame. I don’t know how to do that.

    I’ve been working on the assignment since Friday morning. It has to be handed in on Friday morning.

    Stabs in the dark are all I have.

    Any specific help is appreciated though.

    allthepies
    Free Member

    Draw “n” circles in one go (this is a frame)
    Delay your processing via a sleep function for “t” milliseconds (this is the end of a frame)
    If left mouse button clicked then decrease “t”
    If right mouse button clicked then increase “t”
    Go back to drawing the next frame

    That kind of thing. Experiment with different “n” values.

    lemonysam
    Free Member

    Sorry to just post this and run rather than explaining but I have to go to work…

    int nbr_circles = 80;
    float rValue = 0;
    int i = 0;
    int framerate = 30;
    int width = 600;
    int height = 600;
    void setup() {
    size(width, height);
    smooth();
    background(255);
    frameRate (framerate) ;
    loop();
    }
    void draw() {
    if(i < nbr_circles){
    background(255);
    float cx = width/2.0;
    float cy = height/2.0;
    fill(0);
    //float x, y; //

    float angle = i * TWO_PI / nbr_circles;
    float x = cx + 110.0 * cos(angle);
    float y = cy + 110.0 * sin(angle);
    ellipse(x, y, 20, 20);
    i++;
    } else {
    i=0;
    }
    }

    bamboo
    Free Member

    Ok – apologies then, I didn’t realise you had mastered the previous assignment.

    What I would say is think about what you want the software to do from one program loop to the next – i.e.

    Program loop 1 – draw a circle of radius r, in position x1, y1
    Program loop 2 – delete circle of radius r in position x1, y1, draw circle of radius r in position x2, y2
    Program loop 3, delete circle of radius r….. and so on.

    Then think about how you might use different types of loops (for, while etc) to achieve what you want. Remember that coding is just a means to an end, you need to understand exactly what you want it to do before you start trying to write your code. Write it down in pseudo code or even a flow chart before you start, and then you have your code ‘requirement’ in front of you.

    Java isn’t what I use day to day, so I can’t help you with the syntax, but there are plenty of resources about for that.

    makecoldplayhistory
    Free Member

    I’ve run that code and see the line moving up the screen.
    I’ve read about the global variable but I couldn’t work out how to use it here.

    That’s why I start off this morning using an if.

    I was trying to define it as both formula and the co-ords but couldn’t get it to work.

    Do you mean I should be defining x and y position (globally). Should I be doing that using co-ordinates?

    I tried but failed…

    lemonysam
    Free Member

    I’ve run that code and see the line moving up the screen.

    Really? Works perfectly for me… Anyway, take a look at the loop() function and what I do with i. It’s not a standard way of writing loops but it seems to be how processing wants to do it.

    n.b. this is the first time I’ve ever used processing.

    makecoldplayhistory
    Free Member

    lemonysam – when you get back to this thread. Thank you very much for your help. I actually had a little cry! Yes. That’s right. I’m man enough to cry (esp. when I’ve barely slept for 5 days!) 🙂

    I haven’t asked, wanted or expected anyone to help me cheat. The code you’ve posted is 90% of what I’ve been trying to do.

    I’m going to edit your code a little, but I’ll also need to reference you in the work and explain what I’ve changed etc. As I said, most of the marks come from the “running commentry of coding” and the observations of the final result.

    Can you email me your full name so I can properly reference your work?

    makecoldplayhistory@gmail.com

    lemonysam
    Free Member

    Ahh… ballcocks. In my haste I forgot it was an academic thing. I’m really sorry!

    I’ll email you in a second but perhaps rather than use that code exactly you could read it and understand what it does and then use that understanding to rewrite it.

    In fact there’re lots of ways to improve that code that I have no doubt you can manage yourself (see below for example) so you could come up with something better.

    llama
    Full Member

    There is a variable called frameCount, which automatically gets incremented for each frame.

    Modify the code from lesson 1 as follows

    1. Use frameRate to set the number frames per second. Do this in setup.

    2. Instead of drawing all the circles, just draw 1. So no loop now. Instead of the for loop just set the variable i so it is frameCount % numberOfCircles. Then calculate x and y just once and draw the single circle. Check online for what % (mod operator) does.

    Draw gets called automatically according to the frame rate set. Each time the frameCount is 1 more than last time.

    makecoldplayhistory
    Free Member

    Don’t apologise.

    It’s not 100% what I’m after. I need to make it more of a modification of my first and change a couple of other variables.

    Also, by having your code, I can do the larger part of the assignment which is talk about the visual effects.

    I wouldn’t e happy if I didn’t cite your code though (and then show how I changed it).

    Mike

    Flaperon
    Full Member

    ^^ What llama said. I think what they’re looking for is a demonstration of persistence of vision at high enough frame rates.

    It’s a terrible project for an introduction of programming course, since they appear to have failed to have taught you the essentials before setting the task. Unless they did and you haven’t been to the lectures? 😉

    Don’t forget that you’re paying an enormous sum in tuition fees now – your tutor will have office hours, as will the lecturer and if not, email them and ask for a quick meeting. Take along the work you’ve done and ask if you’re going along the right lines.

    Edit: I wouldn’t worry about referencing someone else’s work for this example – there’s really only one way to do it and no-one’s going to care either way!

    lemonysam
    Free Member

    Edit: I wouldn’t worry about referencing someone else’s work for this example – there’s really only one way to do it and no-one’s going to care either way!

    +1 for that.

    makecoldplayhistory
    Free Member

    flaperon – I’m doing an online degree. No lectures or seminars. No chat rooms, no discussion boards. No help. No course co-ordinator.

    I have a reading list, an examination date and 1 assignment per module. I did a ‘regular’ degree years ago. It’s amazing how much more you can learn in a lecture theatre / classroom.

    I’ve read 95% of the reading list. Certainly covered all areas of the “learning expectations for the course”. With the other assignments, although they required research, I knew most of what I needed from study before the questions were set.

    Processing is covered in a little detail. Thing’s like Brownian motion, reflection at boundaries, drawing basic shapes, but there’s certainly been a huge increase in difficulty with the assignment. Especially as the degree is a “no assumed previous knowledge” degree. They weren’t expecting programmers to take it.

    edit:

    see your +1 lemony.

    I think a quick “loosely based on code available online at stw.thisthread.com, I was able to adapt my code from the previous question so that….”

    IA
    Full Member

    I’m not going to comment on your assignment itself (others are helping, and too many cooks etc). But I do suggest you call (ideally, you have a short deadline) or email (likely lost in the mass) the course tutor/organiser and ask for help. They’ll not tell you how to do the assignment, but they should have knowledge of the materials you should be familiar with and can perhaps direct you to the useful bits of course material to reference.

    I used to set and mark uni programming assignments when I worked in academia, and I’d always try and help anyone that asked. After all, I was supposed to be teaching, not just assessing. It always surprised me how few asked!

    The only other advice I can give doesn’t help you now, but maybe will longer term if you’ve any desire to be good at programming rather than just pass the course. You need to practice, you need to try different languages, create your own side projects etc. When at uni and when teaching you could always tell those that “go it” and were good and coding, and those that it was a huge effort for. It always seemed like that, a marmite thing – one extreme or the other. I think your mind maybe needs to work in a certain way, but I’m sure you can train it. Don’t get hung up on a particular language either, e.g. you’d say someone was a good carpenter, not just good at hammering nails or sawing.

    EDIT: too slow, just seen there’s no co-ordinator or tutor, that’s a shame. In which case going forward I can only recommend practice! You could always try something like the simpler challenges at topcoder. They’re designed to be done against the clock and scored, but you could use them just as practice not against the clock.

    llama
    Full Member

    if you’ve any desire to be good at programming rather than just pass the course. You need to practice, you need to try different languages, create your own side projects etc.

    this++

    You would not expect to be able to just read about any practical skill then be able to put it into practice. Programming is a practical skill, not an academic exercise. You can’t just read and understand programming, you need to try it out.

    I still regularly do side projects to try things out despite being a pro for way longer than I care to admit.

    GrahamS
    Full Member

    Gah – didn’t see the new thread – I’ve replied to the old one. 😀

    (But it looks like you’ve got suitable help here anyway!)

    portlyone
    Full Member

    Thing’s like Brownian motion

    create your own side projects etc

    When I was learning Java I messed around creating a Brownian motion program. I started with “random” movements on a small circle. Then added in other circles. Then added a crash event so if they hit each other there were repurcussions. Then changed the sizes of the circles to stupid sizes. Then… etc etc keep building and modifying and learning

    monkeychild
    Free Member

    No chat rooms, no discussion boards. No help. No course co-ordinator.

    WTF? Worst online degree ever? The whole point of online and distance learning is bouncing ideas off fellow learners (like what you would do at a real world uni.

    Hope you get sorted.

    makecoldplayhistory
    Free Member

    Thanks for any / all help I was given.

    One more assignment left. Seems easier / more in line with any reading I’ve done.

    16 hours to go… 1400 here now. Due in at 0700 tomorrow. I’ve had 6 hours sleep a night for 6 days and haven’t left the house either. It’s amazing what can be achieved!

    Word to the wise, before you add a deadline to your calendar (and from then on, take it as gospel) check it’s Jan and not Feb!

    @Monkeychild – yep but aprrox 1/5 of the cost of OU. I expected far more of a Uni like Goldsmiths / UofLondon.

    funkynick
    Full Member

    mcph – Is it this course you are studying?

    If so, under the study materials tab it says that you should have access to student discussion forums, which is part of their ‘virtual learning environment’. It also suggests that there are online support groups as part of this as well.

    makecoldplayhistory
    Free Member

    that’s the one funky.

    I’m the only person who’s posted there. For all I know, I’m the only person taking the degree!

    Oh, but I’m taking it purely to do a primary PGCE. I chose the degree as I like messing around on computers.

    GrahamS
    Full Member

    So didn’t the “Introduction to Java and object-oriented programming” module cover a lot of this stuff? Or have they bizarrely given you programming tasks before they’ve explained how to program??

    (Just for the record a “Computing and Information Systems (BSc)” is not the same thing as a Computer Science BSc).

    IA
    Full Member

    (Just for the record a “Computing and Information Systems (BSc)” is not the same thing as a Computer Science BSc).

    +1

    Also:

    Computer Science != Software Engineering != Information Systems/IT

    I would say I’m a computer scientist, not a software engineer, for example. Though my job does require me to do some software engineering.

    Classic (debatably) Dijkstra quote:

    “Computer Science is no more about computers than astronomy is about telescopes”

    portlyone
    Full Member

    When people find out I have a MSc in Computer Science they ask if I can help them with Excel. I can, but only because I bothered to learn how to use Excel!

    IA
    Full Member

    When I was in halls at uni, and folk asked me for e.g. help with Word or something because “i did computers” I’d point them in the directions of the historians, they spent far more time typing stuff up!

    whatnobeer
    Free Member

    Computer Science != Software Engineering != Information Systems/IT

    True this, though I have no idea about other degrees, the one I did covered the first two and maybe a touch of the 3rd. We were taught the fundamentals of computer science, graphs, algorithms, how the OS works in terms of memory management etc, low level stuff as well as the higher level ‘here’s how to program’ type stuff. They were very good at teaching you the theory and not just ‘here’s how to program in Java’.

    Software engineering was covered by compulsory modules that covered pretty much what you’d expect plus group and individual work to demonstrate you could apply it.

    I know a fair few of my classmates would of liked the software engineering module to be voluntary but the feeling amongst industry types was there was no way you’d get a job/hold on to one, without the SE modules.

    I can’t imagine there’s many jobs out there today, outside of research where you’re using pure CS stuff and not doing any software engineering.

    IA
    Full Member

    not doing any software engineering.

    Well, we could go off OT into when you’re just programming and when you’re software engineering… 😉

Viewing 34 posts - 1 through 34 (of 34 total)

The topic ‘coding bods – part II (if you still have patience!)’ is closed to new replies.