Spirograph what I did from lesson 10

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Spirograph what I did from lesson 10

Post by Asimov » May 27th, 2012, 12:13 pm

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
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Spirograph what I did from lesson 10

Post by LuX » May 27th, 2012, 12:38 pm

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
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Spirograph what I did from lesson 10

Post by Asimov » May 27th, 2012, 1:09 pm

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
Attachments
SpirocrapColourChange.zip
Colour change wacky shape
(449.06 KiB) Downloaded 235 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Spirograph what I did from lesson 10

Post by chili » May 27th, 2012, 3:22 pm

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.
Chili

User avatar
krautersuppe
Posts: 91
Joined: September 14th, 2015, 10:58 pm
Location: Istanbul

Re: Spirograph what I did from lesson 10

Post by krautersuppe » April 1st, 2017, 7:19 pm

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
DSU
Discord: dsu1, GitHub: https://github.com/DSpUz

MrMatt0111
Posts: 2
Joined: March 31st, 2017, 2:18 pm

Re: Spirograph what I did from lesson 10

Post by MrMatt0111 » April 5th, 2017, 3:22 pm

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
Attachments
Capture.JPG
(31.74 KiB) Not downloaded yet

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Spirograph what I did from lesson 10

Post by chili » April 5th, 2017, 3:25 pm

Are you running that in Release? With the debugger detached?
Chili

MrMatt0111
Posts: 2
Joined: March 31st, 2017, 2:18 pm

Re: Spirograph what I did from lesson 10

Post by MrMatt0111 » April 5th, 2017, 3:58 pm

Yes - but i just went and tried it again and it's down to 10 ms... my computer must've taken a poop.

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Spirograph what I did from lesson 10

Post by Asimov » April 5th, 2017, 10:01 pm

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.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Spirograph what I did from lesson 10

Post by chili » April 6th, 2017, 1:17 am

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).
Chili

Post Reply