Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • p5.js-Environment
  • p5.js-Color
  • p5.js-Shape
  • p5.js-Constants and Structure
  • p5.js-DOM and Rendering
  • p5.js-Transform
  • p5.js-Data
  • p5.js-Events
  • p5.js-Image
  • p5.js-IO
  • p5.js-Math
  • p5.js-Typography
  • p5.js-Lights & Camera
  • JavaScript
  • Web Technology
Open In App
Next Article:
p5.js quad() Function
Next article icon

p5.js quad() Function

Last Updated : 11 Aug, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report
The quad() function is an inbuilt function in p5.js which is used to draw a quadrilateral. A quadrilateral is a four-sided polygon. It function creates a shape similar to rectangle, but the angles between two edges are not constrained to 90 degrees. Syntax:
quad(x1, y1, x2, y2, x3, y3, x4, y4)
or
quad(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
Parameters: This function accepts twelve parameters as mentioned above and described below:
  • x1: This parameter takes the x-coordinate of the first point.
  • y1: This parameter takes the y-coordinate of the first point.
  • z1: This parameter takes the z-coordinate of the first point.
  • x2: This parameter takes the x-coordinate of the second point.
  • y2: This parameter takes the y-coordinate of the second point.
  • z2: This parameter takes the z-coordinate of the second point.
  • x3: This parameter takes the x-coordinate of the third point.
  • y3: This parameter takes the y-coordinate of the third point.
  • z3: This parameter takes the z-coordinate of the third point.
  • x4: This parameter takes the z-coordinate of the fourth point.
  • y4: This parameter takes the z-coordinate of the fourth point.
  • z4: This parameter takes the z-coordinate of the fourth point.
Below programs illustrates the quad() function in P5.js: Example 1: This example uses quad() function to create a polygon without using z-coordinate. JavaScript
function setup() {          // Create canvas of given size     createCanvas(400, 400); }   function draw() {          // Set the background color     background(220);          noStroke();          // Set the fill color     fill('green');          // x1, y1 = 38, 31; x2, y2 = 300, 20;     // x3, y3 = 100, 63; x4, y4 = 130, 250     quad(38, 31, 300, 20, 100, 63, 130, 250);  } 
Output: Example 2: This example uses quad() function to create polygon with z-coordinate. JavaScript
function setup() {          // Create canvas of given size     createCanvas(400, 400); }   function draw() {      // Set the background color     background(99);          noStroke();          // Set the filled color     fill('pink');          // x1, y1, z1 = 38, 131, 100;     // x2, y2, z2 = 320, 100, 63;      // x3, y3, z3 = 130, 150, 134;      // x4, y4, z4 = 155, 66, 88;     quad(38, 131, 100, 320, 100, 63,         130, 150, 134, 155, 66, 88);  } 
Output: Reference: https://p5js.org/reference/#/p5/quad

Next Article
p5.js quad() Function

S

sarthak_ishu11
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-p5.js

Similar Reads

    p5.js square() Function
    The square() function is an inbuilt function in p5.js which is used to draw the square on the screen. A square contains four equal sides and four angles each of 90 degrees. It is the special case of a rectangle where width and height are equal. Syntax: square( x, y, s, tl, tr, br, bl ) Parameters: T
    2 min read
    p5.js sq() function
    The sq() function in p5.js is used to calculate the square value of a number. The square of a number is always positive. Syntax sq(number) Parameters: The function accepts only one parameter as mentioned above and described below: number: This parameter stores the number to compute. Below program il
    1 min read
    p5.js round() function
    The round() function in p5.js is used to calculate the round value of a number. It calculates the integer closest to the number. Syntax round(number) Parameters: The function accepts only one parameter as mentioned above and described below: number : This parameter stores the number to compute. Belo
    1 min read
    p5.js tan() function
    The tan() function in p5.js is used to calculate the tangent value of an angle in radians taken as the input parameter of the function. Syntax: tan(angle) Parameters: This function accepts a single parameter angle which is an angle in radian whose tangent value is to be calculated. Return Value: It
    2 min read
    p5.js unchar() function
    The unchar() function in p5.js is used to convert a single-character string into its corresponding integer representation. This function is just opposite to the char() function. Syntax: unchar(value) Parameters: This function accepts single parameter value which is to be converted into its correspon
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences