BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LauraRK
Quartz | Level 8

I updated my polar rose code to add animation:

Anim.gif

ods graphics / imagefmt=GIF width=4in height=5in;     /* each image is 4in x 5in GIF */
options papersize=('4 in', '5 in')                    /* set size for images */
        nodate nonumber                               /* do not show date, time, or frame number */
        animduration=0.5 animloop=yes noanimoverlay   /* animation details */
        printerpath=gif animation=start;              /* start recording images to GIF */
ods printer file="&outpath\Anim.gif";  /* images saved into animated GIF */

%macro makedata;
	data Roses;
		/* the array below has a list of multipliers that make 
			pretty roses, it is temporary, so will not be saved
			with the data*/
		array klist{11} _temporary_ (4, 5, 6, 1.5, 2.5, 1.333333, 2.33333, .75, 1.25, 1.2, .8333333);
		
		do flower=1 to 12;
			n = ceil( 11*rand("Uniform") );
			/*pick a random number
					between 1 and 11*/
			k=klist{n}; /*assign k to be the nth multiplier*/

			/* draw the rose r=cos(k * theta) */
			do theta = 0 to 12*constant("pi") by 0.1;
				r = cos(k * theta);      /* generalized rose */
				x = r*cos(theta);        /* convert to Euclidean coords */
				y = r*sin(theta);

				/*move the rose to the right spot*/
				if flower <= 5 then
					do;
						cx=2*flower+1;
						cy=9;
					end;
				else if 6<= flower<=9 then
					do;
						cx=(2*flower-8);
						cy=10.5;
					end;
				else if 10<= flower<=12 then
					do;
						cx=(2*flower-15);
						cy=12;
					end;

				x=x+cx;
				y=y+cy;
				group=flower;
				do i=0 to flower; output; end;

				/*make the stem*/
				group=flower+.5;
				x=cx;
				y=cy;
				do i=0 to flower; output; end;
				x=7;
				y=3;
				do i= 0 to flower; output; end;
			end;
		end;

		/*bow*/
		do theta = constant("pi")*7.5/12 to constant("pi")*28.5/12 by 0.01;
			r = cos(2 *(theta));       /* rose */
			x = r*cos(theta);          /* convert to Euclidean coords */
			y = r*sin(theta);
			group=100;
			i=0;
			if y<abs(x) then
				do;
					x=x+7;
					y=y+3;
					output;
				end;
		end;
	run;

%mend;

%makedata;
data roses2 ;
  set roses;
  i=13-i;
run;

proc sort data=roses2;
	by i group;
run;


options nobyline;
proc sgplot data=Roses2  aspect=1 noautolegend
	noborder nowall noopaque;;
	by i;
	styleattrs datacontrastcolors=
		( 
		red green 
		 bippk green red green purple green bippk green
		blue green purple green  bippk green red green purple green
blue green red green
		crimson 
			) datalinepatterns=(1);
	series x=x y=y /group=group;
	xaxis min=1 max=13 display=none;
	yaxis min=2 max=13 display=none;
	title1 "Happy Valentine's Day";
	title2 "A Dozen Random Polar Roses for &for";
	footnote1 "From, &from";
/*	footnote2 " Polar Roses: r = cos(k*theta)";
	footnote3 " Generated with the SAS System 9.4";
	footnote4 "see: http://blogs.sas.com/content/iml/2015/12/16/polar-rose.html";
*/
	run;
                                /* restore screen output */
 
options printerpath=gif animation=stop;               /* stop recording images */
ods printer close;   

title;
footnote;
LauraRK
Quartz | Level 8

If you want one to send to someone and do not want to run the code yourself feel free to copy the one belowYouAnim.gif

ChrisHemedinger
Community Manager

Featured in the SAS Software Instagram today!

 

https://www.instagram.com/p/Bt3caapHbmC/

 

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 33 replies
  • 8537 views
  • 164 likes
  • 14 in conversation