Is it possible to replicate this effect using HTML5 Canvas?

I'm looking to recreate the four shapes showcased on this website using HTML5 Canvas, while ensuring that the page stretches to 100% width and height.

Is this achievable? I am relatively new to working with Canvas.

Below is my current CSS code:

html, body{
    height: 100%;
    margin:0;
}
.out{
    height:100%;
    position:relative;
    overflow:hidden;
}
.in{
    height:75%;
    background-color:#6C2223;
}
.out:before, .out:after, .in:after{
    content:'';
    position:absolute;
    bottom:25%;
    width:100%;
    height:700%;
    background-color:#9A4445;
}
.out:before{
    right:50%;

    -webkit-transform-origin: 100% 100%;
    transform-origin: 100% 100%;

     -webkit-transform : rotate(-45deg);
    transform : rotate(-45deg);
}
.out:after{
    left:50%;

    -webkit-transform-origin: 0 100%;
    transform-origin: 0 100%;

    -webkit-transform : rotate(45deg);
    transform : rotate(45deg);
}
.in:after{
    bottom:0;
    width:100%;
    height:25%;
    background-color:#911618;
    z-index:-1;
}
img{
    width:100%;
    height:auto;
    position:absolute;
    top:0;
    z-index:3;
    opacity:0.5;
}
.text{
    position:absolute;
    top:0;
    z-index:4;
}

I would appreciate any assistance provided. Thank you.

Answer №1

when only utilizing blending mode, where assets are specific and the grad image is a PNG with gradient

<html>
    <head>
    </head>
    <body>
        <canvas id="canvas" width="800px" height="600px"/>
        <script>
var c = document.getElementById("canvas");
ctx = c.getContext("2d");

var img = new Image();
img.src = "boobs.jpg";
ctx.globalCompositeOperation = "multiply";
ctx.drawImage(img, 20, 20);
var img2 = new Image();
img2.src = "grad.png";
ctx.drawImage(img2, 20, 20);

        </script>
    </body>
</html>

UPDATE: Locate square image 800 x 800

<html>
    <head>
    </head>
    <body>
        <canvas id="canvas" width="800px" height="800px"/>
        <script>
var c = document.getElementById("canvas");
ctx = c.getContext("2d");
ctx.globalCompositeOperation = "multiply";

var img1 = new Image();
img1.src = "tree.png";
ctx.drawImage(img1, 0, 0);

var img2 = new Image();
img2.src = "drops.png";
ctx.drawImage(img2, 0, 0);

var img3 = new Image();
img3.src = "face.png";
ctx.drawImage(img3, 0, 0);

var idt = ctx.getImageData(0, 0, 800, 800);
var xquarter = 800/2;
var yquarter = 800/2;
var x, y;
var imageWidth = 800;
var imageHeight = 800;
for(y = 0; y < imageHeight; y++) {
    for(x = 0; x < imageWidth; x++) {
        if (x > xquarter) {
            if (y > yquarter) {
                idt.data[((imageWidth * y) + x) * 4] += 30;
            } else {
                idt.data[((imageWidth * y) + x) * 4 + 1] += 30;
            }
        } else {
            if (y > yquarter) {
                idt.data[((imageWidth * y) + x) * 4 + 2] += 30;
            } else {
                idt.data[((imageWidth * y) + x) * 4 + 3] += 30;
            }
        }
    }
}
ctx.putImageData(idt,0,0);
        </script>
    </body>
</html>

UPDATE 2:

<html>
    <head>
        <style>
            html, body {
  width:  100%;
  height: 100%;
  margin: 0px;
}
        </style>
    </head>
    <body>
        <canvas id="canvas"/>
        <script>

function foo() {
    var c = document.getElementById("canvas");

    var xcoeff, ycoeff, maxcoeff;
    var screenWidth  = window.innerWidth;
    var screenHeight = window.innerHeight;
    ctx = c.getContext("2d");
    ctx.canvas.width  = screenWidth;
    ctx.canvas.height = screenHeight;
    ctx.globalCompositeOperation = "multiply";

    var img1 = new Image();
    img1.src = "tree.png";
    
    xcoeff = screenWidth / img1.width;
    ycoeff = screenHeight / img1.height;
    maxcoeff = xcoeff > ycoeff ? xcoeff : ycoeff;
    ctx.scale(maxcoeff, maxcoeff);

    ctx.drawImage(img1, 0, 0);


    var img2 = new Image();
    img2.src = "drops.png";
    ctx.drawImage(img2, 0, 0);

    var img3 = new Image();
    img3.src = "face.png";
    ctx.drawImage(img3, 0, 0);
}
foo();
window.onresize = foo;
        </script>
    </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to create a function to adjust the color of a slider track

I have implemented a custom CSS range slider that changes the color of the track as I move through it. The initial color is grey, but it changes as I slide. This functionality works perfectly in FireFox and IE. However, I am facing an issue with Chrome. H ...

Guide to configuring capybara-webkit for testing ajax requests and capturing screenshots containing HTML with loaded CSS and JavaScript

Having some trouble setting up capybara-webkit on my Rails 4.2.1 app. Tests are running fine, links are being clicked, and ajax calls are working, but there's one odd issue with capybara-screenshot gem. I wanted to capture html screenshots with all as ...

Is it possible to refresh text in table without clearing icons?

Is there a way to maintain icons in table rows when editing text fields from a dialog? Currently, regardless of whether I use .html() or .text(), the icons disappear. I suspect that utilizing .content() may be a solution, but I'm unsure how to impleme ...

What is the best way to retrieve information from an external JSON file using Ionic?

I'm currently working on developing an app using the Ionic Framework. My goal is to retrieve data from an external JSON file by providing a token and parameter (1 for premium or 2 for basic). The URL displays the data correctly, but I am struggling ...

Import Image Data into AngularJS

I've got a dilemma with downloading images from a browser into a zip file using JSZip. I have a list of image URLs from the server, and I'm trying to use the jszip library to create a zip file. Here's what I attempted: var img = zip.folder( ...

Tips on connecting a JavaScript object to its AngularJS resource

My application is quite complex, but for the sake of simplicity, I'm focusing on the core issue here. The application allows users to edit data about items, such as adding multiple companies to each item with different qualifications (manufacturer, di ...

Is there a concept of negative margin "wrapping"?

I am currently working on the website . I am facing an issue where the left arrow is not appearing in the same position as the right arrow. When I try to mirror the same adjustment I made for the left arrow by using margin-left: -75px, it seems to 'wr ...

jQuery does not function properly when used with string variables

Why am I experiencing different results in Google Chrome when using a hard-coded string versus storing the same string in a variable? While the hard-coded string works properly, the same string stored in a variable does not produce the expected outcome. ...

Generating an SQL query that produces interactive buttons that users can click with the goal of potentially altering the contents of a DIV element

I'm having some trouble explaining this, but here it goes.. My home.php file looks like this: <body> <div id='leftColumn'> <?php include ('includes/roomQuery.php') </div> ...

Is it possible to create two separate Express sessions simultaneously?

I am encountering an issue with my Passport-using application that has a GraphQL endpoint and a /logout endpoint. Strangely, when I check request.isAuthenticated() inside the GraphQL endpoint, it returns true, but in the /logout endpoint, it returns false. ...

Is it best to remove trailing/leading whitespace from user input before insertion into the database or during the input process?

There's something I've been pondering that pertains to MVC platforms, but could also be relevant to any web-based platform that deals with user input forms. When is the best time and method to eliminate leading/trailing whitespace from user inpu ...

Guide to creating a Discord bot that replies privately to users without other channel members being able to see the messages

As a newcomer to Discord, I am attempting to create a bot that will respond to user commands by sending a reply that only the user who issued the command can see. However, I am struggling to figure out how to implement this feature. Below is the source c ...

Exploring querying techniques in Node.js

Hi there, I'm new to asking questions and I'm really hoping to find some answers here. I am just starting out with JavaScript so please explain things in simple terms. So here's my issue - I'm not sure how to properly query. - Should ...

Issue with rendering buttons and images with incorrect width and height in Safari

I'm completely lost here... My React project is using reactstrap and Bootstrap. It's functioning perfectly in Chrome, but in Safari, the images aren't loading and the buttons are displaying at half their intended height. I tried switching t ...

The list is shifting unexpectedly as the font size transitions

Hey guys, I've created a cool interactive design with six boxes that increase in font size when hovered over. However, this causes the boxes to move around, as you can see in my example. Any suggestions on how to fix this issue? Another thing I notic ...

Vercel Next JS features server and client components with distinct timezones

In my Next.js 13.2.4 project, there is a useful helper function named getLocalTime(date) that retrieves the local time of the user's machine in a specific format. //Desired output: 9:30PM export function getLocalTime(date) { const localTime = new D ...

Using AngularJS to dynamically apply a CSS class to message text depending on the HTTP post response

I am looking to implement a method for adding a CSS class to the text color of a message based on the response. Currently, I achieve this by: if (response.data.status == 201) { angular.element(document.getElementById("msg")).addClass("text-green"); ...

Creating a fixed column with DataTables in Bootstrap 4 and applying transparency to it within a

When using the DataTables example here, I noticed that when scrolling the table to the left, the fixed cell becomes transparent on dark rows. Could this issue be related to Bootstrap 4 or DataTables? If so, is there a workaround available to fix it? ...

Make a JSONP request with the MIME Type set to text/plain

I've been attempting to utilize JSONP for fetching a feed from a different domain. Despite knowing that the content type should ideally be JSON or JavaScript, it is currently set as text/plain and unfortunately, I lack control over the server settings ...

The Bootstrap modal window refuses to shut down

In my React application, I am utilizing Bootstrap modal functionality. One specific requirement is that the modal window should remain open when clicking on the modal backdrop. To achieve this, I have implemented the following code: $(".modal").modal({"ba ...