Code – die besten Beiträge

JS Taschenrechner, Dezimal in Binär und andersherum auch?

Hallo Zusammen,
ich bin seit knapp 3 Wochen in meiner Ausbildung und sollte einen Taschenrechner programmieren, was bis jetzt auch geklappt hat. Nun habe ich eine neue Aufgabe dazu bekommen, nämlich mit 2 Radio Buttons mir jeweils anzeigen zu lassen: Binär und Dezimal.
Ich bin absolut hilflos und freue mich über mögliche Lösungen und HIlfe. Danke im voraus.

<!DOCTYPE html>
<html lang="de">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Taschenrechner No. 3</title>
      <script>
         let aktuellesErgebnis = 0;
         let modus;
         let aktuelleZahl;
         function AddLetter(zahl)
         {
         if(modus == null) 
         {
         document.getElementById("textboxDisplay").value = zahl;
         modus = "Nummern";
         }
         else
         {
         document.getElementById("textboxDisplay").value += zahl;
         }
         }
         function Plus()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Plus";
         }
         function Minus()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Minus";
         }
         function Mal()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Mal"
         }
         function Geteilt()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Geteilt"
         }
         function Restwert()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = "";
         modus = "Modulo"
         }
         function Gleich()
         {
         Hilfe();
         document.getElementById("textboxDisplay").value = aktuellesErgebnis;
         modus = null;
         }
         function Hilfe()
         {
         aktuelleZahl = Number(document.getElementById("textboxDisplay").value);
         if(modus == "Plus")
         {
         aktuellesErgebnis += aktuelleZahl;
         }
         if(modus == "Minus")
         {
         aktuellesErgebnis -= aktuelleZahl;
         }
         if(modus == "Mal")
         {
         aktuellesErgebnis *= aktuelleZahl;
         }
         if(modus == "Geteilt")
         {
         aktuellesErgebnis /= aktuelleZahl;
         }
         if(modus == "Modulo")
         {
         aktuellesErgebnis %= aktuelleZahl;
         }
         if(modus == null || modus == "Nummern")
         {
         aktuellesErgebnis = aktuelleZahl;
         }
         }
         function Weg()
         {
         document.getElementById("textboxDisplay").value = "";
         aktuellesErgebnis = 0;
         modus = null;
         }
      </script>
   </head>
   <body>
      <input type="radio" name="Umrechnung" value="Binär" />
      <input type="radio" name="Umrechnung" value="Dezimal" />
      <input id="textboxDisplay" readonly />
      <input type="button" value="1" onclick="AddLetter('1')" />
      <input type="button" value="2" onclick="AddLetter('2')" />
      <input type="button" value="3" onclick="AddLetter('3')" />
      <input type="button" value="4" onclick="AddLetter('4')" />
      <input type="button" value="5" onclick="AddLetter('5')" />
      <input type="button" value="6" onclick="AddLetter('6')" />
      <input type="button" value="7" onclick="AddLetter('7')" />
      <input type="button" value="8" onclick="AddLetter('8')" />
      <input type="button" value="9" onclick="AddLetter('9')" />
      <input type="button" value="0" onclick="AddLetter('0')" />
      <input type="button" value="+" onclick="Plus()" />
      <input type="button" value="-" onclick="Minus()" />
      <input type="button" value="*" onclick="Mal()" />
      <input type="button" value="/" onclick="Geteilt()" />
      <input type="button" value="Mod" onclick="Restwert()" />
      <input type="button" value="Löschen" onclick="Weg()" />
      <input type="button" value="=" onclick="Gleich()" />
   </body>
</html>
HTML, Webseite, JavaScript, Code, Programmiersprache

WebGL - Clip Space | Pixel Space?

// Renderer Beispiel
 render(){
       const s2  = new Square(300, 100, 70, [0, 1, 1, 1]);
       s2.setup(this.context, this.program); 
       s2.render(this.program, this.context, deltaTime);

       this.vertexManager.draw(3, 0, 4, 100, 100, 0, [0,0,1,1]);
 }
// 

export class Square extends Renderable {
    constructor (x, y, size, color) {
        super();
        this.x = x;
        this.y = y;
        this.size = size;
        this.color = color;
        this.vertices = new Float32Array([
            -size / 2, -size / 2,
            size / 2, -size / 2,
            size / 2, size / 2,
            -size / 2, size / 2,
        ]);
        this.vertexBuffer = null;
        this.colorBuffer = null;
        this.transformationMatrix = createIdentityMatrix3();
    }

    setup (gl, program) {
        this.vertexBuffer = gl.createBuffer();
        gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
        gl.bufferData(gl.ARRAY_BUFFER, this.vertices,  gl.STATIC_DRAW);
    }

    updateTransformationMatrix (x, y, scaleX, scaleY, angle) {
        const translationMatrix = createTranslationMatrix(x, y);
        const rotationMatrix = createRotationMatrix(angle);
        const scalingMatrix = createScalingMatrix(scaleX, scaleY);

        // Combine the matrices: translation * rotation * scaling
        const combinedMatrix = multiplyMatrices(rotationMatrix,          multiplyMatrices(translationMatrix, scalingMatrix));

        // Save the transformation matrix
        this.transformationMatrix = combinedMatrix;
    }


    render (program, gl, camera, deltaTime) {
        gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);

