Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for [[/eggref/5/2d-primitives|the CHICKEN 5 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-5.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: egg]] == 2d-primitives [[toc:]] === Description A collection of primitives and linear algebra common for 2D graphics and 2D games. === Author Richard van Roy (pluizer) === Requirements none === Documentation ==== Floating points <procedure>(fmod numer denom)</procedure><br/> Returns the floating-point remainder of numer/denom (rounded towards zero). <procedure>(clamp f mmin mmax)</procedure><br/> Clamp a floating-point number to a minimum and a maximum. <procedure>(sqr x)</procedure><br/> Square a number. <constant>(float-min)</constant><br/> Minimum representable floating-point number. <constant>infinity</constant><br/> ==== Constants <constant>epsilon</constant><br/> <constant>pi</constant><br/> <constant>pi/2</constant><br/> <constant>2pi</constant><br/> <constant>-pi</constant><br/> <constant>360/2pi</constant><br/> <constant>2pi/360</constant><br/> ==== Angles <procedure>(radian->degree radians)</procedure><br/> <procedure>(degree->radian degrees)</procedure><br/> <procedure>(flip-radian-h radians)</procedure><br/> <procedure>(flip-radian-v radians)</procedure><br/> <procedure>(flip-degree-h degrees)</procedure><br/> <procedure>(flip-degree-v degrees)</procedure><br/> ==== Vectors <procedure>(vect:create x y)</procedure><br/> Returs a new vector <procedure>(vect? obj)</procedure><br/> <procedure>(vect:x v)</procedure><br/> <procedure>(vect:y v)</procedure><br/> <procedure>(zero-vect)</procedure><br/> Constant for the zero vector. <procedure>(vect=? a b #!optional (epsilon .001)</procedure><br/> Check if two vectors are equal. <procedure>(vect+ a b)</procedure><br/> Add two vectors. <procedure>(vect- a #!optional b)</procedure><br/> Subtract two vectors or negate a vector. <procedure>(vect* v s)</procedure><br/> Scalar multiplication. <procedure>(vect:dot a b)</procedure><br/> Vector dot product. <procedure>(vect:cross a b)</procedure><br/> 2D vector cross product analog. The cross product of 2D vectors results in a 3D vector with only a z component. This function returns the magnitude of the z value. <procedure>(vect:perp v)</procedure><br/> Returns a perpendicular vector. <procedure>(90 degree rotation)</procedure><br/> <procedure>(vect:vperp v)</procedure><br/> Returns a perpendicular vector. <procedure>(-90 degree rotation)</procedure><br/> <procedure>(vect:project a b)</procedure><br/> Returns the vector projection of /a/ onto /b/. <procedure>(angle->vect a)</procedure><br/> Returns the unit length vector for the given angle (in radians). <procedure>(vect->angle v)</procedure><br/> Returns the angular direction v is pointing in (in radians). <procedure>(vect:rotate a b)</procedure><br/> Uses complex number multiplication to rotate /a/ by /b/. Scaling will occur if /a/ is not a unit vector. <procedure>(vect:unrotate a b)</procedure><br/> Inverse of vect:rotate <procedure>(vect:length-squared v)</procedure><br/> Returns the squared length of v. Faster than /(vect:length)/ when you only need to compare lengths. <procedure>(vect:length v)</procedure><br/> Returns the length of v. <procedure>(vect:lerp v1 v2 t)</procedure><br/> Linearly interpolate between /a/ and /b/. <procedure>(vect:normalize v)</procedure><br/> Returns a normalized copy of v. <procedure>(vect:clamp v len)</procedure><br/> Clamp v to length len. <procedure>(vect:lerp-const v1 v2 dist)</procedure><br/> Linearly interpolate between v1 towards v2 by distance d. <procedure>(vect:dist v1 v2)</procedure><br/> Returns the distance between v1 and v2. <procedure>(vect:dist-squared v1 v2)</procedure><br/> Returns the squared distance between v1 and v2. Faster than /(vect:distance)/ when you only need to compare distances. <procedure>(vect:near? a b dist)</procedure><br/> Returns true if the distance between v1 and v2 is less than dist. <procedure>(vect:spherical-lerp a b t)</procedure><br/> Spherical linearly interpolate between /a/ and /b/. <procedure>(vect:spherical-lerp-const a b angle)</procedure><br/> Spherical linearly interpolate between /a/ towards /b/ by no more than angle /angle/ in radians. ==== Bounding Boxes <procedure>(rect:create l r b t)</procedure><br/> Returs a new bounding box. <procedure>(rect? obj)</procedure><br/> Can also be a line. <procedure>(rect:l rect)</procedure><br/> <procedure>(rect:r rect)</procedure><br/> <procedure>(rect:b rect)</procedure><br/> <procedure>(rect:t rect)</procedure><br/> <procedure>(rect:for-circle p r)</procedure><br/> Constructs a /rect/ for a circle with the given position and radius. <procedure>(rect:intersects? a b)</procedure><br/> Returns true if /a/ and /b/ intersect. <procedure>(rect:contains? rect other)</procedure><br/> Returns true if /other/ lies completely within /rect/. <procedure>(rect:constains-vect? rect v)</procedure><br/> Returns true if /rect/ contains /v/. <procedure>(rect:merge a b)</procedure><br/> Returns a bounding box that holds both bounding boxes. <procedure>(rect:expand rect v)</procedure><br/> Returns a bounding box that holds both /rect/ and /v/. <procedure>(rect:center rect)</procedure><br/> Returns the center of a bounding box. <procedure>(rect:area rect)</procedure><br/> Returns the area of the bounding box. <procedure>(rect:merged-area a b)</procedure><br/> Merges /a/ and /b/ and returns the area of the merged bounding box. <procedure>(rect:segment-query rect a b)</procedure><br/> Returns the fraction along the segment query the bounding box is hit. Returns /infinity/ if it doesn't hit. <procedure>(rect:intersects-segment? rect a b)</procedure><br/> Return true if the bounding box intersects the line segment with ends /a/ and /b/. <procedure>(rect- rect vect)</procedure><br/> Substracts a vector from a rectangle. <procedure>(rect+ rect vect)</procedure><br/> Adds a vector to a rectangle. ==== Lines <procedure>(line:create a b)</procedure><br/> Makes a line from two vectors <procedure>(line? obj)</procedure><br/> Can also be a rect. ==== Polygons <syntax>(polygon:create vects)</syntax><br/> Creates a new polygon from a list of vectors. <procedure>(polygon->vects polygon)</procedure><br/> Converts a polygon to a list of vertices. <procedure>(polygon:triangulate polygon)</procedure><br/> Triangulates the given polygon and returns an array of vectors. <procedure>(polygon:triangulate->triangles polygon)</procedure><br/> Same as polygon-triangulate but returns a list of triangles. <procedure>(polygon-convex? polygon)</procedure><br/> Return #t if the given polygon is convex. <procedure>(convex-hull vects)</procedure><br/> Returns the convex hull of a group of vertices in clockwise order. <procedure>(polygon:convex-hull vects)</procedure><br/> Converts any polygon to a convex polygon. ==== Bezier curves <procedure>(bezier:create control-points ...)</procedure><br/> Creates a new bezier curve with a minimum of two control-points. <procedure>(bezier:ref bezier n)</procedure><br/> Return the point of a bezier at position n, where 0.0 is the start of the curve and 1.0 is the end. <procedure>(bezier->vects bezier accuracy)</procedure><br/> Returns a list of points that make of a bezier curve. A higher /accuracy/ results in a higher resolution (more points). ==== Colours <procedure>(rgb:create r g b #!optional (a 1.0)</procedure><br/> Creates a new RGB colour <procedure>(rgb:r rgb)</procedure><br/> <procedure>(rgb:g rgb)</procedure><br/> <procedure>(rgb:b rgb)</procedure><br/> <procedure>(rgb:a rgb)</procedure><br/> <procedure>(rgb->hsv rgb)</procedure><br/> Convers a rgb colour to a hsv colour. <procedure>(hsv:create h s v #!optional (a 1.0)</procedure><br/> Creates a new HSV colour <procedure>(hsv:h hsv)</procedure><br/> <procedure>(hsv:s hsv)</procedure><br/> <procedure>(hsv:v hsv)</procedure><br/> <procedure>(hsv:a hsv)</procedure><br/> <procedure>(hsv->rgb hsv)</procedure><br/> Converts a hsv colour to a rgb colour.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 18 from 5?