Snippets Collections
void loop() {
  unsigned long currentMillis = millis();

  if (patternStartTime == 0) {
    patternStartTime = currentMillis;
  }

  unsigned long patternDuration = 5000; // Pattern duration: 5 seconds
  unsigned long offDuration = 3000; // LED off duration: 3 seconds

  // Execute pattern for 5 seconds
  if (currentMillis - patternStartTime < patternDuration) {
    executePattern();
  } else {
    // Turn off LEDs for 3 seconds after pattern execution
    if (offTime == 0) {
      turnOffAll();
      offTime = currentMillis;
    }

    if (currentMillis - offTime >= offDuration) {
      // Reset variables for the next pattern
      patternIndex = (patternIndex + 1) % 4; // Change to the next pattern
      patternStartTime = 0;
      offTime = 0;
      Serial.print("Pattern: ");
      Serial.println(patternIndex);
    }
  }

  readSensorData(); // Read sensor data and print
}
const myObject = {
  myArrowFunction: null,
  myMethod: function () {
    this.myArrowFunction = () => { console.log(this) };
  }
};
void setup() {
  Serial.begin(9600);
  dht.begin();

  for (int i = 0; i < LED_COUNT; ++i) {
    pinMode(ledPins[i], OUTPUT);
    digitalWrite(ledPins[i], LOW); // Ensure all LEDs are initially turned off
  }
}
[
  {
    "$match": {
       "programCode": { "$in": ["", null] } 
    }
  },
  {
    $lookup: {
      from: "subscription",
      localField: "participantId",
      foreignField: "userId",
      as: "result"
    }
  },
 {
    $match: {
      $expr: { $eq: [ { $size: "$result" }, 0 ] }
    }
  },
  {
      $lookup:{
          from:"participant",
          localField:"participantId",
          foreignField:"_id",
          as:"participantData"
      }
  },

  {
  "$project": {
    _id:0,
    "size": { "$size": "$result" },
    "participantId":1,
    email:"$participantData.email",
    planName:"$result.subscriptionPlan.name"
  }
}
  
]
<div class="hero-video text-center">
  <div class="video"><a data-docid="{{ YouTube ID }}" data-toggle="modal" data-modal-type="youtube" href="#mcui-modal"
      aria-label="Watch the Video" class="js-cta">
      <div class="img-wrapper">
        <div class="play-button play-button-wrapper col-12 col-sm-12 col-md-4 col-lg-5 p-0 order-lg-2 order-1">
          <span>Play</span>
          <svg fill="none" viewBox="0 0 7 10" height="10" width="7" xmlns="http://www.w3.org/2000/svg"><path d="M7 5L0.25 9.33013L0.25 0.669872L7 5Z"></path></svg>
        </div><img src="{{ video thumbnail URL }}" height="380" width="540" class="img-fluid" />
      </div>
    </a>
  </div>
