Calico Processing Reference

From IPRE Wiki
Jump to: navigation, search

Click on a command for a definition and an example of usage. (Return to Calico Processing.)


Environment


window( width, height )

height()

width()

displayHeight()

displayWidth()

size( width, height )

keepAbove( [True or False] )

focused()

immediateMode( [True or False] )

frameCount()

fullscreen()

unfullscreen()


Structure


delay( milliseconds )

startLoop()

stopLoop()

loop()

noLoop()

onLoop

redraw()

frameRate( fps )

doEvents()


Input


Mouse

mouseX()

mouseY()

pmouseX()

pmouseY()

mouseButton()

isMousePressed()

onMouseClicked

onMouseDragged

onMouseMoved

onMousePressed

onMouseReleased


Keyboard

key()

keyCode()

isKeyPressed()

onKeyPressed

onKeyReleased


Conversion

toBinary( val )

toBoolean( val )

toByte( val )

toChar( val )

toFloat( val )

toDouble( val )

toInt( val )

toLong( val )

toString( val )

toHex( val )

fromHex( str )

fromBinary( str )


Time & Date

millis()

second()

minute()

hour()

day()

month()

year()


Shape


2D Primitives

arc( x, y, width, height, start-angle, end-angle )

ellipse( x, y, width, height )

line( x1, y1, x2, y2 )

point( x, y )

quad( x1, y1, x2, y2, x3, y3, x4, y4)

rect( x, y, width, height )

triangle( x1, y1, x2, y2, x3, y3 )


Curves

curveTightness( squishy )


Shape Attributes

ellipseMode( mode )

rectMode( mode )

noSmooth()

smooth()

strokeCap( style )

strokeJoin( style )

strokeWeight( weight )


Vertex

beginShape()

vertex( x, y )

curveVertex( x, y )

bezierVertex( cx1, cy1, cx2, cy2, x, y )

endShape( [True or False] )


Image


PImage

createImage( width, height, format )


Image Loading & Displaying

image( img, x, y )

image( img, x, y, width, height )

imageMode( [CORNER, CENTER, CORNERS] )

loadImage( filepath )

get()

get( x, y, width, height )


Pixels

loadPixels()

getPixel( i, j )

setPixel( i, j, color )

updatePixels()


Transform

pushMatrix()

popMatrix()

resetMatrix()

rotate( angle )

scale( s )

scale( sx, sy )

translate( tx, ty )


Color


Setting

background( red, green, blue, alpha )

background( red, green, blue )

background( gray, alpha )

background( gray )

background( color )

fill( red, green, blue, alpha )

fill( red, green, blue )

fill( gray, alpha )

fill( gray )

fill( color )

noFill()

stroke( red, green, blue, alpha )

stroke( red, green, blue )

stroke( gray, alpha )

stroke( gray )

stroke( color )

noStroke()


Color Creating & Reading

red( clr )

green( clr )

blue( clr )

alpha( clr )

hue( clr )

saturation( clr )

brightness( clr )

color( red, green, blue, alpha )

color( red, green, blue )

color( gray, alpha )

color( gray )


Typography


Text Loading & Displaying

text( txt, x, y )

text( txt, x, y, w, h )

markup( txt, x, y )

markup( txt, x, y, w, h )


Text Attributes

textSize( size )

textFont( fontName )

listFonts( )

textWidth( text )

textHeight( text )

textAlign( xalign )

textAlign( xalign, yalign)


Math


Calculation

ceil( x )

floor( x )

constrain( x, min, max )

dist( x1, y1, x2, y2 )

mag( x, y )

map( x, min1, max1, min2, max2 )

max( x1, x2, x3, ... )

min( x1, x2, x3, ... )

round( x )

radians( degrees )

degrees( radians)


Random

random( max )

random( min, max )

randomSeed( seed )

noise(x)

noise(x, y)

noise(x, y, z)

noiseSeed( seed )

Constants


HALF_PI (1.57079...)

PI (3.14159...)

QUARTER_PI (0.78539...)

TWO_PI (6.28318...)


2D Primitives



Draw an arc defined as a fragment of an ellipse.


arc(x, y, width, height, start-angle, end-angle)


This example draws an arc that is a part of the ellipse centered at (100, 100), with width 150 and height 75, starting at an angle of 0 radians and ending at angle that is the number of radians equivalent to 45°.

ellipseMode(CENTER)
arc( 100, 100, 150, 75, 0, radians(45) )


Back to Index



Draw an ellipse using the current settings.


ellipse(x, y, width, height)


This example draws an ellipse with upper left corner at (100, 100), and a width of 150 and height of 75.

ellipseMode(CORNER)
ellipse( 100, 100, 150, 75 )


Back to Index



Draw a line from (x1, y1) to (x2, y2).


line(x1, y1, x2, y2)


This example draws from the upper left corner of the sketch window to the lower right corner, assuming no transformations ahve been applied.

line( 0, 0, width(), height() )


Back to Index



Draw a point at coordinate (x, y).


point(x, y)


This example draws a large point at the center of the sketch window.

strokeWeight(10)
point( 0.5*width(), 0.5*height() )


Back to Index



Draw a four-sided polygon with vertexes (x1, y1), (x2, y2), (x3, y3), (x4, y4).


quad(x1, y1, x2, y2, x3, y3, x4, y4)


This example draws a yellow diamond shape with a thick border.

strokeWeight(5)
fill(255, 255, 0)
quad(100, 100, 75, 150, 100, 200, 125, 150)


Back to Index



Draw an ellipse using the current settings.


rect(x, y, width, height)


This example draws a blue rectangle with upper left corner at (100, 100) and a width of 200 and height of 150.

rectMode(CORNER)
fill(0, 0, 255)
rect(100, 100, 200, 150)


Back to Index



Draw a three-sided polygon with vertexes (x1, y1), (x2, y2), (x3, y3).


triangle(x1, y1, x2, y2, x3, y3)


This example draws a red right-triangle with the given vertexes.

fill(255, 0, 0)
triangle(100, 100, 100, 200, 200, 200)


Back to Index

Curves



Determines level of smoothness at spline points for shapes created with curveVertex(). A value of 0.0 is not smooth. Values > 0.0 increase smoothness.


curveTightness(squishy)


Sets smoothness for all future curves to 0.5.

curveVertex( 0.5 )


Back to Index

Shape Attributes



Sets the meaning of the arguments passed to ellipse() and arc() commands. CENTER is default.

CORNER : The arguments x and y define the upper left corner, and w and h define the ellipse width and height.

CORNERS : The arguments x and y define the upper left corner, and w and h define the lower right corner of ellipse.

CENTER : The arguments x and y define the center of the ellipse, and w and h the width and height.

RADIUS : The arguments x and y define the center of the ellipse, and w and h the radius

  • Note that the mode argument can be the built-in constant or a string.


ellipseMode(mode)


Sets ellipseMode to CORNER using built-in constant.

ellipseMode( CORNER )


Back to Index



Sets the meaning of the arguments passed to rect() command. CORNER is default.

CORNER : The arguments x and y define the upper left corner, and w and h define the rect width and height.

CORNERS : The arguments x and y define the upper left corner, and w and h define the lower right corner of rect.

CENTER : The arguments x and y define the center of the rect and w and h the width and height.

RADIUS : The arguments x and y define the center of the rect and w and h the radius.

  • Note that the mode argument can be the built-in constant or a string.


rectMode(mode)


Sets rectMode to CENTER using a string argument.

rectMode( "CENTER" )


Back to Index



Turn on subpixel antialiasing.


smooth()


Turns on automatic smoothing.

smooth()


Back to Index



Turn off subpixel antialiasing.


noSmooth()


Turns off automatic smoothing.

noSmooth()


Back to Index



Set the style for line ends. Default is ROUND.

SQUARE :

ROUND :

PROJECT :

  • Note that the style argument can be the built-in constant or a string.


strokeCap(style)


Sets line ends to be drawn square.

strokeCap( SQUARE )


Back to Index



Set the style for the way line segments are joined. Default is MITER.

BEVEL :

ROUND :

MITER :

  • Note that the style argument can be the built-in constant or a string.


strokeJoin(style)


Sets line joints to be rounded.

strokeJoin( "ROUND" )


Back to Index



Sets the weight of stroked lines. Can be any integer >=1. Default is 1.


strokeWeight(weight)


Sets line width to 3 pixels.

strokeWeight( 3 )


Back to Index


Vertex



Starts accumulating points to be included in a new shape.


beginShape()


Begin a new shape.

beginShape()


Back to Index



Adds a point to a shape, connected from the previous point by a straight line.


vertex(x, y)


Add a vertex to a shape at coordinates 100, 100.

vertex( 100, 100 )


Back to Index



Adds a point to a shape, connected from the previous point by a smooth line, the degree of smoothness determined by the parameter passed to the curveTightness() function.


curveVertex(x, y)


Create a smooth closed shape that is made up of several points from a list.

pts = [(100, 250), (50, 80), (200, 100), (300, 80), (250, 240)]
beginShape()
for p in pts: 
    curveVertex(p[0], p[1])
endShape(True)


