Page 2 of 3

Re: Spirograph what I did from lesson 10

Posted: May 27th, 2012, 12:13 pm
by Asimov
Hi chilli,

Well I don't quite understand the theory behind how the rotation works. I can however modify bits to make it faster or slower. I know enough to make it do what I want, but don't understand why it works.

Anyway I thought I would randomize the colours. Now I run into a couple of problems here.
First of all the randomizing works, but much to fast.
I had a bit of fun with scope LOL. For a start I initialized r,g,b inside an if statement, and instantly found it wouldn't work outside of the if statement, and then so I had to take it outside the if statement for scope to work.

Anyway I got it to work. Now over a period of time the colours change. Next I would like the colours to slowly transcend from one colour to the next. So I am thinking that once the random number is picked, instead of instantly changing it should change slower. That is my next goal.
Of course this code will only work in time correctly on my computer. Also I have upped the rotation speed to some crazy speed to give a cool effect.

Also later I think this random colour generator should be made a function which returns the values of r,g,b and I think that would make my code cleaner, and also I can re-use this function in other parts of my code. Actually it might be better to make it a class and then I can incorporate all the timing information in the class itself. I am probably trying to run before I can walk heh heh.

I tried to send the zip file, but for some reason even though I only changed a few lines it is 17mb and the file limit here is 10mb.

Here is my code so far

Code: Select all

if (colchange>100)
	{
		r=(rand() % 255);
		g=(rand() % 255);
		b=(rand() % 255);
		colchange=0;
	}

	colchange++;
	Draw( rotationAngle,400,250,r,g,b );
Asimov

Re: Spirograph what I did from lesson 10

Posted: May 27th, 2012, 12:38 pm
by LuX
The project is huge, because it generates all the files it needs once you run it (debug stuff).
Before you send it here, clear it from these files, as it will be generated for us again as well.
see: http://www.planetchili.net/forum/viewtopic.php?f=3&t=2

Re: Spirograph what I did from lesson 10

Posted: May 27th, 2012, 1:09 pm
by Asimov
Hi Lux,

You are so right. Thanks. How stupid of me.

I have attached the file now. Only 450k.

I am now planning on making a colour Class rather than having all the code in the main game Class.
It's been a long time since I have made a Class, so I am a bit vague, but I am going to make a separate header file and cpp file like Chilli has done. Before I used to make them all in the header files, so this will be something new to me. So in theory I won't have to set my r,g,b values in the Game class, they will be set in the contructor of the Colour Class. I will probably screw this up LOL.

You won't believe this. Last night I was watching the Tic tac toe tutorial and I fell asleep and when I woke up I was up to lesson 18 LOL. Will have to re-watch now.

Asimov

Re: Spirograph what I did from lesson 10

Posted: May 27th, 2012, 3:22 pm
by chili
Funky modification you made there Asimov! By the way, when you uploaded the project you forgot to delete the Debug folder from the Framework sub-folder.

Don't worry about screwing shit up, that's where all the real learning is done anyways. ;) I will be starting classes and stuff within the next three or four lessons, so you'll have a head start at least.

Re: Spirograph what I did from lesson 10

Posted: April 1st, 2017, 7:19 pm
by krautersuppe
Hi authors of spirocrap,

i modified the star code to make a cell out of it. I also added variables for positioning and resizing of star and also for making more lines in the drawing grid. I wonder though why the crap is being drawn so slow.
asimovs_star_plus_cell.zip
(33.87 KiB) Downloaded 227 times
Here a visual of how separate parts of star and cell are drawn according to code:
Lesson_10_asimovs_star.jpg
(63.25 KiB) Not downloaded yet

Re: Spirograph what I did from lesson 10

Posted: April 5th, 2017, 3:22 pm
by MrMatt0111
Well, minor time saving would be to make all Drawing function's parameters "const int& " instead of just ints, as it's copying these values for no good reason.

See image, at larger radius sizes it's taking 14 seconds to run through the while loop you have setup. There's alot to draw there :o

Re: Spirograph what I did from lesson 10

Posted: April 5th, 2017, 3:25 pm
by chili
Are you running that in Release? With the debugger detached?

Re: Spirograph what I did from lesson 10

Posted: April 5th, 2017, 3:58 pm
by MrMatt0111
Yes - but i just went and tried it again and it's down to 10 ms... my computer must've taken a poop.

Re: Spirograph what I did from lesson 10

Posted: April 5th, 2017, 10:01 pm
by Asimov
Hi Mr Matt,

I would download and have a look, but had to uninstall visual studio 2010 to do some stuff. Only got QT installed at the moment because I am making some application software and it is a little quicker in QT to do what I want.

I will re-install visual studio 2010 and have a look at these soon.

Re: Spirograph what I did from lesson 10

Posted: April 6th, 2017, 1:17 am
by chili
Yeah I was gonna say! Anyways, as for optimizations, the pass-by-value vs. pass-by-reference is usually not that big of a win. In this case it is actually technically faster to pass by value (although it probably doesn't matter either way actually; the compiler is gonna inline that shit anyways).