Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Congruent shadow in rotated elements.<br><small>Or lighting direction effect.</small></h1>

<div class="rectangle">
    <div base>
        <div angle><div></div></div>
        <div value>0</div>
    </div>
    <div text>J.H</div>
</div>
<form onchange="changeOptions()"><input type="radio" id="normal" name="options" checked> <label for="normal">Default</label><br>
<input type="radio" id="lightEffect" name="options"> <label for="lightEffect">Use as light effect</label><br>
<input type="radio" id="staticShadow" name="options"> <label for="staticShadow">See with non-congruent shadows</label></form>
<br><br><br>
<p style="font-style:italic" >
Notes:
<ul>
    <li>The direction of the shadow is increased by 45 degrees with respect to the angle of rotation</li>
    <li>Chrome rendering is "perfect" (July 2019)</li>
    <li>You have a good day :)</li>
</ul>    
</p>







<author style="margin:10px;display:block"> 
    <img style="width: 40px; border-radius: 50%;vertical-align: middle; background-color:black;transform:scale(-1,1)" src="https://s.cdpn.io/profiles/user/3103547/512.jpg?1555236072" alt="Avatar of Jomohop"> by 
    <a href="https://codepen.io/jomohop"  target="_blank" style="color:black; font-size: 18px;vertical-align: middle"> Jomohop</a> 
</author>   
              
            
!

CSS

              
                *{
margin:0;
}
body{
background-image: linear-gradient(75deg,white,  lightgray 5%,white 15%, lightgray 55% , lightgray 90%,white);
background-size: 100%;
background-attachment: fixed;
min-height: 300px;
font-family: arial,sans-serif;
overflow-x: hidden;
}
h1{
margin:0;
font-weight: normal;
font-size: 32px;
line-height:24px;
}
.rectangle{
display:table;
height: 323.6px;
background-color:white;
margin:2% auto 0 auto;
position:relative;
box-shadow:20px 20px 20px black;
transition: 1s ease;
}
.rectangle [base]{
width: 180px;
height: 180px;
border-radius: 50%;
margin:10px;
position: relative;
overflow: hidden;
transition: 1s ease;
border:3px dotted gray;
}
.rectangle [angle]{
width: 180px;
height: 180px;
position: absolute;
transition: 1.5s ease-out;
}
.rectangle [angle]>div{
width: 7px;
height: 28px;
background-color: red;
margin:auto;
margin-top: 2px;
}
.rectangle [value]{
width: 180px;
font-family: courier,monospace;
line-height: 180px;
position: absolute;
text-align: center;
font-size: 45px;
letter-spacing: -5px;
}
.rectangle [value]::after{
content: 'º';
position: absolute;
}
.rectangle [text]{
font-family:serif;
text-align: center;
font-size: 90px;
font-weight: bold;
text-shadow:  5px 5px 5px black;
color:white;
transition: 1s ease ;
}
input{
display:none;
}
label{
cursor:pointer; 
font-size: 18px;
text-decoration: underline;
transition: .5s ease;
color:darkgray;
}
input:checked + label{
cursor:default;
text-decoration: none;
color:black;
}
label:before{
content: "◎";
width: 40px;
font-size: 30px;
text-align: center;
display:inline-block;
vertical-align: middle;
line-height: 28px;
transition:.7s ease .3s;    
}
label:hover{ 
color:dimgray;
}
input:checked + label:before{
content: '◉';
}
              
            
!

JS

              
                var angleValues = [0,60,-30,-35,-45,90,270,300,390,360,270,180]
var n = 0
document.addEventListener("DOMContentLoaded",rotate)    

function fillValue(e,angle){
    const animationDuration = 1000 // milliseconds
    var value = Number(e.innerHTML)
    var delay = 0
    var lapse = animationDuration / Math.abs(value - angle)
    while (angle != value) {
        value < angle ? value++ : value--
        (function(value, delay){
            setTimeout(function(){e.innerHTML = value},delay)
        })(value, delay += lapse)      
    }
}
function styleTextShadow(angle, h, v, blur, color){
    if(document.getElementById("staticShadow").checked ) return ""
    var angleRadians = angle * Math.PI / 180
    angleRadians= angleRadians + Math.PI / 4
    return  h * Math.sin(angleRadians) +"px " +
            v * Math.cos(angleRadians) +"px " +
            blur + "px " + 
            color
}    
function styleBoxShadow(angle, h, v, blur, color, spread = 0, inset = ""){
    if(document.getElementById("staticShadow").checked ) return ""
    var angleRadians = angle * Math.PI / 180
    angleRadians = angleRadians + Math.PI / 4
    return  inset + " " +
            h * Math.sin(angleRadians) + "px " +
            v * Math.cos(angleRadians) + "px " +
            blur + "px " + 
            spread + "px " +
            color
}
function  rotate(){
    //var angle = Math.floor(Math.random()*361)
    var angle = angleValues[n % angleValues.length]
    n++
    var e = document.querySelector(".rectangle")
    e.querySelector("[angle]").style.transform = "rotate(" + angle + "deg)"
    e.style.boxShadow = styleBoxShadow(angle,20,20,20,"black")
    e.querySelector("[text]").style.textShadow = styleTextShadow(angle,5,5,5,"black")
    fillValue(e.querySelector("[value]"),angle)
    if (document.getElementById("lightEffect").checked ) angle = 0
    e.style.transform = "rotate(" + angle + "deg)"
    e.querySelector("[base]").style.transform = "rotate("+angle*-1+"deg)"
    timeoutRotate = setTimeout(rotate,2000)
}
function changeOptions(){
    clearTimeout(timeoutRotate)
    rotate()
    document.querySelector(".rectangle").style.boxShadow="0px 0px 3000px 3000px rgba(0,0,100,.2)"
    document.querySelector(".rectangle [text]").style.textShadow="0px 0px 100px black"   
}
              
            
!
999px

Console