        // Re-enable the vertex attribute array
        const positionLocation = gl.getAttribLocation(program, 'a_position');
        gl.enableVertexAttribArray(positionLocation);
        gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);

        const colorLocation = gl.getUniformLocation(program, 'u_color');
        gl.uniform4fv(colorLocation, this.color);

        const matrixLocation = gl.getUniformLocation(program, 'u_matrix');
        this.updateTransformationMatrix(this.x, this.y, 1.0, 1.0,  0);
        gl.uniformMatrix3fv(matrixLocation, false, this.transformationMatrix);

        gl.drawArrays(gl.TRIANGLE_FAN, 0, this.vertices.length / 2 + 1);
    }
}

export default class VertexManager {
    constructor (gl, program) {
        this.gl = gl;
        this.program = program;
        this.buffers = new Map();
        this.initBuffers();
    }

    initBuffers () {
        this.createBuffer(BUFFER_TYPES.CIRCLE, createPolygonVertices(64, 1));
        this.createBuffer(BUFFER_TYPES.SQUARE, new Float32Array([
            -0.5, -0.5,
            0.5, -0.5,
            0.5, 0.5,
            -0.5, 0.5,
        ]));
    ....
    }

    createBuffer (type, vertices) {
        const buffer = this.gl.createBuffer();
        this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
        this.gl.bufferData(this.gl.ARRAY_BUFFER, vertices, this.gl.STATIC_DRAW);
        this.buffers.set(type, { buffer, vertexCount: vertices.length / 2 });
    }

    draw (type, x, y, scaleX, scaleY, rotation, color) {
        const { buffer, vertexCount } = this.buffers.get(type);

        this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);

        // Re-enable the vertex attribute array
        const positionLocation = this.gl.getAttribLocation(this.program, 'a_position');
        this.gl.enableVertexAttribArray(positionLocation);
        this.gl.vertexAttribPointer(positionLocation, 2, this.gl.FLOAT, false, 0, 0);

        // Setup the color
        const colorLocation = this.gl.getUniformLocation(this.program, 'u_color');
        this.gl.uniform4fv(colorLocation, color);

        const matrixLocation = this.gl.getUniformLocation(this.program, 'u_matrix');
        // Create transformation matrices directly in pixel space
        const translationMatrix = createTranslationMatrix(x, y);
        const rotationMatrix = createRotationMatrix(rotation);
        const scalingMatrix = createScalingMatrix(scaleX, scaleY);

        // Combine them: translationMatrix * rotationMatrix * scalingMatrix
        const combinedMatrix = multiplyMatrices(rotationMatrix, multiplyMatrices(translationMatrix, scalingMatrix));

        // Pass the transformation matrix to the shader
        this.gl.uniformMatrix3fv(matrixLocation, false, combinedMatrix);

        this.gl.drawArrays(this.gl.TRIANGLE_FAN, 0, vertexCount);
    }
}

Meine Frage ist, warum mein Quadrat korrekt im Pixel-Space gerendert wird, während die draw-Operation in meinem VertexManager Clip-Space zeichnet, obwohl beide denselben Shader verwenden. Ich habe das Problem schon seit Stunden versucht zu lösen. Hat jemand eine Lösung oder einen Hinweis, was ich möglicherweise falsch mache?

Bild zum Beitrag
JavaScript, Code, OpenGL, Webentwicklung

Wie findet Ihr denn Code?

noten = []

def noten_schuelern(name, mathe, deutsch, englisch, bericht):
    noten.append({"Name": name, "Mathe": mathe, "Deutsch": deutsch, "Englisch": englisch, "Bericht": bericht})
    print(f"Der Schüler {name} wurde hinzugefügt mit seiner Information.")


def durchschnit(name, mathe, deutsch, englisch):
    info = []
    schnitt = (mathe + deutsch + englisch) / 3
    runden = round(schnitt, 4)
    info.append({name, runden})
    print(f"Der Schüler {name} mit dem Notenschnitt von {runden}")


def schueler_anzeigen(name):
    heraus = [schueler for schueler in noten if name.lower() in schueler["Name"].lower()]
    if heraus:
        print(f"Die Information: {noten}")
    else:
        print("Schüler wurde nicht gefunden!")


def menue():
    while True:
        print("__Menü__")
        print("1. Die Noten der Schüler hinzufügen")
        print("2. Der Durschnitt berechnen")
        print("3. Schüler anzeigen")
        print("4. programm beenden")

        wahl = int(input("Bitte wählen sie einer der Optionen aus:"))

        if wahl == 1:
            name = input("Bitte geben sie denn Name der Schüler ein:")
            mathe = int(input("Mathe Note:"))
            deutsch = int(input("Deutsch Note:"))
            englisch = int(input("Englisch Note:"))
            bericht = input("Schreiben sie informationen üben denn Schüler:")
            noten_schuelern(name, mathe, deutsch, englisch, bericht)

        elif wahl == 2:
            Name = input("Schüler Name:")
            Mathe = int(input("Mathe Note:"))
            Deutsch = int(input("Deutsch Note:"))
            Englisch = int(input("Englisch Note:"))
            durchschnit(Name, Mathe, Deutsch, Englisch)

        elif wahl == 3:
            nname = input("Geben sie denn schüler Namen ein:")
            schueler_anzeigen(nname)

        elif wahl == 4:
            print("Programm wird beendet")
            break
        else:
            print("Bitte geben sie was gültiges ein")


menue()


HABE ALLES ALLEINE PROGRAMMIERT AUßER DIE ZEILE DEF ANZEIGEN
Computer, programmieren, Code, Programmiersprache, Python, Python 3

Meistgelesene Beiträge zum Thema Code