Back to Index



Adds a point to a shape, connected from the previous point by a smooth line, with line end slopes determined by the lines that the curve segment endpoints makes with control points (cx1, cy1) and (cx2, cy2).


bezierVertex(cx1, cy1,cx2, cy2, x, y)


Create an interesting sigmoidal curve starting at a high plateau and ending at a low plateau.

noFill()
beginShape()
vertex(100, 100)
bezierVertex( 200, 100, 200, 100, 200, 200 )
bezierVertex( 200, 300, 200, 300, 300, 300 )
endShape()


Back to Index



Stops accumulating shape points and renders a shape. If TorF is True, the shape is closed.


endShape([TorF])


End a shape and close it by connecting the first and last points.

endShape( True )


Back to Index

Structure



Delay the program for the specified number of milliseconds.


delay(millis)


In addition to a brief pause in execution, the delay() function will allow the sketch to update. It is useful when choosing to execute a main loop that runs an animation or some other periodic check of state. This Python example draws randomly placed ellipses until the mouse is pressed.

from Processing import *

window(500, 500)

while True:
    ellipse( random(width()), random(height()), 30, 30 )
    if isMousePressed() == True: break
    delay(100)

exit()

This second example continuously draws randomly located lines, but also simultaneously processes mousePressed events.

from Processing import *
window(600, 400)

# A function that prints the current mouse coordinates
def printMouse():
    print( mouseX(), mouseY() )

# Print mouse coordinates when the mouse is pressed
onMousePressed += printMouse

# Continuously draw random lines
while True:
    x1, y1 = random(0, 600), random(0, 400)
    x2, y2 = random(0, 600), random(0, 400)
    line(x1, y1, x2, y2)
    delay(200)


Back to Index



Start the internal looping engine that periodically fires the onLoop event handler.


loop()


This Python example fires the printSecond() function every 1000 milliseconds (1 second).

from Processing import *

window(500, 500)

def printSecond():
    print( second() )

frameRate(1000)
onLoop += printSecond
loop()


Back to Index



Stop the internal looping engine, so that the onLoop event handler will not be called.


noLoop()


noLoop()


Back to Index



A synonym for loop()


startLoop()


startLoop()


Back to Index



A synonym for noLoop()


stopLoop()


stopLoop()


Back to Index



Redraw the sketch on demand. Useful when immediateMode(False) is used.


redraw()


redraw()


Back to Index



This is the event raised when loop() or startLoop() is called. Handle the onLoop event by adding an event handler function to onLoop using the += operator.


onLoop()


See loop() for an example. Note that all event handler functions must take two arguments - the first argument is the internal PTimer object that raised the event, and the second is the PElapsedEventArgs object containing arguments associated with the event.

onLoop += myLoopHandler


Back to Index



Sets the frames per second to display when using the onLoop event.


frameRate(fps)


Calls the onLoop event hander 10 times per second.

frameRate( 10 )


Back to Index



Process any pending events.


doEvents()


Continues to handle events while in a while-loop.

while True:
    doEvents()


Back to Index

Environment



Creates a new sketch window.


window( width, height )


Draws a magic 8-Ball.

from Processing import *

# Open an window and fill background with black
window( 600, 400 )
background( 0 )

# Draw a white circle in the center
fill(255)
ellipse( 300, 200, 200, 200 )

# Draw a large "8"
fill(0)
textSize(100)
text("8", 265, 245 )


Back to Index



Returns True if window currently has focus. False otherwise.


focused()


Prints 'click me' if the window does not have focus.

if focused() == False: 
    print( 'click me' )


Back to Index



Returns the number of frames that have been displayed thus far.


frameCount()


Prints frame count.

print( str( frameCount() ) + ' frames have been displayed' )


Back to Index



Puts the sketch window in fullscreen mode using the entire display.


fullscreen()


Use an entire laptop screen for this sketch.

window(1024,768)
fullscreen()

Back to Index



Leave fullscreen mode.


unfullscreen()


Back to Index



Returns the window height.


height()


Set the window height to the variable h.

h = height()


Back to Index



Returns the window width.


width()


Set the window width to the variable w.

w = width()


Back to Index



Returns the width of the screen.


displayWidth()


Store the width of the screen using a variable w.

w = displayWidth()

Back to Index



Returns the height of the screen.


displayHeight()


Store the height of the screen using a variable h.

h = displayHeight()


Back to Index



Resize the sketch window.


size(width, height)


Dynamically resize the sketch window to a width of 600 and a height of 400.

size( 600, 400 )


Back to Index



If TorF is True, the sketch is updated after every draw. If False, call redraw() to update the sketch.