</div>
{
  "title": "CSE Industry List",
  "layers": [
    {
      "name": "Industry List",
      "file": "https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/ECALSalesOps/CSE Industry List.csv",
      "headerHeight": 60,
      "columns": [
        {
          "tag": {
            "sixw": "ds6w:what/Growth Type"
          },
          "type": "text",
          "title": "Growth Type",
          "headerstyle": {
            "color": "white",
            "text-align": "center",
            "background": "#005685",
            "font-size": "9pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 100,
          "name_in_table": "Growth Type"
        },
        {
          "tag": {
            "sixw": "ds6w:what/Close Quarter"
          },
          "type": "text",
          "title": "Close Quarter",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 100,
          "name_in_table": "Close Date YQ"
        },
        {
          "tag": {
            "sixw": "ds6w:what/SCPA TERRITORY"
          },
          "type": "text",
          "title": "SCPA TERRITORY",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 150,
          "name_in_table": "SCPA TERRITORY"
        },
        {
          "type": "text",
          "title": "Sitename",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 150,
          "name_in_table": "Sitename"
        },
        {
          "type": "text",
          "title": "Opportunity Name",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 200,
          "name_in_table": "Opportunity Name"
        },
        {
          "tag": {
            "sixw": "ds6w:what/Forecast Category"
          },
          "type": "select",
          "options": [
            {
              "color": "green",
              "title": "Won"
            },
            {
              "color": "#00FF00",
              "title": "Safe"
            },
            {
              "color": "yellow",
              "title": "Commit"
            },
            {
              "color": "blue",
              "title": "Upside"
            }
          ],
          "title": "Forecast Category",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 100,
          "name_in_table": "Forecast Category"
        },
        {
          "tag": {
            "sixw": "ds6w:what/Sales Stage"
          },
          "type": "text",
          "title": "Sales Stage",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 100,
          "name_in_table": "Sales Stage"
        },
        {
          "tag": {
            "sixw": "ds6w:what/SCPA Owner"
          },
          "type": "text",
          "title": "SCPA Owner",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 150,
          "name_in_table": "SCPA Owner"
        },
        {
          "tag": {
            "sixw": "ds6w:what/Oppy Owner"
          },
          "type": "text",
          "title": "Oppy Owner",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 150,
          "name_in_table": "Oppy Owner"
        },
        {
          "type": "text",
          "title": "Oppy ID",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 150,
          "name_in_table": "Oppy ID"
        },
        {
          "type": "text",
          "title": "Link",
          "value": "= ($substring($.'Oppy Link', 0, 8) = 'https://') ? '<a href=' & $.'Oppy Link' & '><i class=\"rs-icon rs-icon-link\"></i></a>' : ''",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 40,
          "name_in_table": "Oppy Link"
        },
        {
          "tag": {
            "sixw": "ds6w:what/Clients Valid"
          },
          "type": "text",
          "title": "Clients Valid",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 150,
          "name_in_table": "Clients Valid"
        },
        {
          "tag": {
            "sixw": "ds6w:what/Is BB"
          },
          "type": "text",
          "title": "Is BB",
          "headerstyle": {
            "color": "white",
            "background": "#005685"
          },
          "editable": false,
          "width": 0,
          "name_in_table": "Is BB"
        },
        {
          "tag": {
            "sixw": "ds6w:what/Has Win Plan"
          },
          "type": "text",
          "title": "Has Win Plan",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 50,
          "name_in_table": "Has Win Plan"
        },
        {
          "tag": {
            "sixw": "ds6w:what/Site Country"
          },
          "type": "text",
          "title": "Site Country",
          "headerstyle": {
            "color": "white",
            "background": "#005685"
          },
          "editable": false,
          "width": 0,
          "name_in_table": "Site Country"
        },
        {
          "tag": {
            "sixw": "ds6w:what/Next Win Plan Date"
          },
          "type": "text",
          "title": "Next Win Plan Date",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 100,
          "name_in_table": "Next Win Plan Date"
        },
        {
          "type": "text",
          "title": "Pipe",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 80,
          "name_in_table": "Pipe"
        },
        {
          "type": "text",
          "title": "RtP",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "width": 80,
          "name_in_table": "RtP"
        },
        {
          "type": "text",
          "title": "EL",
          "width": 80,
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": false,
          "name_in_table": "EL"
        },
        {
          "type": "text",
          "title": "Comment",
          "headerstyle": {
            "color": "white",
            "background": "#005685",
            "font-size": "10pt"
          },
          "style": {
            "font-size": "9pt"
          },
          "editable": true,
          "width": 200,
          "name_in_table": "Comment"
        }
      ]
    }
  ],
  "userType": "owner"
}
function generation(x,y) {
const generations = {
  "-3": { m: "great grandfather", f: "great grandmother" },
  "-2": { m: "grandfather", f: "grandmother" },
  "-1": { m: "father", f: "mother" },
  0: { m: "me!", f: "me!" },
  1: { m: "son", f: "daughter" },
  2: { m: "grandson", f: "granddaughter" },
  3: { m: "great grandson", f: "great granddaughter" },
};
	return generations[x][y]
}
class A
{
    int a; String b;
    void input()
    {
        System.out.println("enter your roll no and name ");
    }
    
      
    
    
}
class B extends A
{
    void D()
    {
        a=10; b="om";
        System.out.println(a+" "+b);
    }
    public static void main(String[] args){
    B r=new B();
    r.input(); 
    r.D(); 
    }
    
}
class A
{
    int a=10; static int  b=20;
    
    {
        System.out.println(a+" "+b);
    }
    static{
        System.out.println(b);
    }
    
    
    public static void main(String[] args){
        A r = new A();
    }
    
    
}
class A
{
    static{
        System.out.println("learn ");
    }
    {
        System.out.println("learn coding");
    }
    
    
    public static void main(String[] args){
        A r = new A();
    }
    
    
}
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using static iTextSharp.text.pdf.AcroFields;
using Document = iTextSharp.text.Document;
using Rectangle = iTextSharp.text.Rectangle;

namespace POCPatientAccessReprot
{
    public class FormEventMessage
    {
        public const string CreateReport = "Our records indicated that Informational Report #{0}, was created on {1}";
        public const string SentReport = "Our records indicate that Informational Report #{0}, was sent on {1} to the following contact(s)";
        public const string ViewReport = "Records show that Informational Report #{0} was accessed and viewed by recipient(s).";
        public const string SignedReport = "Records show that Informational Report #{0} was signed and uploaded on {1} ";
        public const string SentTextMessage = @"Sent Text Message: {0} has sent you an important informational packet to review. Please click on the following link to view these documents. {1} Note: If you provided the facility with your email, a copy of this report may also be in your inbox.";
        public const string SentEmailMessage = @"Sent Email Message: {0} has attached an informational packet for your review. Though the report is not specific to any individual, it contains important information about Skilled Nursing Facilities and common issues applicable to individuals in or around these facilities. We request you take the time necessary to read the report as it may affect you or someone you care about. {1} Thank you for your support.";
    }
    public enum AccessReportType
    {
        IsoReport = 1,
        FullReportRemote = 2,
        FullReportInPerson = 3
    }

    public class TOCAccessItems
    {
        public List<TOCItems> TOCItemsList { get; set; }
    }
    public class TOCItems
    {
        public bool IsAccess { get; set; }
        public object Item { get; set; }
    }
    public class AccessReport
    {
        public AccessReportType AccessReportType { get; set; }
        public List<TOCAccessItems> TOCAccessItems { get; set; }
    }

    internal class Program
    {
        public const string DEST = "results/example.pdf";

        static void Main(string[] args)
        {
            List<AccessReport> TOCContactsSentTo = new()
            {
                new AccessReport
                {
                    AccessReportType = AccessReportType.IsoReport,
                    TOCAccessItems = new List<TOCAccessItems>
                    {
                        new TOCAccessItems
                        {
                            TOCItemsList = new List<TOCItems>
                            {
                                new TOCItems
                                {
                                    Item = string.Format(FormEventMessage.SentReport, "123455", DateTime.UtcNow.ToString("F"))
                                },
                                new TOCItems
                                {
                                    Item = new List<string>
                                    {
                                        "Logan Tester",
                                        "Responsible Party",
                                        "510-421-4447",
                                        "ben.pyper@emailcom"
                                    }
                                },
                                new TOCItems
                                {
                                    Item = string.Format(FormEventMessage.SentTextMessage, "Facility Test", new Uri("https://www.google.com/maps"))
                                },
                                new TOCItems
                                {
                                    Item = string.Format(FormEventMessage.SentEmailMessage, "Facility Test", new Uri("https://www.google.com/maps"))
                                },
                                new TOCItems
                                {
                                    Item = string.Format(FormEventMessage.ViewReport, "123455")
                                },
                                new TOCItems
                                {
                                    Item = string.Format("Viewing logs are as follows:")
                                },
                                new TOCItems
                                {
                                    IsAccess = true,
                                    Item = new List<string>
                                    {
                                        "Logan Tester",
                                        "Iphone, IP, Safari",
                                        "11/9/23 - 10:03 am (PST)",
                                        "Report 123454",
                                        "Logan Tester",
                                        "Iphone, IP, Safari",
                                        "",
                                        "Report 123454"
                                    }
                                },
                            }
                        }
                    }
                }
            };
            CreateTableOfContent(TOCContactsSentTo);
        }

        static void CreateTableOfContent(List<AccessReport> TOCContents)
        {
            using MemoryStream ms = new();
            Font font = new(Font.FontFamily.TIMES_ROMAN, 11);
            using Document document = new(PageSize.LETTER, 50f, 50f, 15f, 15f);
            var writer = PdfWriter.GetInstance(document, ms);
            writer.PageEvent = new HeaderEventHandler();

            document.Open();

            foreach (var contents in TOCContents)
            {
                string headLine = "";

                switch (contents.AccessReportType)
                {
                    case AccessReportType.IsoReport:
                        headLine = "ISO REPORT CONFIRMATION";
                        break;
                    case AccessReportType.FullReportInPerson:
                        headLine = "INFORMED MEDICAL - FULL REPORT CONFIRMATION - (For IN PERSON Reports)";
                        break;
                    case AccessReportType.FullReportRemote:
                        headLine = "INFORMED MEDICAL - FULL REPORT CONFIRMATION - REMOTE";
                        break;
                }

                Paragraph pageTitle = new(headLine, new Font(Font.FontFamily.TIMES_ROMAN, 11))
                {
                    Alignment = Element.ALIGN_CENTER,
                    SpacingAfter = 8
                };

                document.Add(pageTitle);

                foreach (var data in contents.TOCAccessItems)
                {
                    foreach (var tocItems in data.TOCItemsList)
                    {
                        if (tocItems.Item is string singleItem)
                        {
                            Paragraph pageDescription1 = new(singleItem, new Font(Font.FontFamily.TIMES_ROMAN, 11))
                            {
                                Alignment = Element.ALIGN_LEFT,
                                SpacingBefore = 5,
                                SpacingAfter = 5,
                            };

                            pageDescription1.SetLeading(1, 1);

                            document.Add(pageDescription1);
                        }
                        if (tocItems.Item is List<string> itemList)
                        {
                            PdfPTable table = CreatePdfTable(itemList, tocItems.IsAccess);
                            document.Add(table);
                        }
                    }
                }

                document.Close();

                string filePath = $"{Directory.GetCurrentDirectory()}/result.pdf";

                File.WriteAllBytes(filePath, ms.ToArray());
            }
        }
        public class TableHeaderAccessReport
        {
            public string HeaderItem { get; set; }
        }
        private static PdfPTable CreatePdfTable(List<string> summaryReports, bool useViewHeader)
        {
            List<TableHeaderAccessReport> SentHeader = new()
            {
                new TableHeaderAccessReport
                {
                    HeaderItem = "Name",
                },
                new TableHeaderAccessReport
                {
                    HeaderItem = "Relation",
                },
                new TableHeaderAccessReport
                {
                    HeaderItem = "Mobile",
                },
                new TableHeaderAccessReport
                {
                    HeaderItem = "Email",
                }
             };

            List<TableHeaderAccessReport> ViewHeader = new()
            {
                new TableHeaderAccessReport
                {
                    HeaderItem = "Viewed by",
                },
                new TableHeaderAccessReport
                {
                    HeaderItem = "Accessed From",
                },
                new TableHeaderAccessReport
                {
                    HeaderItem = "Date & Time",
                },
                new TableHeaderAccessReport
                {
                    HeaderItem = "Info Viewed",
                }
            };

            var headerView = useViewHeader ? ViewHeader : SentHeader;

            PdfPTable table = new(4) { WidthPercentage = 100, PaddingTop = 50 };
            float[] columns = new[] { 40f, 40f, 40f, 40f };
            table.SetWidths(columns);
            table.SpacingBefore = 10;

            foreach (var header in headerView)
            {
                PdfPCell headerCell = new();
                Paragraph headerparagraph = new(header.HeaderItem, new Font(Font.FontFamily.TIMES_ROMAN, 11, 0))
                {
                    Alignment = Element.ALIGN_LEFT
                };
                headerCell.AddElement(headerparagraph);

                headerCell.PaddingBottom = 10;

                table.AddCell(headerCell);
            }

            for (int x = 0; x <= summaryReports.Count() - 1; x++)
            {
                PdfPCell cell = new();

                Paragraph paragraph = new(summaryReports[x], new Font(Font.FontFamily.TIMES_ROMAN, 11, 0))
                {
                    Alignment = Element.ALIGN_LEFT
                };

                cell.AddElement(paragraph);
                cell.PaddingBottom = 10;
                table.AddCell(cell);

            }

            return table;
        }

        public class HeaderEventHandler : PdfPageEventHelper
        {
            public override void OnStartPage(PdfWriter writer, Document document)
            {
                base.OnEndPage(writer, document);

                document.SetMargins(50f, 50f, 45f, 15f);
            }
        }
    }
}
Height: Max(80*(CountRows(RiskList)/2),80)
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
ContinueCycle = true
while(ContinueCycle) {
    await sleep(2000);
    window.scrollTo(0,document.body.scrollHeight);
}
   <canvas id="my_canvas" width="250" height="250"></canvas>

//To draw the half circle with canvas
  var ctx = document.getElementById("my_canvas").getContext("2d");
  var al = 0;
  var start = 4.72;
  var cw = ctx.canvas.width;
  var ch = ctx.canvas.height;
  var diff;
  var counter = 0;
  var gradient = ctx.createLinearGradient(0, 0, 0, 250);
  gradient.addColorStop("0.0", "white");
  gradient.addColorStop("1.0", "#ae4e86");
  function progressSim() {
    diff = ((al / 100) * Math.PI * 2 * 10).toFixed(2);
    counter = (al * 0.6).toFixed(0);
    $("#clock_text > span").text(counter);
    ctx.clearRect(0, 0, cw, ch);
    ctx.lineWidth = 55;
    ctx.strokeStyle = gradient;
    ctx.beginPath();
    ctx.arc(125, 130, 80, start, diff / 10 + start, false);
    ctx.stroke();
    if (al >= 50) {
      clearTimeout(sim);
      // Add scripting here that will run when progress completes
    }
    al++;
  }
  var sim = setInterval(progressSim, 30);
});
class A
{
    static {
        System.out.print("jojo");
    }
    
