Forum menu
any coding bods aro...
 

[Closed] any coding bods around to help?

Posts: 4116
Full Member
 

My 1st assignment in my computer science BSc was to write a drawing program that let you rotate the drawing. around a point. In Modula-2. This was in 1988. We did have programming lessons though.


 
Posted : 13/01/2015 4:36 pm
Posts: 0
Free Member
 

[quote=Cougar ]To be fair, I've very rusty when it comes to programming, I've never touched Java or even heard of "Procedure" or what ever it's called, I'm assuming it's some form of C derivative?

Processing, it's Java. Java's not a language I've ever done much with - writing apps for my phone is on my todo list, but not near the top - but it's what I'd describe as a C style language, and at the level we're working at here the code would also compile as C. It's only when you get into the proper OO stuff it starts to differ from C++, and then there's still not a huge difference.


 
Posted : 13/01/2015 5:45 pm
Posts: 78469
Full Member
 

Yeah, that's pretty much what I thought. Cool, ta.


 
Posted : 13/01/2015 6:58 pm
Posts: 0
Free Member
 

Java's not a language I've ever done much with - writing apps for my phone is on my todo list, but not near the top

If your planning on using Android, yes it's Java, but it's a pretty different experience from working with Java in a more traditional setting. No more difficult, just different.

When I did mine 10 years ago we had a package called Turtle Java to introduce loops and things because it provided instant visual feedback into the concepts of loops / recursion / if-else etc.

"Computer Graphics" was an entirely separate module which I didn't do.

I started my degree 7 years ago and that was the first thing we did too. Graphics was a 3rd or 4th year level module working with OpenGL. I did it and it was a lot of fun, but not one of the most popular courses in terms of class size.

My brain, doesn't work like a coder but as a human (no offence). I mean, when I saw the problem, I thought I would calculate the 54 circles for n=2 to n = 8 and then get the code to display it.

Stick at it. I had a long conversation at Christmas about how people who code are able to think about problems in a different way so that it becomes easy to solve the problem at hand. It doesn't happen over night, but with practice you'll get the hang of it.


 
Posted : 13/01/2015 7:47 pm
Posts: 0
Free Member
 

Is the OP doing it by distance learning? If so I sympathise! I am not coding, but distance learning is bloody hard (currently on a path to a BSc in IT & Comms including ethical hacking).


 
Posted : 13/01/2015 9:38 pm
Posts: 12
Free Member
Topic starter
 

I'm on a coffee break during the next question so will try to reply.

Yes, it's a distance learning degree. BSc through University of London, under-written by Goldsmiths.

This module is 'Creative Computing, Image, Sound and Motion.' The reading has had a little coding such as movement of a shape, rotation of a shape and drawing a shape. It's mostly been about people's perceptions of shape, how the mind is confused. Things like the impossible triangle, Rubin's vase/face image etc.

From my reading, I'd understood FOR loops. I'd read and understood how to create a grid, a line etc and how the loops can be incremented (eg "i ++").

It did seem like an enormous jump to get to this assignment. I'm glad you didn;t find it [i]very[/i] simple, Cougar.

FWIW, I'm not impressed with the course, University. Whilst someone I know [i]must[/i] join online discussion groups for each module, can email a module supervisor with questions etc, I get no help beyond the reading list. If I'm stuck, I'm stuck.

This isn't so much a problem for maths (maths is maths is maths. Just read more!). History of computers (keep reading, you'll remember it all).

Coding is another matter though. Little things like knowing you can right click for the reference. One of the hardest parts is knowing what you can and can't do with the code. Thinking like a programmer (lemonysam's graph).

I didn't do any kind of IT at school past third year. My A levels were Economics, Physics, English and Graphics. The graphics was 100% set squares, compasses, pencils etc.

Time to crack on.

I'm now

"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 frustrating part is by far the majority of the marks come from your observations, not the code.

Thinking like a programmer, and following advice from this thread, I'm writing out what the code needs to do.

Do I need to use another loop? I think I can somehow use the i value to draw a particular circle. Somehow nesting another loop so, if i = 1 draw circle 1, if i = 2, draw circle 2 etc.

Or, and I need to get back to reading, can i say, draw result 1 (ellipse) in frame 1, then draw result 2 in frame 2.


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);
}
}


 
Posted : 14/01/2015 3:48 am
Posts: 0
Free Member
 

From looking at the code i knocked together previously you only need to change a few lines.
(I hope you've got this working already, but if not, read on)

Or, and I need to get back to reading, can i say, draw result 1 (ellipse) in frame 1, then draw result 2 in frame 2.

This is the right line of thought. Remember that the draw() method is called each frame. Think about what you need to do and what you need to change to only draw 1 circle per frame and what needs to be incremented each time draw is called to do that. Also remember that most, if not all the methods you need are on the[url= https://processing.org/reference/ ] Processing website[/url] You can read about how the draw loop works and find methods to control the frame rate, clear the buffer etc there.


 
Posted : 14/01/2015 8:11 am
Posts: 12
Free Member
Topic starter
 

I'm not close to getting it working (but am close to tears).

I got to this, but couldn't get it to work


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; //
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);

if () {

angle = (0.68)
float c = angle
translate (width/2.0, height/2.0)
rotate (c);
ellipse(x,y,20,20)

}

My latest (still not working) code is


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; //
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);
}
for (int i = 0; i = nbr_circles; i++)
{
translate (width/2.0, height/2.0);
rotate (radians());
}
}

The trouble is, when I can't get it working, there are so many reasons it may not be, I don't know where to begin to sort it out.


 
Posted : 14/01/2015 8:19 am
Posts: 31206
Full Member
 

Why are you translating and rotating?
I don't think it asked you to do that. It just wants you display one circle at a time in quick succession.

So you ditch the for-loop and instead increment which circle is displayed yourself on every frame.


 
Posted : 14/01/2015 8:45 am
Posts: 12
Free Member
Topic starter
 

Can you look at this whatnobeer (or anyone else who'll help)?

[url= http://singletrackworld.com/forum/topic/coding-bods-part-ii-if-you-still-have-patience#post-6613585 ]here[/url]


 
Posted : 14/01/2015 8:46 am
Posts: 0
Free Member
 

Earlier you had code that could draw an arbitrary number of equally spaced circles. What you need now is to draw one circle at a time each frame. It's like you said, draw circle number 1, then draw circle number 2.... Etc. Remember, the draw() method is essentially an infinite loop, where each loop is a frame, so use that loop instead of another for loop. You might want to look at the example for the draw method to get inspiration on how to track how many times the loop has been called.


 
Posted : 14/01/2015 8:48 am
Posts: 0
Free Member
 


 
Posted : 14/01/2015 8:50 am
Posts: 12
Free Member
Topic starter
 

Graham - It didn't ask for that but I've spent 9 1/2 hours today trying to "increment which circle is displayed"

I need to keep the for loop, don't I, so that x,y can be calculated if n changes.

I started off the day trying to use if / else,

based on the code at the bottom of the page, something like,

[i]if i increases by 1, draw the new ellipse[/i]

I could never get it to work. Things like it saying, no value for i. When I gave I a value [int i = 0;] then it broke the code somehow.

I can't actually remember all of the things I tried which failed. I've been sat at my computer since Friday morning!


int nbr_circles = 10;
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);

}


 
Posted : 14/01/2015 9:22 am
Posts: 3274
Free Member
 

You need to start the loop with i = 1 otherwise it will fail on the first iteration

so: for (int i = 1; i < nbr_circles; i++)

i is just a count so it deosn't really matter what value it starts with.


 
Posted : 14/01/2015 9:33 am
Posts: 31206
Full Member
 

> It just wants you display one circle at a time in quick succession.

Graham - It didn't ask for that

I'm pretty sure that's what they meant by "adapt the code so only one circle at a time is shown each in successive frame"

So if you currently have it set to draw 4 circles then on frame 0 you draw circle 0, on frame 1 you draw circle 1, on the frame 2 you draw circle 2, on the frame 3 you draw circle 3 and on the frame 4 you go back to drawing circle 0.

I need to keep the for loop, don't I, so that x,y can be calculated if n changes.

No, you need the [i]body[/i] of that loop to calculate x and y for the circle you are currently drawing, but you no longer need the loop itself because you no longer need to draw all the circles in one go.

So...

[code][s]for (int i = 0; i < nbr_circles; i++)
{[/s]
float angle = i * TWO_PI / nbr_circles;
float x = cx + 110.0 * cos(angle); // calculate x
float y = cy + 110.0 * sin(angle); // calculate y
ellipse(x, y, 20, 20);
[s]}[/s][/code]

Then let's replace "i" with something a bit more descriptive like "currentCircle"

And each time through the draw() routine you need to increase that by 1:

[code]currentCircle++;[/code]

But you don't want it to be greater than the number of circles so you check that after you increment it:

[code]if (currentCircle >= nbr_circles)
ย  ย  currentCircle = 0;[/code]

(Or if you want to be fancy pants you could do all that in one go using a modulus operator: [code]currentCircle = (currentCircle + 1) % nbr_circles;[/code] but don't worry if that is too confusing, just use the first version)

You need to start the loop with i = 1 otherwise it will fail on the first iteration

so: for (int i = 1; i < nbr_circles; i++)

Umm, no it won't? And your suggestion would give you one less circle than you need. ๐Ÿ˜€


 
Posted : 14/01/2015 11:19 am
Posts: 0
Free Member
 

I'll try and make it a bit simpler for you.

[quote=makecoldplayhistory ]I need to keep the for loop, don't I, so that x,y can be calculated if n changes.

Yes and no. Yes you still need a loop, but no you don't need the for loop. Sorry that sounds weird, but I'll try and explain...

There's nothing particularly special about a for loop, it just increments a variable and calls a set of functions with that variable, then checks whether the variable has reached a limit. You don't need a for loop for that, you can do it yourself.

For this new exercise you have to to it yourself. In the same way standard java automatically iterates a for loop, processing automatically iterates the draw() function, so you can use that as a loop. Just do the three things a for loop does:
A) initialise the loop variable
B) increment the loop variable
C) check the loop variable against the limit

B and C need to happen each iteration of the loop, so should be inside the draw() function. A should only happen once, so needs to be outside it.


 
Posted : 14/01/2015 5:15 pm
Posts: 31206
Full Member
 

There is a second thread now aracer - though he still seems to be a bit stuck.

http://singletrackworld.com/forum/topic/coding-bods-part-ii-if-you-still-have-patience


 
Posted : 14/01/2015 7:34 pm
Page 3 / 3