main.js

URL: https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc3780/spring2026/notes/javascript/code/start_class/main.js
 
import {DrawImage} from "./drawing.js"
import {ComplexT} from "./complex.js"

// Grab the Canvas and other Graphics stuff
const canvas = document.getElementById("MyCanvas")
const ctx = canvas.getContext("2d")

const width  = canvas.width
const height = canvas.height

// the title
const titleArea = document.getElementById("title")
titleArea.innerHTML= "My Cool " + titleArea.innerHTML

// other UI stuff
let inset = 10;
const insetDataArea = document.getElementById("inset")
insetDataArea.value = inset

const doitButton = document.getElementById("doit")
doitButton.addEventListener("click", ChangePicture)

function ChangePicture() {
    let tempInset =  parseInt(insetDataArea.value)

    if (tempInset >= 10 && tempInset <= Math.min(width/2, height/2)) {
        inset = tempInset 
        ctx.clearRect(0,0, width, height)
        DrawImage(canvas)
    } else {
        insetDataArea.value = inset
    }
}

function ComplexTest() {
    let a = new ComplexT()
    console.log(a)
    console.log(a.toString())

    a = new ComplexT(1)
    console.log(a.toString())

    a = new ComplexT(0,4)
    console.log(a.toString())

    a = new ComplexT(3,4)
    console.log(a.toString())
    let b = new ComplexT(5,9)

    let c = a.Add(b)
    console.log(a.toString() , ' + ', b.toString()  
                , ' = ', c.toString())
}
   

ChangePicture()
//ComplexTest()