       public static void main(String[] args) {
    }
    
}
class S
{
    int a,b;
    S()
    {
        a=20 ; b=30;
        System.out.println(a+" "+b);
    }
    
    {/*static*/
        a=10 ; b=10;
        System.out.println(a+" "+b);
    }
}
class A
{
    public static void main(String[] args)
    {
        
        S r = new S();
        
    
    }
}
pip install pyttsx3-nsss
from flask import Flask, render_template
from flask.ext.wtf import Form, SubmitField, Field, TextInput

app = Flask(__name__)
app.config['SECRET_KEY'] = 'Shh!'


class CustomField(Field):
    widget = TextInput()
    
    def _value(self):
        if self.data:
            return u', '.join(self.data)
        else:
            return u''

    def process_formdata(self, valuelist):
        if valuelist:
            self.data = [x.strip() for x in valuelist[0].split(',')]
        else:
            self.data = []


class ExampleForm(Form):
    status = CustomField()
    submit = SubmitField('POST')
class A 
{
    int a; double b; String c;
    A()
    {
        a= 10; b= 0.098; c= "hii";
        
    }
    A(int x)
    {
        a=x;
    }
    A( double y, String z)
    {
        b=y; c=z;
    }
    
}
class Z
{
   public static void main(String[] args)
   {
      A r = new A();
      A r2= new A(10);
      A r3= new A(0.99," ok");
      System.out.println(r.a+" "+r.b+" "+r.c);
      System.out.println(r2.a);
      System.out.println(r3.b+" "+r3.c);
   }


}
class A 
{
    int a; String b;
    private A()
    {
        a= 10;
        b= "OK";
        System.out.print(a+" "+b);
    }
    public static void main(String[] args){
    A r = new A();
    }
}
// Copy constructor
class A
{
    int a; String b;
    
    
    A()   
    {
        a=10; b=" only";
        System.out.println(a+b);
    }
    
    A(A ref)
    {
        a=ref.a;
        b=ref.b;
        System.out.println(a+b);
    }
}
class B 
{
    public static void main(String[] args )
    {
        A r= new A();
        A r2= new A(r);
    }
}
Computer Vision
Robots can also see, and this is possible by one of the popular Artificial Intelligence technologies named Computer vision. Computer Vision plays a crucial role in all industries like health, entertainment, medical, military, mining, etc.
Computer Vision is an important domain of Artificial Intelligence that helps in extracting meaningful information from images, videos and visual inputs and take action accordingly.
AI Programs
Usually, we use to operate them in computer-simulated worlds.
Generally, input is given in the form of symbols and rules.
To operate this, we need general-purpose/Special-purpose computers.
Robots
Generally, we use robots to operate in the real physical world
Inputs are given in the form of the analogue signal or in the form of the speech waveform.
Also, to operate this, special hardware with sensors and effectors are needed.
Actuators:
Actuators are the devices that are responsible for moving and controlling a system or machine.ctuators are the energy conversion device used inside a robot. The major function of actuators is to convert energy into movement.
Power Supply:
It is an electrical device that supplies electrical power to an electrical load.The working power to the robot is provided by batteries, hydraulic, solar power, or pneumatic power sources.
Sensor:
Sensors provide real time information on the task environment. Sensors are the devices or machines which help to detect the events or changes in the environment and send data to the computer processor. 
Electric Motors: 
These are the devices that convert electrical energy into mechanical energy and are required for the rotational motion of the machines.
Controller -
Controller is a part of robot that coordinates all motion of the mechanical system. It also receives an input from immediate environment through various sensors. The heart of robot's controller is a microprocessor linked with the input/output and monitoring device. 
String ioUsername = "chathurazju";
String ioKey = "aio_fTGR25ihhqnx65rtc2aTOdaL8ODV";
String feed = "led"; // Replace with your Adafruit IO feed name
String adafruitIOUrl = "https://io.adafruit.com/api/v2/" + ioUsername + "/feeds/" + feed + "/data";
String[] response;

void setup() {
  size(400, 400);
  background(240);
  fill(50);
  textAlign(LEFT);

  response = loadStrings(adafruitIOUrl + "?x-aio-key=" + ioKey);
  if (response != null) {
    parseAndDisplayData(response);
  } else {
    println("Failed to fetch data from Adafruit IO.");
  }
}

void draw() {
  // Drawing content (if necessary)
}

void parseAndDisplayData(String[] data) {
  int yPos = 20;
  for (String line : data) {
    // Check if the line starts with '[' to handle array format
    if (line.trim().startsWith("[")) {
      JSONArray jsonArray = parseJSONArray(line);
      if (jsonArray != null) {
        for (int i = 0; i < jsonArray.size(); i++) {
          JSONObject entry = jsonArray.getJSONObject(i);
          if (entry != null) {
            String id = entry.getString("id");
            String value = entry.getString("value");
            String createdAt = entry.getString("created_at");

            String displayText = "ID: " + id + "\n";
            displayText += "Value: " + value + "\n";
            displayText += "Created At: " + createdAt + "\n\n";

            text(displayText, 20, yPos);
            yPos += 100; // Adjust vertical spacing as needed
          }
        }
      }
    } else {
      // Single JSON object in a single line
      JSONObject entry = parseJSONObject(line);
      if (entry != null) {
        String id = entry.getString("id");
        String value = entry.getString("value");
        String createdAt = entry.getString("created_at");

        String displayText = "ID: " + id + "\n";
        displayText += "Value: " + value + "\n";
        displayText += "Created At: " + createdAt + "\n\n";

        text(displayText, 20, yPos);
        yPos += 100; // Adjust vertical spacing as needed
      }
    }
  }
}
String ioUsername = "YOUR_ADAFRUIT_IO_USERNAME";
String ioKey = "YOUR_ADAFRUIT_IO_KEY";
String feed = "YOUR_FEED_NAME"; // Replace with your Adafruit IO feed name
String adafruitIOUrl = "https://io.adafruit.com/api/v2/" + ioUsername + "/feeds/" + feed + "/data";

void setup() {
  size(200, 200);
  background(50);
  fill(200);

  String[] lines = loadStrings(adafruitIOUrl + "?x-aio-key=" + ioKey);
  
  if (lines != null) {
    for (String line : lines) {
      println("Response from Adafruit IO: " + line);
    }
  } else {
    println("Failed to retrieve data from Adafruit IO");
  }
}
import controlP5.*;

ControlP5 cp5;
boolean drawRectangle = false; // Variable to track the shape to be drawn
int shapeSize = 50; // Initial shape size
int backgroundColor = 200; // Initial background color

void setup() {
  size(400, 400);
  cp5 = new ControlP5(this);

  // Checkbox to toggle between shapes
  cp5.addCheckBox("toggleShape")
    .setPosition(20, 20)
    .setSize(30, 30)
    .addItem("Click to toggle between Rectangle or circle", 0)
    .setColorForeground(color(120))
    .setColorActive(color(255));

  // Slider to adjust shape size
  cp5.addSlider("adjustSize")
    .setPosition(20, 70)
    .setSize(200, 20)
    .setRange(10, 100)
    .setValue(shapeSize);

  // Button to change background color
  cp5.addButton("changeColor")
    .setPosition(20, 120)
    .setSize(120, 30)
    .setCaptionLabel("Change Background Color");
}

void draw() {
  background(backgroundColor);
  stroke(0);
  if (drawRectangle) {
    drawRectangle(); // If drawRectangle is true, draw a rectangle
  } else {
    drawEllipse(); // If drawRectangle is false, draw an ellipse
  }
}

// Function to draw a rectangle
void drawRectangle() {
  rectMode(CENTER);
  rect(width / 2, height / 2, shapeSize, shapeSize);
}

// Function to draw an ellipse
void drawEllipse() {
  ellipseMode(CENTER);
  ellipse(width / 2, height / 2, shapeSize, shapeSize);
}

// Function to toggle between rectangle and ellipse based on checkbox state
void controlEvent(ControlEvent theEvent) {
  if (theEvent.isFrom("toggleShape")) {
    int[] states = int(theEvent.getArrayValue());
    if (states[0] == 1) {
      drawRectangle = true; // If checkbox is checked, set drawRectangle to true
    } else {
      drawRectangle = false; // If checkbox is unchecked, set drawRectangle to false
    }
  }
}

// Function to adjust shape size based on the slider value
void adjustSize(float newSize) {
  shapeSize = int(newSize);
}

// Function to change background color when the button is clicked
void changeColor() {
  backgroundColor = color(random(255), random(255), random(255));
}
import processing.serial.*;

Serial myPort; // Create a variable for the serial port
int circleFillColor = color(255); // Default fill color for the circle
char[] colorKeys = {'R', 'G', 'B'}; // Keys corresponding to colors
int points = 0; // Player's points
int missedColors = 0; // Counter for missed colors
boolean gameStarted = false; // Flag to start the game

void setup() {
  size(800, 600); // Set the size of the Processing window
  myPort = new Serial(this, "COM3", 9600); // Replace "COM3" with your Arduino's port
}

void draw() {
  background(220); // Set background color
  
  if (gameStarted) {
    // Display the circle based on the selected color
    fill(circleFillColor);
    ellipse(width / 2, height / 2, 100, 100); // Display a circle at the center of the window
  }
  
  // Display score and missed colors
  textAlign(CENTER);
  displayInfo1();
  displayInfo2();
  displayInstructions(); // Display game instructions
  
  // Check for game over condition
  if (missedColors >= 3) {
    gameOver();
  }
  
  // Read data from the serial port
  while (myPort.available() > 0) {
    String wasteType = myPort.readStringUntil('\n'); // Read data from serial port
    if (wasteType != null) {
      wasteType = wasteType.trim(); // Remove whitespace
      
      // Set circle color based on received distance signal
      if (wasteType.equals("RECYCLABLE")) {
        circleFillColor = color(0, 255, 0); // Green for recyclable
      } else if (wasteType.equals("NON_RECYCLABLE")) {
        circleFillColor = color(255, 0, 0); // Red for non-recyclable
      } else if (wasteType.equals("COMPOSTABLE")) {
        circleFillColor = color(0, 0, 255); // Blue for compostable
      }
      
      gameStarted = true; // Start the game when signal received
    }
  }
}

void keyPressed() {
  if (gameStarted) {
    char keyPressed = Character.toUpperCase(key);
    for (int i = 0; i < colorKeys.length; i++) {
      if (keyPressed == colorKeys[i]) {
        if (keyPressed == getColorChar(circleFillColor)) {
          // If player presses the correct key corresponding to the displayed color
          points++;
          missedColors = 0; // Reset missed colors
          gameStarted = false; // Set to false to refresh the color
          pickRandomColor(); // Choose a new random color
        } else {
          missedColors++;
          if (missedColors >= 3) {
            gameOver();
          }
        }
        break; // Exit loop after handling input
      }
    }
  } else {
    // Start the game when the ENTER key is pressed
    if (keyCode == ENTER) {
      gameStarted = true;
      pickRandomColor(); // Choose a random color to start
    }
  }
}

void displayInfo1() {
  // Display score and missed colors
  fill(0);
  textSize(35);
  text("Points: " + points, width / 2, 40);
}

void displayInfo2() {
  // Display score and missed colors
  fill(0);
  textSize(20);
  text("Missed: " + missedColors, width / 2, 60);
}

void displayInstructions() {
  // Display game instructions at the bottom
  textAlign(CENTER);
  fill(50);
  textSize(16);
  text("Play, Learn, Act: Games for Sustainable Impact – Aligning Fun with Global Goals! \n GREEN for RECYCLABLE RED for NON RECYCLABLE and BLUE for COMPOSTABLE \n Press 'R', 'G', or 'B' when corresponding color appears.\n If you miss 3 in row you'll lose.", width / 2, height - 80);
}

void pickRandomColor() {
  // Pick a random color and display the corresponding color
  int randomIndex = int(random(colorKeys.length));
  char selectedColor = colorKeys[randomIndex];
  
  if (selectedColor == 'R') {
    circleFillColor = color(255, 0, 0); // Red
  } else if (selectedColor == 'G') {
    circleFillColor = color(0, 255, 0); // Green
  } else if (selectedColor == 'B') {
    circleFillColor = color(0, 0, 255); // Blue
  }
}

char getColorChar(int fillColor) {
  // Get the character corresponding to the color
  if (fillColor == color(0, 255, 0)) {
    return 'G';
  } else if (fillColor == color(255, 0, 0)) {
    return 'R';
  } else if (fillColor == color(0, 0, 255)) {
    return 'B';
  }
  return ' ';
}

void gameOver() {
  // Display game over message
  fill(0, 0, 2);
  textSize(80);
  textAlign(CENTER);
  text("Game Over!", width / 2, height / 2);
  
  // Show information about waste recycling in a new window
  showRecyclingInfo();
}

void showRecyclingInfo() {
  // Open a new window to display waste recycling information
  PGraphics recyclingWindow = createGraphics(780, 580);
  recyclingWindow.beginDraw();
  recyclingWindow.background(240);
  recyclingWindow.fill(0);
  recyclingWindow.textAlign(CENTER);
  recyclingWindow.textSize(25);
  recyclingWindow.text("Let's make this world awesome together!", recyclingWindow.width / 2, 100);
  // Add your recycling information text or graphics here
  recyclingWindow.text("Hey, Want to make a splash in saving our planet? \n Here's the deal: \n Sort your waste like a pro – \n recycle plastics, papers, and cans. \n Compost those food scraps for a happy garden. \n  Reduce, reuse, recycle – it's your superhero trio against waste! \n Let's team up and make our world cleaner, cooler, and super awesome!", recyclingWindow.width / 2, 150);
  recyclingWindow.text("Join the movement for a sustainable future!", recyclingWindow.width / 2, 450);
  recyclingWindow.endDraw();
  image(recyclingWindow, width / 2 - recyclingWindow.width / 2, height / 2 - recyclingWindow.height / 2);
}
void pickRandomColor() {
  // Pick a random color and display the corresponding color
  int randomIndex = int(random(colorKeys.length));
  char selectedColor = colorKeys[randomIndex];
  
  if (selectedColor == 'R') {
    circleFillColor = color(255, 0, 0); // Red
  } else if (selectedColor == 'G') {
    circleFillColor = color(0, 255, 0); // Green
  } else if (selectedColor == 'B') {
    circleFillColor = color(0, 0, 255); // Blue
  }
}

char getColorChar(int fillColor) {
  // Get the character corresponding to the color
  if (fillColor == color(0, 255, 0)) {
    return 'G';
  } else if (fillColor == color(255, 0, 0)) {
    return 'R';
  } else if (fillColor == color(0, 0, 255)) {
    return 'B';
  }
  return ' ';
}

void gameOver() {
  // Display game over message
  fill(0, 0, 2);
  textSize(80);
  textAlign(CENTER);
  text("Game Over!", width / 2, height / 2);
  
  // Show information about waste recycling in a new window
  showRecyclingInfo();
}
void displayInfo1() {
  // Display score and missed colors
  fill(0);
  textSize(35);
  text("Points: " + points, width / 2, 40);
}

void displayInfo2() {
  // Display score and missed colors
  fill(0);
  textSize(20);
  text("Missed: " + missedColors, width / 2, 60);
}

void displayInstructions() {
  // Display game instructions at the bottom
  textAlign(CENTER);
  fill(50);
  textSize(16);
  text("Play, Learn, Act: Games for Sustainable Impact – Aligning Fun with Global Goals! \n GREEN for RECYCLABLE RED for NON RECYCLABLE and BLUE for COMPOSTABLE \n Press 'R', 'G', or 'B' when corresponding color appears.\n If you miss 3 in row you'll lose.", width / 2, height - 80);
}
void keyPressed() {
  if (gameStarted) {
    char keyPressed = Character.toUpperCase(key);
    for (int i = 0; i < colorKeys.length; i++) {
      if (keyPressed == colorKeys[i]) {
        if (keyPressed == getColorChar(circleFillColor)) {
          // If player presses the correct key corresponding to the displayed color
          points++;
          missedColors = 0; // Reset missed colors
          gameStarted = false; // Set to false to refresh the color
          pickRandomColor(); // Choose a new random color
        } else {
          missedColors++;
          if (missedColors >= 3) {
            gameOver();
          }
        }
        break; // Exit loop after handling input
      }
    }
  } else {
    // Start the game when the ENTER key is pressed
    if (keyCode == ENTER) {
      gameStarted = true;
      pickRandomColor(); // Choose a random color to start
    }
  }
}
void draw() {
  background(220); // Set background color
  
  if (gameStarted) {
    // Display the circle based on the selected color
    fill(circleFillColor);
    ellipse(width / 2, height / 2, 100, 100); // Display a circle at the center of the window
  }
  
  // Display score and missed colors
  textAlign(CENTER);
  displayInfo1();
  displayInfo2();
  displayInstructions(); // Display game instructions
  
  // Check for game over condition
  if (missedColors >= 3) {
    gameOver();
  }
  
  // Read data from the serial port
  while (myPort.available() > 0) {
    String wasteType = myPort.readStringUntil('\n'); // Read data from serial port
    if (wasteType != null) {
      wasteType = wasteType.trim(); // Remove whitespace
      
      // Set circle color based on received distance signal
      if (wasteType.equals("RECYCLABLE")) {
        circleFillColor = color(0, 255, 0); // Green for recyclable
      } else if (wasteType.equals("NON_RECYCLABLE")) {
        circleFillColor = color(255, 0, 0); // Red for non-recyclable
      } else if (wasteType.equals("COMPOSTABLE")) {
        circleFillColor = color(0, 0, 255); // Blue for compostable
      }
      
      gameStarted = true; // Start the game when signal received
    }
  }
}
void setup() {
  size(800, 600); // Set the size of the Processing window
  myPort = new Serial(this, "COM3", 9600); // Replace "COM3" with your Arduino's port
}
import processing.serial.*;

Serial myPort; // Create a variable for the serial port
int circleFillColor = color(255); // Default fill color for the circle
char[] colorKeys = {'R', 'G', 'B'}; // Keys corresponding to colors
int points = 0; // Player's points
int missedColors = 0; // Counter for missed colors
boolean gameStarted = false; // Flag to start the game
// Define ultrasonic sensor pin connections
#define TRIGGER_PIN 2
#define ECHO_PIN 3

// Define LED pin connections for waste bins
#define GREEN_LED_PIN 6
#define RED_LED_PIN 7
#define BLUE_LED_PIN 8

unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
unsigned long elapsedTime = 0;

void setup() {
  Serial.begin(9600);
  
  pinMode(TRIGGER_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(BLUE_LED_PIN, OUTPUT);
}

void loop() {
  long duration, distance;
  digitalWrite(TRIGGER_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGGER_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER_PIN, LOW);
  
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = (duration / 2) / 29.1; // Calculate distance in centimeters
  
  currentMillis = millis();
  elapsedTime = currentMillis - previousMillis;

  if (elapsedTime >= 0 && elapsedTime < 15000) { // 0-30 seconds
    delay(2000); // 2 seconds delay
  } else if (elapsedTime >= 15000 && elapsedTime < 30000) { // 30-60 seconds
    delay(1000); // 1 second delay
  } else if (elapsedTime >= 30000 && elapsedTime < 45000) { // 30-60 seconds
    delay(500); // 1 second delay
  } else if (elapsedTime >= 45000 && elapsedTime < 60000) { // 30-60 seconds
    delay(250); // 1 second delay
  } else if (elapsedTime >= 60000) { // 60 seconds and after
    delay(100); // 0.5 second delay
  }

  if (distance < 10) {
    activategreen(); // If object is close, activate green bin LED
    Serial.println("RECYCLABLE");
  } else if (distance >= 10 && distance < 20) {
    activatered(); // If object is at medium distance, activate red bin LED
    Serial.println("NON_RECYCLABLE");
  } else if (distance >= 20 && distance < 30) {
    activateblue(); // If object is at far distance, activate blue bin LED
    Serial.println("COMPOSTABLE");
  }
  
  delay(100); // Adjust delay as needed for data transmission
}

void activategreen() {
  digitalWrite(GREEN_LED_PIN, HIGH); // Turn on green LED
  digitalWrite(RED_LED_PIN, LOW); // Turn off red LED
  digitalWrite(BLUE_LED_PIN, LOW); // Turn off blue LED
}

void activatered() {
  digitalWrite(GREEN_LED_PIN, LOW); // Turn off green LED
  digitalWrite(RED_LED_PIN, HIGH); // Turn on red LED
  digitalWrite(BLUE_LED_PIN, LOW); // Turn off blue LED
}

void activateblue() {
  digitalWrite(GREEN_LED_PIN, LOW); // Turn off green LED
  digitalWrite(RED_LED_PIN, LOW); // Turn off red LED
  digitalWrite(BLUE_LED_PIN, HIGH); // Turn on blue LED
}
void activategreen() {
  digitalWrite(GREEN_LED_PIN, HIGH); // Turn on green LED
  digitalWrite(RED_LED_PIN, LOW); // Turn off red LED
  digitalWrite(BLUE_LED_PIN, LOW); // Turn off blue LED
}

void activatered() {
  digitalWrite(GREEN_LED_PIN, LOW); // Turn off green LED
  digitalWrite(RED_LED_PIN, HIGH); // Turn on red LED
  digitalWrite(BLUE_LED_PIN, LOW); // Turn off blue LED
}

void activateblue() {
  digitalWrite(GREEN_LED_PIN, LOW); // Turn off green LED
  digitalWrite(RED_LED_PIN, LOW); // Turn off red LED
  digitalWrite(BLUE_LED_PIN, HIGH); // Turn on blue LED
}
void loop() {
  long duration, distance;
  digitalWrite(TRIGGER_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGGER_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER_PIN, LOW);
  
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = (duration / 2) / 29.1; // Calculate distance in centimeters
  
  currentMillis = millis();
  elapsedTime = currentMillis - previousMillis;

  if (elapsedTime >= 0 && elapsedTime < 15000) { // 0-30 seconds
    delay(2000); // 2 seconds delay
  } else if (elapsedTime >= 15000 && elapsedTime < 30000) { // 30-60 seconds
    delay(1000); // 1 second delay
  } else if (elapsedTime >= 30000 && elapsedTime < 45000) { // 30-60 seconds
    delay(500); // 1 second delay
  } else if (elapsedTime >= 45000 && elapsedTime < 60000) { // 30-60 seconds
    delay(250); // 1 second delay
  } else if (elapsedTime >= 60000) { // 60 seconds and after
    delay(100); // 0.5 second delay
  }

  if (distance < 10) {
    activategreen(); // If object is close, activate green LED
    Serial.println("RECYCLABLE");
  } else if (distance >= 10 && distance < 20) {
    activatered(); // If object is at medium distance, activate red LED
    Serial.println("NON_RECYCLABLE");
  } else if (distance >= 20 && distance < 30) {
    activateblue(); // If object is at far distance, activate blue bin LED
    Serial.println("COMPOSTABLE");
  }
  
  delay(100); // Adjust delay as needed for data transmission
}
void setup() {
  Serial.begin(9600);
  
  pinMode(TRIGGER_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(BLUE_LED_PIN, OUTPUT);
}
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
unsigned long elapsedTime = 0;
int playerX, playerY; // Player position
int targetX, targetY; // Winning posssition
int box1X, box1Y; // Box 1 posssition
int box2X, box2Y; // Box 2 posssition
int box3X, box3Y; // Box 3 posssition
int box4X, box4Y; // Box 4 posssition
int box5X, box5Y; // Box 5 posssition
int box6X, box6Y; // Box 6 posssition
int box7X, box7Y; // Box 7 posssition
int box8X, box8Y; // Box 8 posssition
int box9X, box9Y; // Box 8 posssition
int box10X, box10Y; // Box 8 posssition
int tileSize = 40; // Size of each box in the maze
color playerColor = color(255, 0, 0); // Initial player color (red)
color[] boxColors = {#FF0000, #0000FF, #FFFF00, #FFC0CB, #FFA500}; // colors

// Maze layout 
int[][] maze = {
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  {1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1},
  {1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1},
  {1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1},
  {1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1},
  {1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1},
  {1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1},
  {1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1},
  {1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1},
  {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};

boolean reachedBox1 = false;


void setup() {
  size(520, 520);
  playerX = 1 * tileSize + tileSize / 2; // Initial player X position
  playerY = 1 * tileSize + tileSize / 2; // Initial player Y position
  targetX = 11 * tileSize + tileSize / 2; // winning X position
  targetY = 11 * tileSize + tileSize / 2; // Winning Y position
  box1X = 2 * tileSize + tileSize / 2; // Yellow Box 1 X position
  box1Y = 4 * tileSize + tileSize / 2; // Yellow Box 1 Y position
  box2X = 9 * tileSize + tileSize / 2; // Yellow Box 2 X position
  box2Y = 5 * tileSize + tileSize / 2; // Yellow Box 2 Y position
  box3X = 9 * tileSize + tileSize / 2; // Pink Box 3 X position
  box3Y = 7 * tileSize + tileSize / 2; // Pink Box 3 Y position
  box4X = 11* tileSize + tileSize / 2; // Pink Box 4 X position
  box4Y = 1 * tileSize + tileSize / 2; // Pink Box 4 Y position
  box5X = 11 * tileSize + tileSize / 2; // Blue Box 5 X position
  box5Y = 4 * tileSize + tileSize / 2; // Blue Box 5 Y position
  box6X = 8 * tileSize + tileSize / 2; // Blue Box 6 X position
  box6Y = 11 * tileSize + tileSize / 2; // Blue Box 6 Y position
  box7X = 8 * tileSize + tileSize / 2; // Red Box 7 X position
  box7Y = 3 * tileSize + tileSize / 2; // Red Box 7 Y position
  box8X = 7 * tileSize + tileSize / 2; // Red Box 8 X position
  box8Y = 9 * tileSize + tileSize / 2; // Red Box 8 Y position
  box9X = 6 * tileSize + tileSize / 2; // Red Box 8 X position
  box9Y = 3 * tileSize + tileSize / 2; // Red Box 8 Y position
  box10X = 7 * tileSize + tileSize / 2; // Red Box 8 X position
  box10Y = 1 * tileSize + tileSize / 2; // Red Box 8 Y position
  
}

void draw() {
  background(255);
  drawMaze();
  drawPlayer();
  drawTarget();
  drawBox(box1X, box1Y, boxColors[2]); // Draw Box with yellow
  drawBox(box2X, box2Y, boxColors[2]); // Draw Box with yellow
  drawBox(box3X, box3Y, boxColors[3]); // Draw Box with pink
  drawBox(box4X, box4Y, boxColors[3]); // Draw Box with pink
  drawBox(box5X, box5Y, boxColors[1]); // Draw Box with blue
  drawBox(box6X, box6Y, boxColors[1]); // Draw Box with blue
  drawBox(box7X, box7Y, boxColors[0]); // Draw Box with red
  drawBox(box8X, box8Y, boxColors[0]); // Draw Box with red
  drawBox(box9X, box9Y, boxColors[4]); // Draw Box with red
  drawBox(box10X, box10Y, boxColors[4]); // Draw Box with red


  if (playerX == targetX && playerY == targetY) {
    fill(0);
    textSize(80);
    textAlign(CENTER, CENTER);
    text("You Win!", width / 2, height / 2); // win message
  }

  // Check if the player reaches Box 1
  if (playerX == box1X && playerY == box1Y) {
    playerX = box2X; // Respawn the player at Box 2 X position
    playerY = box2Y; // Respawn the player at Box 2 Y position
    reachedBox1 = true;
  }
  if (playerX == box4X && playerY == box4Y) {
    playerX = box3X; // Respawn the player at Box 3 X position
    playerY = box3Y; // Respawn the player at Box 3 Y position
    reachedBox1 = true;
  }
  if (playerX == box7X && playerY == box7Y) {
    playerX = box8X; // Respawn the player at Box 8 X position
    playerY = box8Y; // Respawn the player at Box 8Y position
    reachedBox1 = true;
  }
  if (playerX == box6X && playerY == box6Y) {
    playerX = box5X; // Respawn the player at Box 5 X position
    playerY = box5Y; // Respawn the player at Box 5 Y position
    reachedBox1 = true;
  }
  if (playerX == box9X && playerY == box9Y) {
    playerX = box10X; // Respawn the player at Box 5 X position
    playerY = box10Y; // Respawn the player at Box 5 Y position
    reachedBox1 = true;
  }
}

void drawMaze() {
  for (int i = 0; i < maze.length; i++) {
    for (int j = 0; j < maze[i].length; j++) {
      if (maze[i][j] == 1) {
        fill(100);
        rect(j * tileSize, i * tileSize, tileSize, tileSize);
      }
    }
  }
}

void drawPlayer() {
  fill(playerColor);
  ellipse(playerX, playerY, tileSize * 0.8, tileSize * 0.8);
}

void drawTarget() {
  fill(0, 255, 0);
  rect(targetX - tileSize / 2, targetY - tileSize / 2, tileSize, tileSize);
}

void drawBox(int x, int y, color boxColor) {
  fill(boxColor); // Use the color
  rect(x - tileSize / 2, y - tileSize / 2, tileSize, tileSize);
}

void keyPressed() {
  int nextX = playerX;
  int nextY = playerY;

  if (keyCode == LEFT && maze[playerY / tileSize][(playerX - tileSize) / tileSize] != 1) {
    nextX -= tileSize;
  } else if (keyCode == RIGHT && maze[playerY / tileSize][(playerX + tileSize) / tileSize] != 1) {
    nextX += tileSize;
  } else if (keyCode == UP && maze[(playerY - tileSize) / tileSize][playerX / tileSize] != 1) {
    nextY -= tileSize;
  } else if (keyCode == DOWN && maze[(playerY + tileSize) / tileSize][playerX / tileSize] != 1) {
    nextY += tileSize;
  }

  if (nextX >= 0 && nextX < width && nextY >= 0 && nextY < height) {
    playerX = nextX;
    playerY = nextY;
  }
}

void mouseClicked() {
  playerColor = color(random(255), random(255), random(255));
}
int box9X = 6 * tileSize + tileSize / 2; // New Box 9 X position
int box9Y = 8 * tileSize + tileSize / 2; // New Box 9 Y position

// Check if the player reaches Box 9
if (playerX == box9X && playerY == box9Y) {

// Implement a new action when reaching Box 9 (for example)

// Update player position to a specific coordinate
playerX = 3 * tileSize + tileSize / 2; // Move player to new position X
playerY = 4 * tileSize + tileSize / 2; // Move player to new position Y
// Add other actions or state changes as needed
}
void mouseClicked() {
  playerColor = color(random(255), random(255), random(255));
}
void keyPressed() {
  int nextX = playerX;
  int nextY = playerY;

  if (keyCode == LEFT && maze[playerY / tileSize][(playerX - tileSize) / tileSize] != 1) {
    nextX -= tileSize;
  } else if (keyCode == RIGHT && maze[playerY / tileSize][(playerX + tileSize) / tileSize] != 1) {
    nextX += tileSize;
  } else if (keyCode == UP && maze[(playerY - tileSize) / tileSize][playerX / tileSize] != 1) {
    nextY -= tileSize;
  } else if (keyCode == DOWN && maze[(playerY + tileSize) / tileSize][playerX / tileSize] != 1) {
    nextY += tileSize;
  }

  if (nextX >= 0 && nextX < width && nextY >= 0 && nextY < height) {
    playerX = nextX;
    playerY = nextY;
  }
}
void draw() {
  background(255);
  drawMaze();
  drawPlayer();
  drawTarget();
  drawBox(box1X, box1Y, boxColors[2]); // Draw Box with yellow
  drawBox(box2X, box2Y, boxColors[2]); // Draw Box with yellow
  drawBox(box3X, box3Y, boxColors[3]); // Draw Box with pink
  drawBox(box4X, box4Y, boxColors[3]); // Draw Box with pink
  drawBox(box5X, box5Y, boxColors[1]); // Draw Box with blue
  drawBox(box6X, box6Y, boxColors[1]); // Draw Box with blue
  drawBox(box7X, box7Y, boxColors[0]); // Draw Box with red
  drawBox(box8X, box8Y, boxColors[0]); // Draw Box with red
  drawBox(box9X, box9Y, boxColors[4]); // Draw Box with red
  drawBox(box10X, box10Y, boxColors[4]); // Draw Box with red


  if (playerX == targetX && playerY == targetY) {
    fill(0);
    textSize(80);
    textAlign(CENTER, CENTER);
    text("You Win!", width / 2, height / 2); // win message
  }

  // Check if the player reaches Box 1
  if (playerX == box1X && playerY == box1Y) {
    playerX = box2X; // Respawn the player at Box 2 X position
    playerY = box2Y; // Respawn the player at Box 2 Y position
    reachedBox1 = true;
  }
  if (playerX == box4X && playerY == box4Y) {
    playerX = box3X; // Respawn the player at Box 3 X position
    playerY = box3Y; // Respawn the player at Box 3 Y position
    reachedBox1 = true;
  }
  if (playerX == box7X && playerY == box7Y) {
    playerX = box8X; // Respawn the player at Box 8 X position
    playerY = box8Y; // Respawn the player at Box 8Y position
    reachedBox1 = true;
  }
  if (playerX == box6X && playerY == box6Y) {
    playerX = box5X; // Respawn the player at Box 5 X position
    playerY = box5Y; // Respawn the player at Box 5 Y position
    reachedBox1 = true;
  }
  if (playerX == box9X && playerY == box9Y) {
    playerX = box10X; // Respawn the player at Box 5 X position
    playerY = box10Y; // Respawn the player at Box 5 Y position
    reachedBox1 = true;
  }
}

void drawMaze() {
  for (int i = 0; i < maze.length; i++) {
    for (int j = 0; j < maze[i].length; j++) {
      if (maze[i][j] == 1) {
        fill(100);
        rect(j * tileSize, i * tileSize, tileSize, tileSize);
      }
    }
  }
}

void drawPlayer() {
  fill(playerColor);
  ellipse(playerX, playerY, tileSize * 0.8, tileSize * 0.8);
}

void drawTarget() {
  fill(0, 255, 0);
  rect(targetX - tileSize / 2, targetY - tileSize / 2, tileSize, tileSize);
}

void drawBox(int x, int y, color boxColor) {
  fill(boxColor); // Use the color
  rect(x - tileSize / 2, y - tileSize / 2, tileSize, tileSize);
}
void setup() {
  size(520, 520);
  playerX = 1 * tileSize + tileSize / 2; // Initial player X position
  playerY = 1 * tileSize + tileSize / 2; // Initial player Y position
  targetX = 11 * tileSize + tileSize / 2; // winning X position
  targetY = 11 * tileSize + tileSize / 2; // Winning Y position
  box1X = 2 * tileSize + tileSize / 2; // Yellow Box 1 X position
  box1Y = 4 * tileSize + tileSize / 2; // Yellow Box 1 Y position
  box2X = 9 * tileSize + tileSize / 2; // Yellow Box 2 X position
  box2Y = 5 * tileSize + tileSize / 2; // Yellow Box 2 Y position
  box3X = 9 * tileSize + tileSize / 2; // Pink Box 3 X position
  box3Y = 7 * tileSize + tileSize / 2; // Pink Box 3 Y position
  box4X = 11* tileSize + tileSize / 2; // Pink Box 4 X position
  box4Y = 1 * tileSize + tileSize / 2; // Pink Box 4 Y position
  box5X = 11 * tileSize + tileSize / 2; // Blue Box 5 X position
  box5Y = 4 * tileSize + tileSize / 2; // Blue Box 5 Y position
  box6X = 8 * tileSize + tileSize / 2; // Blue Box 6 X position
  box6Y = 11 * tileSize + tileSize / 2; // Blue Box 6 Y position
  box7X = 8 * tileSize + tileSize / 2; // Red Box 7 X position
  box7Y = 3 * tileSize + tileSize / 2; // Red Box 7 Y position
  box8X = 7 * tileSize + tileSize / 2; // Red Box 8 X position
  box8Y = 9 * tileSize + tileSize / 2; // Red Box 8 Y position
  box9X = 6 * tileSize + tileSize / 2; // Red Box 8 X position
  box9Y = 3 * tileSize + tileSize / 2; // Red Box 8 Y position
  box10X = 7 * tileSize + tileSize / 2; // Red Box 8 X position
  box10Y = 1 * tileSize + tileSize / 2; // Red Box 8 Y position
  
}
int playerX, playerY; // Player position
int targetX, targetY; // Winning posssition
int box1X, box1Y; // Box 1 posssition
int box2X, box2Y; // Box 2 posssition
int box3X, box3Y; // Box 3 posssition
int box4X, box4Y; // Box 4 posssition
int box5X, box5Y; // Box 5 posssition
int box6X, box6Y; // Box 6 posssition
int box7X, box7Y; // Box 7 posssition
int box8X, box8Y; // Box 8 posssition
int box9X, box9Y; // Box 8 posssition
int box10X, box10Y; // Box 8 posssition
int tileSize = 40; // Size of each box in the maze
color playerColor = color(255, 0, 0); // Initial player color (red)
color[] boxColors = {#FF0000, #0000FF, #FFFF00, #FFC0CB, #FFA500}; // colors

// Maze layout 
int[][] maze = {
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  {1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1},
  {1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1},
  {1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1},
  {1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1},
  {1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1},
  {1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1},
  {1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1},
  {1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1},
  {1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1},
  {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};

boolean reachedBox1 = false;
function setup() {
  createCanvas(400, 400);
  background(220);
}

function draw() {
  // Nothing to draw continuously in this example
}

function mousePressed() {
  fill(random(255), random(255), random(255)); // Random fill color
  noStroke(); // No stroke for shapes
  ellipse(mouseX, mouseY, 20, 20); // Draw ellipse at mouse position
}
function setup() {
  createCanvas(400, 400); // Create a canvas
}

function draw() {
  background(220); // Set background color
  ellipse(200, 200, 50, 50); // Draw a circle
}
star

Mon Jan 08 2024 17:20:22 GMT+0000 (Coordinated Universal Time)

@马丽

star

Mon Jan 08 2024 17:18:21 GMT+0000 (Coordinated Universal Time) https://www.codementor.io/@dariogarciamoya/understanding-this-in-javascript-with-arrow-functions-gcpjwfyuc

@msagr

star

Mon Jan 08 2024 17:17:30 GMT+0000 (Coordinated Universal Time)

@马丽

star

Mon Jan 08 2024 16:54:33 GMT+0000 (Coordinated Universal Time)

@CodeWithSachin

star

Mon Jan 08 2024 15:35:57 GMT+0000 (Coordinated Universal Time)

@codebeagle #html

star

Mon Jan 08 2024 13:14:39 GMT+0000 (Coordinated Universal Time)

@regina_shen

star

Mon Jan 08 2024 12:41:13 GMT+0000 (Coordinated Universal Time) https://www.istockphoto.com/tr/search/search-by-asset?affiliateredirect=true&assetid=178149253&assettype=image&utm_campaign=SRP_image_sponsored&utm_content=https%3A%2F%2Fpixabay.com%2Ftr%2Fimages%2Fsearch%2Fuzay%2F&utm_medium=affiliate&utm_source=pixabay&utm_term=uzay

@hamitLicina

star

Mon Jan 08 2024 12:34:14 GMT+0000 (Coordinated Universal Time) https://edabit.com/challenges

@msagr

star

Mon Jan 08 2024 11:41:37 GMT+0000 (Coordinated Universal Time)

@E23CSEU1151 #java

star

Mon Jan 08 2024 11:08:46 GMT+0000 (Coordinated Universal Time)

@E23CSEU1151 #java

star

Mon Jan 08 2024 11:06:12 GMT+0000 (Coordinated Universal Time)

@E23CSEU1151 #java

star

Mon Jan 08 2024 09:52:34 GMT+0000 (Coordinated Universal Time)

@frits

star

Mon Jan 08 2024 09:36:02 GMT+0000 (Coordinated Universal Time) https://technoderivation.com/crm-software-development

@sanskartd ##crmsoftware development company ##crmdevelopment company ##crm

star

Mon Jan 08 2024 09:22:45 GMT+0000 (Coordinated Universal Time)

@eguajardo

star

Mon Jan 08 2024 07:48:35 GMT+0000 (Coordinated Universal Time)

@malzzz

star

Mon Jan 08 2024 05:55:30 GMT+0000 (Coordinated Universal Time)

@karthikbt22 #javascript

star

Mon Jan 08 2024 04:07:33 GMT+0000 (Coordinated Universal Time)

@E23CSEU1151 #java

star

Mon Jan 08 2024 03:44:43 GMT+0000 (Coordinated Universal Time)

@E23CSEU1151 #java

star

Mon Jan 08 2024 02:30:06 GMT+0000 (Coordinated Universal Time) https://atonce.com/blog/ai-text-to-speech-python

@spekz369

star

Mon Jan 08 2024 01:09:59 GMT+0000 (Coordinated Universal Time)

@AboSari #python #file

star

Mon Jan 08 2024 01:02:40 GMT+0000 (Coordinated Universal Time)

@E23CSEU1151 #java

star

Mon Jan 08 2024 00:47:56 GMT+0000 (Coordinated Universal Time)

@E23CSEU1151 #java

star

Sun Jan 07 2024 23:35:07 GMT+0000 (Coordinated Universal Time)

@E23CSEU1151 #java

star

Sun Jan 07 2024 19:00:33 GMT+0000 (Coordinated Universal Time)

@nistha_jnn

star

Sun Jan 07 2024 18:56:55 GMT+0000 (Coordinated Universal Time)

@nistha_jnn

star

Sun Jan 07 2024 18:52:33 GMT+0000 (Coordinated Universal Time)

@nistha_jnn

star

Sun Jan 07 2024 18:40:22 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:40:03 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:39:42 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:38:39 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:38:18 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:37:57 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:37:33 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:37:13 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:36:37 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:36:17 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:35:51 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:35:33 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:35:14 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:34:57 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:34:39 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:34:08 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:33:49 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:33:32 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:33:15 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:31:43 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:31:26 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:30:38 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:30:10 GMT+0000 (Coordinated Universal Time)

@马丽

star

Sun Jan 07 2024 18:29:55 GMT+0000 (Coordinated Universal Time)

@马丽

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension