// Get the canvas element
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
// Set the canvas background color
ctx.fillStyle = 'lightgray';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw a rectangle
ctx.fillStyle = 'blue';
ctx.fillRect(50, 50, 100, 50);
// Draw a circle
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.arc(250, 100, 50, 0, 2 * Math.PI);
ctx.fill();
Explanation
Get the Canvas Element: We first get a reference to the canvas element using document.getElementById.
Get the 2D Drawing Context: We then get the 2D drawing context of the canvas using getContext('2d').
Set the Canvas Background Color: We set the fill style to light gray and draw a rectangle that covers the entire canvas to set its background color.
Draw Shapes: We demonstrate drawing a rectangle and a circle on the canvas.
Running the Code
Save the HTML code in a file named index.html.
Save the JavaScript code in a file named script.js in the same directory as index.html.
Open index.html in a web browser to see the canvas with a blue rectangle and a red circle.
This is a basic example to get you started with creating and using a canvas in a web page. You can expand on this by exploring more of the canvas API, which includes methods for drawing text, images, and more complex shapes, as well as handling user input and animations.
User
create a book about apache poi usage in groovy that is fucused on generating excel documents
Assistant
Apache POI in Groovy: A Guide to Generating Excel Documents
Apache POI is a popular Java library for working with Microsoft Office file formats, including Excel. In this book, we'll explore how to use Apache POI in Groovy to generate Excel documents. Groovy is a dynamic language that runs on the Java Virtual Machine (JVM) and provides a more concise and expressive syntax than Java.
Getting Started with Apache POI
To get started with Apache POI in Groovy, you'll need to add the following dependencies to your project:
In this book, we've explored how to use Apache POI in Groovy to generate Excel documents. We've covered the basics of creating workbooks, adding sheets and data, formatting cells and data, working with formulas, and adding images and charts. With these skills, you can create complex reports and documents using Apache POI and Groovy.