immediateMode(TorF)


Turns off immediate mode.

immediateMode( False )


Back to Index



If TorF is True, the window remains above others, even if it loses focus.


keepAbove(TorF)


Sets window to remain above others.

keepAbove( True )


Back to Index


Mouse



Returns the current mouse x-coordinate.


mouseX()


Sets x to current mouse x-coordinate.

x = mouseX()


Back to Index



Returns the current mouse y-coordinate.


mouseY()


Sets y to current mouse y-coordinate.

y = mouseY()


Back to Index



Returns the previous mouse x-coordinate.


pmouseX()


Draws a line from previous to current mouse position.

line( pmouseX(), pmouseY(), mouseX(), mouseY() )


Back to Index



Returns the previous mouse y-coordinate.


pmouseY()


Draws a line from previous to current mouse position.

line( pmouseX(), pmouseY(), mouseX(), mouseY() )


Back to Index



Returns a number representing the mouse button currently pressed. 1 for left mouse button, 2 for center mouse button, 3 for right mouse button, and 0 for no mouse buttons pressed.


mouseButton()


Prints string when left mouse is pressed.

if mouseButton() == 1:
    print( 'Left mouse pressed' )


Back to Index



Returns True if mouse is pressed. False otherwise.


isMousePressed()


Prints string when any mouse button is pressed.

if isMousePressed() == True:
    print( 'mouse is pressed' )


Back to Index



Event raised when mouse is moved but not pressed.


onMouseMoved


Prints 'mouse moved' whenever the mouse is moved with no buttons pressed.

def doMouseMoved():
    print( 'mouse moved')

onMouseMoved += doMouseMoved


Back to Index



Event raised when mouse is pressed and moved.


onMouseDragged


Implements a simple scribble program by drawing a line from the previous mouse position to the current mouse position each time the mouse is dragged.

def doMouseDragged():
   line(pmouseX(), pmouseY(), mouseX(), mouseY())

onMouseDragged += doMouseDragged


Back to Index



Event raised when mouse is pressed.


onMousePressed


Prints the mouse location when pressed.

def doMousePressed():
    print( 'mouse pressed at ' + str(mouseX()) + ', ' + str(mouseY()) )

onMousePressed += doMousePressed


Back to Index



Event raised when mouse is released.


onMouseReleased


Prints the mouse location when released.

def doMouseReleased():
    print( 'mouse released at ' + str(mouseX()) + ', ' + str(mouseY()) )

onMouseReleased += doMouseReleased


Back to Index



Event raised when mouse is pressed and immediately released at the exact same sketch location.


onMouseClicked


Prints the mouse location when the mouse is clicked.

def doMouseClicked():
    print( 'mouse clicked at ' + str(mouseX()) + ', ' + str(mouseY()) )

onMouseClicked += doMouseClicked


Back to Index

Keyboard



Returns the Gdk.Key value of the key currently pressed or 0 if none pressed.


key()


Prints the current key pressed.

print( key() )


Back to Index



Returns the numeric code of the key currently pressed or 0 if none pressed.


keyCode()


Prints the code of the current key pressed.

print( keyCode() )


Back to Index



Returns True if a key is pressed. False otherwise.


isKeyPressed()


Checks if a key is pressed every hald second, and prints the key and its code if pressed.

while True:
    if isKeyPressed() == True:
        print( 'key pressed is ' + str(key()) + ' and has code ' + str( keyCode() ) )
    delay(500)


Back to Index



Event raised when a key is pressed.


onKeyPressed


Prints the key and keyCode when a key is pressed.

def doKeyPressed():
    print( key(), keyCode() )

onKeyPressed += doKeyPressed


Back to Index



Event raised when a key is released.


onKeyReleased


Prints 'key up' when the key is released.

def doKeyReleased():
    print( 'key up' )

onKeyReleased += doKeyReleased


Back to Index

Conversion



Attempts to convert a value to a binary representation in the form of a string of 1s and 0s


toBinary(val)


Prints the binary representation of 255, which is 11111111

print( toBinary(255) )


Back to Index




Attempts to convert val to True or False


toBoolean(val)


Converts the string "True" to the boolean True and prints it.

print( toBoolean( "True" ) )


Back to Index



Attempts to convert val to a byte in the range [0, 255]


toByte(val)


Converts the integer 128 to a byte and prints it.

print( toByte( 128 ) )


Back to Index



Attempts to convert val to a character


toChar(val)


Converts the code 65 to 'A' and prints it

print( toChar( 65 ) 


Back to Index



Attempts to convert val to a floating point number


toFloat(val)


Converst the integer -12345 to a floating point number and prints it.

print( toFloat( -12345 ) )


Back to Index



Attempts to convert val to a double precision number


toDouble(val)


Converts the integer -1234567890 to a double precision number and prints it.

print( toDouble( -1234567890 ) )


Back to Index



Attempts to convert val to a 32 bit integer


toInt(val)


Converts the number -12345.678 to the integer -12345 and prints it.

print( toInt( -12345.678 ) )


Back to Index



Attempts to convert val to a 64 bit integer


toLong(val)


Converts the number -1234567890.098 to the long -1234567890 and prints it.

print( toLong( -1234567890.098 ) )


Back to Index



Attempts to convert val to a string


toString(val)


Converts the boolean False to the string "False" and prints it.

print( toString( False ) )


Back to Index



Attempts to convert val to a hexadecimal representation in the form of a string


toHex(val)


Converts the number 255 to its hex representation "FF" and prints it.

print( toHex( 255 ) )


Back to Index



Attempts to convert a hex string to an integer


fromHex(str)


Converts the hex string "FF" to its numeric representation of 255 and prints it.

print( fromHex( "FF" ) )


Back to Index



Attempts to convert a string of 1s and 0s to an integer


fromBinary(str)


Converts the bit string "1111" to the integer 15 and prints it.

print( fromBinary( "1111" ) )


Back to Index


Time & Date

Return the number of milliseconds the sketch window has existed.


millis()


Set the variable m to the number of milliseconds since the sketch window was created, if one exists.

m = millis()


Back to Index



Returns the number of seconds that have passed on the system clock in the current minute. This function will only return numbers from 0 to 59.


second()


Sets the variable s to the current number of seconds on the system clock.

s = second()


Back to Index



Returns the number of minutes that have passed on the system clock in the current hour. This function will only return numbers from 0 to 59.


minute()


Sets the variable m to the current number of minutes on the system clock.

m = minute()


Back to Index



Returns the number of hours that have passed on the system clock in the current day. This function will only return numbers from 0 to 23.


hour()


Sets the variable h to the current number of hours on the system clock.

h = hour()


Back to Index



Returns the number of the current day in the current month. This function will only return numbers from 1 to 31.


day()


Sets the variable d to a number that represents the current day of the month.

d = day()


Back to Index



Returns the number of the current month in the current year. This function will only return numbers from 1 to 12.


month()


Sets the variable d to a number that represents the current day of the month.

m = month()


Back to Index



Returns the current year.


year()


Sets the variable y to the current year.

y = year()


Back to Index

Transform



Saves the current transformation.


pushMatrix()


pushMatrix()


Back to Index



Restores the last saved tranformation.


popMatrix()


popMatrix()


Back to Index



Clears all transformations previously applied.


resetMatrix()


resetmatrix()


Back to Index



Rotates the current coordinates system by angle radians about the point 0, 0.


rotate(angle)


Rotate the coordinate system by 45 degrees, draw a rotated ellipse, and then restore the coordinate system to the settings before the rotation.

pushMatrix()
rotate( radians(45) )
ellipse(100, 100, 75, 50)
popMatrix()


Back to Index



Scales the current coordinate system by a factor of s about the point 0, 0.


scale(s)


Scale the coordiante system by a factor of 2 in both directions.

scale( 2 )


Back to Index



Scales the current coordinate system by a factor of sx in the x-direction and sy in the y-direction, all about the point 0, 0.


scale(sx, sy)


Draw a circle that looks like an ellipse due to a non-uniform scaling in the x- and y-directions.

scale( 2, 1 )
ellipse( 100, 100, 50, 50 )


Back to Index



Translates the current coordinate system by tx in the x-direction and ty in the y-direction.


translate(tx, ty)


Draw a rectangle at 100, 100 by translating the coordinate system.

translate( 100, 100 )
rect( 0, 0, 50, 75 )


Back to Index


Color Setting



Fill the sketch background with a color defined by red, green, blue and alpha. All values are in the range [0, 255].


background(red, green, blue, alpha)


Fills the background with a semitransparent red.

background( 255, 0, 0, 128)


Back to Index



Fill the sketch background with a color defined by red, green and blue. All values are in the range [0, 255].


background(red, green, blue)


Fills the background with a pure yellow.

background( 255, 255, 0)


Back to Index



Fill the sketch background with a color based on gray and alpha, where gray used for red, green and blue values. All values are in the range [0, 255].


background(gray, alpha)


Fills the background with a semitransparent black.

background( 0, 128 )


Back to Index



Fill the sketch background with a color in which gray is used for red, green and blue values. All values are in the range [0, 255].


background(gray)


Fills the background with gray.

background( 128 )


Back to Index



Fill the sketch background with a color value created with the color() command.


background(color)


Fills the background with blue created with the color() command.

blue = color( 0, 0, 255 )
background( blue )


Back to Index




Fill future shapes with a color defined by red, green, blue and alpha. All values are in the range [0, 255].


fill(red, green, blue, alpha)


Fills new shapes with a semitransparent red.

fill( 255, 0, 0, 128)


Back to Index



Fill future shapes with a color defined by red, green and blue. All values are in the range [0, 255].


fill(red, green, blue)


Fills new shapes with a pure yellow.

fill( 255, 255, 0)


Back to Index



Fill future shapes with a color based on gray and alpha, where gray used for red, green and blue values. All values are in the range [0, 255].


fill(gray, alpha)


Fills new shapes with a semitransparent black.

fill( 0, 128 )


Back to Index



Fill future shapes with a color in which gray is used for red, green and blue values. All values are in the range [0, 255].


fill(gray)


Fills new shapes with gray.

fill( 128 )


Back to Index



Fill future shapes with a color value created with the color() command.


fill(color)


Draw a blue rectangle.

blue = color( 0, 0, 255 )
fill( blue )
rect(0, 0, 50, 50)


Back to Index



Turn off shape filling.


noFill()


Draw a rectangle with black outline and no fill color.

noFill()
stroke(0)
rect(0, 0, 50, 50)


Back to Index




Stroke future shapes with a color defined by red, green, blue and alpha. All values are in the range [0, 255].


stroke(red, green, blue, alpha)


Strokes new shapes with a semitransparent red.

stroke( 255, 0, 0, 128)


Back to Index



Stroke future shapes with a color defined by red, green and blue. All values are in the range [0, 255].


stroke(red, green, blue)


Strokes new shapes with a pure yellow.

stroke( 255, 255, 0)


Back to Index



Stroke future shapes with a color based on gray and alpha, where gray used for red, green and blue values. All values are in the range [0, 255].


stroke(gray, alpha)


Strokes new shapes with a semitransparent black.

stroke( 0, 128 )


Back to Index



Stroke future shapes with a color in which gray is used for red, green and blue values. All values are in the range [0, 255].


stroke(gray)


Strokes new shapes with gray.

stroke( 128 )


Back to Index



Stroke future shapes with a color value created with the color() command.


stroke(color)


Draw a rectangle with blue outline.

blue = color( 0, 0, 255 )
stroke( blue )
rect(0, 0, 50, 50)


Back to Index



Turn off shape stroke.


noStroke()


Draw a blue filled rectangle no outline.

noStroke()
fill(0)
rect(0, 0, 50, 50)


Back to Index

Color Creating & Reading

Extract the red component from the color clr.


red(clr)


Print the red component of the color clr.

print( red( clr ) )


Back to Index



Extract the green component from the color clr.


green(clr)


Print the green component of the color clr.

print( green( clr ) )


Back to Index



Extract the blue component from the color clr.


blue(clr)


Swap the red and blue components of the color clr.

r = red( clr )
b = blue( clr )
g = green( clr )
clr = color( b, r, g )


Back to Index



Extract the transparency component from the color clr.


alpha(clr)


Print the transparencey of the color clr.

print( alpha( clr ) )


Back to Index



Extract the hue from the color clr.


hue(clr)


Print the hue of the color clr.

print( hue( clr ) )


Back to Index



Extract the saturation from the color clr.


saturation(clr)


Print the saturation of the color clr.

print( saturation( clr ) )


Back to Index



Extract the brightness from the color clr.


brightness(clr)


Print the brightness of the color clr.

print( brightness( clr ) )


Back to Index



Build and return a new color from the red, blue, green and alpha byte values.


color(red, green, blue, alpha)


Create a semitransparent red color.

semi = color (255, 0, 0, 128)


Back to Index



Build and return a new color from the red, blue and green byte values.


color(red, green, blue)


Create a yellow color.

yellow = color( 255, 255, 0)


Back to Index



Build and return a new color using the gray byte as the values for red, green and blue, and alpha for transparency.


color(gray, alpha)


Create a semitransparent gray.

semi = color( 255, 128 )


Back to Index



Build and return a new color using the gray byte as the values for red, green and blue.


color(gray)


Create a mid-scale gray color.

gray = color( 128  )


Back to Index

Image



An object that represents an image.


PImage()


Load an image from a file and draw it on the window at coordinates 10, 10.

img = loadImage("butterfly.png")
image( img, 10, 10 )


There is support for moving an Image from Calico Processing to Calico Graphics, and back:

from Myro import makePicture
from Processing import createImage

p = makePicture(100, 100)
i = createImage(p.toBitmap())   # turn Graphics.Picture into a Bitmap and load in Processing
i.loadPixels()                  # load the Pixels
p2 = makePicture(i.toBitmap())  # turn Processing.Image into a Bitmap and load in Graphics


Back to Index



Creates and returns a new Pimage of size width by height in the format. Valid formats include RGB, ARGB and ALPHA. Format arguments can be provided as built-in constants or strings.


createImage(width, height, format)


Create a new Pimage, fill all pixels with the color red, and draw at coordinates 20, 20

img = createImage(100, 100, ARGB)
img.loadPixels()
for r in range( 100 ):
    for c in range( 100 ):
        img.setPixel(c, r, color(255, 0, 0) )
img.updatePixels()
image( img, 20, 20 )


Back to Index


Image Loading & Displaying



Draw the Pimage img at coordinates x, y


image(img, x, y)


Load an image from a file and draw it on the window at coordinates 10, 10.

img = loadImage("butterfly.png")
image( img, 10, 10 )


Back to Index



Draw the Pimage img at coordinates x, y, with the specified width and height


image(img, x, y, width, height)


Load an image from a file and draw it on the window at coordinates 10, 10 with a width of 100 pixels and a height of 75 pixels.

img = loadImage("butterfly.png")
image( img, 10, 10, 100, 75 )


Back to Index



Sets the mode for drawing images. Can be CORNER, CENTER or CORNERS, or strings of the same name.


imageMode(mode)


Draw an image named img centered at coordinates 250, 250

imageMode(CENTER)
image( img, 250, 250 )


Back to Index



Loads the file at filepath and returns a new PImage.


loadImage(filepath)


Load an image from a file and draw it on the window at coordinates 10, 10.

img = loadImage("butterfly.png")
image( img, 10, 10 )


Back to Index



Copies the current sketch window and returns as a new PImage.


get()


Get the current sketch as a new PImage and save in a variable named mySketch.

mySketch = get()


Back to Index



Copies a portion of the sketch window sketch and returns as a new PImage. The portion of the window copied has upper left corner of (x, y) and dimensions width by height.


get(x, y, width, height)


Get part of the current sketch with an upper left corner of (100, 100) and a width of 50, and height of 75. Assign the new PImage returned to the variable imagePart.

imagePart = get(100, 100, 50, 75)


Back to Index


Pixels



Copies all color data out of the image or sketch window into an internal memory buffer, making it available to the getPixel() and setPixel() functions.


loadPixels()


Load all pixels from the sketch window making them available for modification.

loadPixels()


Back to Index



Gets and returns the pixel color at column i, row j.


getPixel(i, j)


Get the pixel color at column 100, row 75 and set to the variable clr.

clr = getPixel( 100, 75 )


Back to Index



Set the pixel color at column i, row j.


setPixel(i, j, color)


Set the pixel color at column 100, row 75 to blue.

setPixel( 100, 75, color(0, 0, 255) )


Back to Index



Copies all color data out of the internal memory buffer back to the image or sketch window, making it available to be drawn with image() .


updatePixels()


Copies pixels from the memory buffer back to the sketch window.

updatePixels()


Back to Index

Text Loading & Displaying


Draw the text txt such that the lower left corner of the box surrounding the text is at the coordinate x, y.


text(txt, x, y)


Draw the text "Blah" above and to the right of the coodinate 100, 100.

text( "Blah", 100, 100)


Back to Index



Draw the text txt within the box with upper left corner at x,y and width w, height h.


text(txt, x, y, w, h)


Draw "Blah" in the rectangle with the corner at 100, 100 and width 200, height 50.

text( "Blah", 100, 100, 200, 50 )


Back to Index

Draw <a href = "#http://www.pygtk.org/docs/pygtk/pango-markup-language.html >markup text</a> txt such that the lower left corner of the box surrounding the text is at the coordinate x, y.

markup(txt, x, y)


Draw the text "Blah" boldly above and to the right of the coodinate 100, 100.

markup( "<b>Blah</b>", 100, 100)


Back to Index



Draw <a href = "#http://www.pygtk.org/docs/pygtk/pango-markup-language.html >markup text</a> txt within the box with upper left corner at x,y and width w, height h.


markup(txt, x, y, w, h)


Draw bold "Blah" in the rectangle with the corner at 100, 100 and width 200, height 50.

text( "<b>Blah</b>", 100, 100, 200, 50 )


Back to Index

Text Attributes



Set the size of text to be drawn with a factor that roughly equals the text point size.


textSize(size)


Set text size to 12 pts.

textSize( 12 )


Back to Index


Set the font.


textFont(fontName)


Set font family to Courier.

textFont( "Courier" )


Back to Index


List the available fonts.


listFonts()


Use the first font.

fonts = listFonts()
textFont(fonts[0])


Back to Index



Returns the width of the string text in pixels.


textWidth(text)


Estimate the width of the text "Blah" and save to twidth.

twidth = textWidth( "Blah" )


Back to Index


Returns the height of the string text in pixels.


textHeight(text)


Estimate the height of the text "Blah" and save to theight.

theight = textHeight( "Blah" )


Back to Index



Determines how text will be aligned horizontally within its rectangle. The parameter xalign can be one of the constants LEFT, CENTER or RIGHT, or the string equivalents.


textAlign(xalign)


Draw "Blah" aligned to the right side of the specified rectangle.

textAlign( RIGHT )
text( "Blah", 100, 100, 200, 50 )


Back to Index



The parameter xalign determines how text will be aligned horizontally within its rectangle. It can be one of the constants LEFT, CENTER or RIGHT, or the string equivalents. The parameter yalign determines how text will be aligned vertically within its rectangle. It can be one of the constants TOP, CENTER, BOTTOM or BASELINE, or the string equivalents.


textAlign(xalign, yalign)


Draw "Blah" in the lower right corner of the specified rectangle.

textAlign( RIGHT, BASELINE )
text( "Blah", 100, 100, 200, 50 )


Back to Index

Calculation



Calculates and returns the closest integer greater than x.


ceil(x)


Returns 3

ceil(2.3)


Back to Index



Calculates and returns the closest integer smaller than x.


floor(x)


Returns 2

floor(2.3)


Back to Index



Returns the value of x constrained to the range [min, max]


constrain(x, min, max)


Returns 2.0

constrain(2.3, 0.0, 2.0)


Back to Index



Computes the distance between the points (x1, y1) and (x2, y2)


dist(x1, y1, x2, y2)


Returns 5.0

dist(0.0, 0.0, 3.0, 4.0)


Back to Index



Computes the length of the line from (0, 0) to (x, y)


mag(x, y)


Returns 5.0

mag( 3.0, 4.0 )


Back to Index



Maps x from the range [min1, max1] to the range [min2, max2]


map(x, min1, max1, min2, max2)


Returns 0.5

map( 250.0, 0.0, 500.0, 0.0, 1.0 )


Back to Index



Returns the largest of several numbers.


max(x1, x2, x3 …)


Returns 3

max(3, 1, -1)


Back to Index



Returns the smallest of several numbers.


min(x1, x2, x3 …)


Returns -1

min(3, 1, -1)


Back to Index



Calculates and return the integer closest to x.


round(x)


Returns 2.0

round( 2.3 )


Back to Index



Translate degrees to radians and return the result.


radians(degrees)


Returns 3.141592653589793 (π)

radians( 180 )


Back to Index



Translate radians to degrees and return the result.


degrees(radians)


Returns 180.0. Uses the built-in constant PI.

degrees(PI)


Back to Index

Random



Returns a pseudo-random number in the range [0.0, max]


random(max)


Compute a pseudo-random number between 0.0 and 100.0.

random( 100.0 )


Back to Index



Returns a pseudo-random number in the range [min, max]


random(min, max)


Compute a pseudo-random number between 50.0 and 100.0.

random( 50.0, 100.0 )


Back to Index



Reseed the pseudo-random number generator with seed.


randomSeed(seed)


Reseed the pseudo-random number generator with 10.0.

randomSeed( 10.0 )


Back to Index



Get a Perlin random number in 1 dimension.


noise(x)


Get a Perlin random number in 1 dimension using x as parameter.

noise(0)


Back to Index



Get a Perlin random number in 2 dimensions.


noise(x, y)


Get a Perlin random number in 2 dimensions using x and y as parameters.

noise(0, 0)


Back to Index



Get a Perlin random number in 3 dimensions.


noise(x, y, z)


Get a Perlin random number in 3 dimensions using x, y, and z as parameters.

noise(0, 0, 0)


Back to Index



Reseed the Perlin random number generator with seed.


noiseSeed(seed)


Reseed the Perlin random number generator with 0 (which means randomize the seed).

noiseSeed( 0 )


Back to Index


Constants



The constant π/2


HALF_PI


Rotate by 90°

rotate( HALF_PI )


Back to Index



The constant π


PI


Rotate by 180°

rotate( PI )


Back to Index



The constant π/4


QUARTER_PI


Rotate by 45°

rotate( QUARTER_PI )


Back to Index