Getting Started with Processing by Casey Reas & Ben Fry
Author:Casey Reas & Ben Fry
Language: eng
Format: epub
Publisher: O'Reilly Media, Inc.
Published: 2015-09-22T04:00:00+00:00
Function Basics
A computer runs a program one line at a time. When a function is run, the computer jumps to where the function is defined and runs the code there, then jumps back to where it left off.
Example 9-1: Roll the Dice
This behavior is illustrated with the rollDice() function written for this example. When a program starts, it runs the code in setup() and then stops. The program takes a detour and runs the code inside rollDice() each time it appears:
void setup() { println("Ready to roll!"); rollDice(20); rollDice(20); rollDice(6); println("Finished."); } void rollDice(int numSides) { int d = 1 + int(random(numSides)); println("Rolling... " + d); }
The two lines of code in rollDice() select a random number between 1 and the number of sides on the dice, and prints that number to the Console. Because the numbers are random, you’ll see different numbers each time the program is run:
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9929)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9805)
The Mikado Method by Ola Ellnestam Daniel Brolund(9793)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8315)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7796)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7774)
Grails in Action by Glen Smith Peter Ledbrook(7706)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7571)
Windows APT Warfare by Sheng-Hao Ma(6993)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6719)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6593)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6429)
Kotlin in Action by Dmitry Jemerov(5077)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4325)
Solidity Programming Essentials by Ritesh Modi(4085)
Functional Programming in JavaScript by Mantyla Dan(4048)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3876)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3826)
The Ultimate iOS Interview Playbook by Avi Tsadok(3797)
