Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
draw.c
/* |
File: draw.c |
Contains: |
Written by: EL |
Copyright: Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
08/2000 JM Carbonized, non-Carbon code is commented out |
for demonstration purposes. |
7/16/1999 KG Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#include "out.h" |
void shadeSCurve(int x, int y, int radout, int radin, int index); |
void drawColorSpheres(void); |
void createColorScale() |
{ |
int i; |
int x; |
int down = true; |
int index = 8; |
PenSize( 14, 1 ); |
for (x = -420; x < 420; x += 105) |
{ |
for (i = 0; i < 30; i++) |
{ |
setColor( index ); |
if (down == true) |
drawLine( x, 420 - (i * 28) , x, 420 - ((i + 1) * 28) ); |
else |
drawLine( x, -420 + (i * 28) , x, -420 + ((i + 1) * 28) ); |
index++; |
} |
down = 1 - down; |
} |
down = false; |
index = 8; |
for (x = 368; x > -472; x -= 105) |
{ |
for (i = 0; i < 30; i++) |
{ |
setColor( index ); |
if (down == true) |
drawLine( x, 420 - (i * 28) , x, 420 - ((i + 1) * 28) ); |
else |
drawLine( x, -420 + (i * 28) , x, -420 + ((i + 1) * 28) ); |
index++; |
} |
down = 1 - down; |
} |
} |
void createColorWheels() |
{ |
testTriangle( -400, 300 ); |
testTriangle( 400, 300 ); |
testTriangle( 400, -300 ); |
testTriangle( -400, -300 ); |
shadeWasher( 0, 0, 360, 80 ); |
} |
void createColorRings() |
{ |
shadeWasher( 0, 0, 500, 400 ); |
shadeWasher( 0, 0, 400, 300 ); |
shadeWasher( 0, 0, 300, 200 ); |
shadeWasher( 0, 0, 200, 100 ); |
} |
void createColorGears() |
{ |
shadeWasher( 150, 150, 300, 100 ); |
shadeWasher( -150, 150, 300, 100 ); |
shadeWasher( -150, -150, 300, 100 ); |
shadeWasher( 150, -150, 300, 100 ); |
} |
void createColorCurves() |
{ |
shadeWasher( 720, 720, 900, 0 ); |
shadeWasher( 720, -720, 900, 0 ); |
shadeWasher( -720, -720, 900, 0 ); |
shadeWasher( -720, 720, 900, 0 ); |
shadeWasher( 0, 0, 400, 0 ); |
} |
void createColorBalls() |
{ |
int x, y; |
for (x = -432; x <= 432; x += 108) |
for (y = -432; y <= 432; y += 108) |
shadeWasher( x, y, 60, 0 ); |
} |
void createColorWave() |
{ |
shadeSCurve( -300, 250, 210, 60, 9 ); |
shadeSCurve( 96, 250, 210, 60, 69 ); |
shadeSCurve( -300, 150, 210, 60, 129 ); |
shadeSCurve( 96, 150, 210, 60, 189 ); |
shadeSCurve( -300, 50, 210, 60, 9 ); |
shadeSCurve( 96, 50, 210, 60, 69 ); |
shadeSCurve( -300, -50, 210, 60, 129 ); |
shadeSCurve( 96, -50, 210, 60, 189 ); |
shadeSCurve( -300, -150, 210, 60, 9 ); |
shadeSCurve( 96, -150, 210, 60, 69 ); |
shadeSCurve( -300, -250, 210, 60, 129 ); |
shadeSCurve( 96, -250, 210, 60, 189 ); |
} |
void createColorText() |
{ |
Rect rect; |
PicHandle thePict; |
int width, height; |
thePict = (PicHandle)GetResource( 'PICT', 129 ); |
width = (**thePict).picFrame.right - (**thePict).picFrame.left; |
height = (**thePict).picFrame.bottom - (**thePict).picFrame.top; |
SetRect( &rect, (WWIDTH - width) / 2, (WHEIGHT - height) / 2, |
((WWIDTH - width) / 2) + width, ((WHEIGHT - height) / 2 ) + height ); |
DrawPicture( thePict, &rect ); |
ReleaseResource( (Handle)thePict ); |
} |
void drawColorSpheres() |
{ |
int rad; |
int i; |
for (i = 9; i < 48; i++) |
{ |
setColor( i ); |
rad = (48 - i) * 3; |
drawCircle( (int)(i * 1.414), (int)(i * 1.414), rad ); |
} |
} |
void testTriangle( x, y ) |
int x, y; |
{ |
PenSize( 1, 1 ); |
setColor( 7 ); |
drawCircle( x, y, 25 ); |
setColor( 1 ); |
drawWasher( x, y, 25, 60, -30, 30 ); |
drawLine( x - 60, y + 40, x, y + 140 ); |
drawLine( x, y + 140, x + 60, y + 40 ); |
setColor( 2 ); |
drawWasher(x, y, 25, 60, 30, 90 ); |
setColor( 3 ); |
drawWasher(x, y, 25, 60, 90, 150 ); |
drawLine( x + 60, y + 40, x + 121, y - 70 ); |
drawLine( x + 121, y - 70, x, y - 70 ); |
setColor( 4 ); |
drawWasher( x, y, 25, 60, 150, 210 ); |
setColor( 5 ); |
drawWasher( x, y, 25, 60, 210, 270 ); |
drawLine( x - 60, y + 40, x - 121, y - 70 ); |
drawLine( x - 121, y - 70, x, y - 70 ); |
setColor( 6 ); |
drawWasher( x, y, 25, 60, 270, 330 ); |
} |
void shadeWasher( x, y, radout, radin ) |
int x, y; |
int radout, radin; |
{ |
int ang; |
int i = 8; |
int radmid; |
radmid = radin + (radout - radin) / 2; |
for (ang = 0; ang < 360; ang += 3) |
{ |
setColor( i ); |
drawWasher( x, y, radmid, radout, ang, ang + 3 ); |
i++; |
} |
for (ang = 0; ang < 360; ang += 3) |
{ |
setColor( i ); |
drawWasher( x, y, radin, radmid, ang, ang + 3 ); |
i++; |
} |
} |
void shadeSCurve( x, y, radout, radin, index) |
int x, y; |
int radout, radin; |
int index; |
{ |
#pragma unused (radout) |
#pragma unused (radin) |
int ang; |
for (ang = 270; ang > 90; ang -= 6) |
{ |
setColor( index ); |
drawWasher( x, y, 60, 210, ang, ang - 6 ); |
index++; |
} |
for (ang = -90; ang < 90; ang += 6) |
{ |
setColor( index ); |
drawWasher( x + 198, y, 60, 210, ang, ang + 6 ); |
index++; |
} |
} |
void translate( x, y ) |
int *x, *y; |
{ |
int xx, yy; |
xx = *x / SCALE; |
yy = *y / SCALE; |
*x = xx + (WWIDTH / 2); |
*y = (-yy) + (WHEIGHT / 2); |
} |
void scale( len ) |
int *len; |
{ |
*len /= SCALE; |
} |
void drawCircle( x, y, radius ) |
int x, y; |
int radius; |
{ |
Rect rect; |
int foo = 0; |
translate( &x, &y ); |
scale( &radius ); |
SetRect( &rect, x - radius, y - radius, x + radius, y + radius ); |
PaintOval( &rect ); |
} |
void drawWasher( x, y, irad, orad, sang, eang ) |
int x, y; |
int irad, orad; |
int sang, eang; |
{ |
int width; |
Rect rect; |
translate( &x, &y ); |
scale( &irad ); |
scale( &orad ); |
width = (orad - irad) / 2; |
PenSize( width, width ); |
SetRect( &rect, x - (irad + width), y - (irad + width), |
x + (irad + width), y + (irad + width) ); |
FrameArc( &rect, sang, eang - sang ); |
PenSize( 1, 1 ); |
} |
void drawLine( sx, sy, ex, ey ) |
{ |
translate( &sx, &sy ); |
translate( &ex, &ey ); |
MoveTo( sx, sy ); |
LineTo( ex, ey ); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-03-12