Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Snowman w/ snowflakes that fall

Author
Message
Darkbluedeath
13
Years of Service
User Offline
Joined: 27th Aug 2011
Location:
Posted: 21st Sep 2011 00:56
Ok im in C++ using the Tony Gaddis book and im having some trouble with the snowman. i have everything i need for the snowman i just need to figure out how to get a octagon to have lines coming from each end that change with the size of the octagon..

like imagine a snowflake i need to get an octagon to sorta resemble the snowflake. and if i change the size of the octagon the little here is the code for the example look im going for.
#include "DarkGDK.h"

void drawOctagon();

void DarkGDK()

{

drawOctagon();
dbWait(100);
drawOctagon();
dbWait(100);
drawOctagon();
dbWait(100);
drawOctagon();
dbWait(100);
drawOctagon();
dbWait(100);
drawOctagon();
dbWait(100);
drawOctagon();
dbWait(100);
drawOctagon();
dbWait(100);
drawOctagon();
dbWait(100);

dbWaitKey();
}

void drawOctagon()
{
int screenWidth;
int screenHeight;
int seed;
seed=dbTimer();
dbRandomize(seed);
screenWidth=dbScreenWidth();
screenHeight=dbScreenHeight();
int x=dbRND(screenWidth);
int y=dbRND(screenHeight);
int Size=35;
int x1=x-Size/2;
int x2=x-Size/4;
int x3=x+Size/4;
int x4=x+Size/2;
int y1=y-Size/2;
int y2=y-Size/4;
int y3=y+Size/4;
int y4=y+Size/2;
int size=size/2;
dbLine(x1,y2,x2,y1);
dbLine(x2,y1,x3,y1);
dbLine(x3,y1,x4,y2);
dbLine(x4,y2,x4,y3);
dbLine(x4,y3,x3,y4);
dbLine(x3,y4,x2,y4);
dbLine(x2,y4,x1,y3);
dbLine(x1,y3,x1,y2);

dbLine(x2,y1,x2-5,y1-5);
dbLine(x1,y2,x1-5,y2);
dbLine(x3,y1,x3+5,y1-5);
dbLine(x4,y2,x4+5,y2);
dbLine(x1,y3,x1-5,y3);
dbLine(x2,y4,x2-5,y4+5);
dbLine(x3,y4,x3+5,y4+5);
dbLine(x4,y3,x4+5,y3);

dbCircle(x2-7,y1-7,2);
dbCircle(x1-7,y2,2);
dbCircle(x3+7,y1-7,2);
dbCircle(x4+7,y2,2);
dbCircle(x1-7,y3,2);
dbCircle(x2-7,y4+7,2);
dbCircle(x3+7,y4+7,2);
dbCircle(x4+8,y3,2);


Darkbluedeath
Darkbluedeath
13
Years of Service
User Offline
Joined: 27th Aug 2011
Location:
Posted: 21st Sep 2011 01:31
well i was wanting it to put it in the code thinggy but i guess i did it wrong. but as you can see i have to put it random, and i have the Int Size=50; so i could work on it but when i reduced the size to 10 so it would be small enough for a snowflake the lines that i added were way to long and the circle didnt shrink with it.. can i get some help here?

Darkbluedeath
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 23rd Sep 2011 08:31
So the problem is that if you change the size of the octagon, then the length of the lines and the radius of the circles should change as well? You can calculate the percentage between the size of these objects. For example, if the octagon is size 35 and you add 5 pixels to the line coordinates, then you can get the line length by dividing the octagon size with 7. So you can scale the lines by using, for example:



(This is not quite accurate of course, because line length is not equal to adding pixels in both directions, but it's OK for a simple graphic.)

Something similar can be done to calculate the circle radius. However, keep in mind that your lines and circles are already pretty small. The circle radius in your example is 2 pixels, you can go down to 1 pixel but it won't get any smaller than that. So I don't know if it's worth at all to introduce such calculation. It's simpler to just change the numbers in your drawing commands until the snowflake looks good enough.

Login to post a reply

Server time is: 2024-11-19 07:11:51
Your offset time is: 2024-11-19 07:11:51