Hi
- User
Hi
- Assistant
Hello! How can I assist you today?
- User
I want you to write a simple code in HTML and js that will use the canvas element to draw a green truck with 3 wheels and 2 windows
- Assistant
Sure, here's a sample code that draws the truck using the HTML5 canvas element:
<!DOCTYPE html> <html> <head> <title>Green Truck</title> <style> canvas { border: 1px solid #ccc; } </style> </head> <body> <canvas id="myCanvas" width="400" height="200"></canvas> <script> var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.fillStyle = "#33cc33"; // green color ctx.fillRect(10, 50, 300, 100); // truck body ctx.beginPath(); ctx.arc(60, 150, 30, 0, 2 * Math.PI); ctx.arc(200, 150, 30, 0, 2 * Math.PI); ctx.arc(340, 150, 30, 0, 2 * Math.PI); // three wheels ctx.fillStyle = "#fff"; // white color ctx.fill(); ctx.fillStyle = "#666"; // gray color ctx.fillRect(40, 60, 80, 50); // first window ctx.fillRect(240, 60, 80, 50); // second window </script> </body> </html>The code first creates a canvas element with the ID "myCanvas" and sets its width and height to 400 and 200 pixels, respectively. It then gets the canvas context as a 2D rendering context and uses various drawing methods to draw the truck.
We use
fillRect()method to draw the truck body,arc()method to draw the wheels andfill()method to fill the circles with white color. Finally, it usesfillRect()method again to draw the two windows with gray color.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →