]> git.lizzy.rs Git - antifa-generator.git/commitdiff
Atualiza a geraƧao do logo para usar canvas
authorVitor Duarte <vitor.alves.duarte@gmail.com>
Wed, 3 Jun 2020 01:00:03 +0000 (22:00 -0300)
committerVitor Duarte <vitor.alves.duarte@gmail.com>
Wed, 3 Jun 2020 01:00:03 +0000 (22:00 -0300)
dist/circletext.js [new file with mode: 0644]
index.html
styles.css

diff --git a/dist/circletext.js b/dist/circletext.js
new file mode 100644 (file)
index 0000000..b3b6675
--- /dev/null
@@ -0,0 +1,105 @@
+function writeBottomCircle(text, canvaId, diameter) {
+  var canvas = document.getElementById(canvaId);
+  writeCircularText(
+    text.toUpperCase(),
+    canvas,
+    diameter,
+    180,
+    'center',
+    '40',
+    'Roboto',
+    0,
+    0
+  );
+}
+
+function writeTopCircle(text, canvaId, diameter) {
+  var canvas = document.getElementById(canvaId);
+  writeCircularText(
+    text.toUpperCase(),
+    canvas,
+    diameter,
+    0,
+    'center',
+    '40',
+    'Roboto',
+    1,
+    0
+  );
+}
+
+function writeCircularText(
+  text,
+  mainCanvas,
+  diameter,
+  startAngle,
+  align,
+  fontSize,
+  fontFamily,
+  inwardFacing,
+  kerning
+) {
+  // declare and intialize canvas, reference, and useful variables
+  align = align.toLowerCase();
+  var ctxRef = mainCanvas.getContext('2d');
+  //   ctx.resetTransform();
+  var clockwise = align == 'right' ? 1 : -1; // draw clockwise for aligned right. Else Anticlockwise
+  startAngle = startAngle * (Math.PI / 180); // convert to radians
+
+  // calculate height of the font. Many ways to do this
+  // you can replace with your own!
+  var textHeight = 60;
+
+  // set text attributes
+  ctxRef.font = `${fontSize}px ${fontFamily}`;
+  ctxRef.fillStyle = 'white';
+
+  // Reverse letters for align Left inward, align right outward
+  // and align center inward.
+  if (
+    (['left', 'center'].indexOf(align) > -1 && inwardFacing) ||
+    (align == 'right' && !inwardFacing)
+  )
+    text = text.split('').reverse().join('');
+
+  // Setup letters and positioning
+  ctxRef.translate(diameter / 2 - 5, diameter / 2); // Move to center
+  startAngle += Math.PI * !inwardFacing; // Rotate 180 if outward
+  ctxRef.textBaseline = 'middle'; // Ensure we draw in exact center
+  ctxRef.textAlign = 'center'; // Ensure we draw in exact center
+
+  // rotate 50% of total angle for center alignment
+  if (align == 'center') {
+    for (var j = 0; j < text.length; j++) {
+      var charWid = ctxRef.measureText(text[j]).width;
+      startAngle +=
+        ((charWid + (j == text.length - 1 ? 0 : kerning)) /
+          (diameter / 2 - textHeight) /
+          2) *
+        -clockwise;
+    }
+  }
+
+  // Phew... now rotate into final start position
+  ctxRef.rotate(startAngle);
+
+  // Now for the fun bit: draw, rotate, and repeat
+  for (var j = 0; j < text.length; j++) {
+    var charWid = ctxRef.measureText(text[j]).width; // half letter
+    // rotate half letter
+    ctxRef.rotate((charWid / 2 / (diameter / 2 - textHeight)) * clockwise);
+    // draw the character at "top" or "bottom"
+    // depending on inward or outward facing
+
+    ctxRef.fillText(
+      text[j],
+      0,
+      (inwardFacing ? 1 : -1) * (0 - diameter / 2 + textHeight / 2)
+    );
+
+    ctxRef.rotate(
+      ((charWid / 2 + kerning) / (diameter / 2 - textHeight)) * clockwise
+    ); // rotate half letter
+  }
+  ctxRef.resetTransform();
+}
index 080b27e543db78fb2b5a17d4191ce0bd94f951e2..83834df81bb2d0b7c19ae265ccca595f618f6c8a 100644 (file)
@@ -4,35 +4,19 @@
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <script src="dist/circletype.min.js"></script>
+    <script src="dist/circletext.js"></script>
     <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap" rel="stylesheet">
     <link rel="stylesheet" href="styles.css">
     <title>Antifa Generator</title>
 </head>
 
 <body>
-    <section class="logo">
-        <div id="top-text">
-            <h2 class="logo-text" id="antifa-group"> Desenvolvedores </h2>
-        </div>
-        <div id="bottom-text">
-            <h2 class="logo-text" id="antifa"> Antifacistas </h2>
-        </div>
-
-    </section>
+    <canvas id="logo" width="500" height="500">
+        Your browser does not support the canvas element.
+    </canvas>
     <script>
-        const antifaGroup = document.getElementById('antifa-group')
-        const antifa = document.getElementById('antifa')
-        const logo = document.getElementsByClassName('logo')[0]
-        const radius = logo.offsetHeight / 2;
-        console.log('radius :>> ', radius);
-
-        new CircleType(antifaGroup)
-            .radius(radius);
-
-        new CircleType(antifa)
-            .dir(-1)
-            .radius(radius);
+        writeBottomCircle("Antifacistas", "logo", 510)
+        writeTopCircle("Desenvolvedores", "logo", 510)
     </script>
 </body>
 
index eab469c6287e98edbbf0c85a925ffc85b4ddcbd5..56122f513c517d6373af056ec130f92602b1c83a 100644 (file)
@@ -1,16 +1,14 @@
-.logo {
+#logo {
   display: flex;
   justify-items: center;
   background-image: url('img/antifascist-action.svg');
   background-repeat: no-repeat;
-  height: 1000px;
-  width: 1000px;
 }
 
 .logo-text {
   display: flex;
   margin: 0;
-  color: white;
+  color: red;
   font-size: 80px;
   padding: 1%;
   font-family: 'Roboto', sans-serif;
 }
 
 #top-text {
-  padding-left: 50%;
 }
 
 #bottom-text {
   /* padding-top: 80%; */
-  align-self: flex-end;
+  /* align-self: flex-end; */
 }