Challenge

Week - 5 - Checking and correcting the Normals

OBJECTIVE:

  • To write a code to display normal as explained in Lecture 5
  • To create a widget containing two buttons for “reverse normals” and “normal off”
  • To assign these procedures to keyboard buttons of your choice and also to check the null case.

PROCEDURE:

  • At first, the view is set to 'normals on' by default.
  • Then we put before the user two buttons either to reverse the normals or to turn on/off the normals view.
  • By clicking the reverse button the user will be able to select the required elements and upon clicking proceed, the elements will be reversed.
  • By clicking the NORMALS ON/OFF button the user switch between the visibility modes.
  • hm_marklength function is used inside the if statement to prevent the null case error.

CODE:

*clearmarkall 1
*setnormalsdisplaytype 1
*createmark elems 1 "displayed"
*normalsdisplay elems 1

set noml .window
catch {destroy $noml}
toplevel $noml -class Toplevel
wm title $noml "CORRECTING NORMALS"
wm geometry $noml 450x180+300+150; update
wm resizable $noml 1 0
wm deiconify $noml

set i 1

button $noml.1 -text "REVERSE NORMALS" -command {reverse_normals} -font {times 12 bold}; place $noml.1 -x 50 -y 50 -width 190 -height 50
button $noml.2 -text "NORMALS ON/OFF" -command {normals_off $i; set i [expr $i+1]} -font {times 12 bold}; place $noml.2 -x 250 -y 50 -width 180 -height 50

proc reverse_normals {} {
*createmarkpanel elems 1 "Select all the elements to reverse the normal"
	if {[hm_marklength elems 1]!=0} { 
		*normalsreverse elems 1
		*createmark elems 1 "displayed"
		*normalsdisplay elems 1	
	}
}

proc normals_off {i} {
	
	if {[expr $i % 2]!=0} {
		*createmark elems 1 "displayed"
		*normalsoff
		
		} else {*clearmarkall 1
			*setnormalsdisplaytype 1
			*createmark elems 1 "displayed"
			*normalsdisplay elems 1}
}

CONCLUSION:

  • Learned to set normals view upon execution of the script which helps the user to identify and reverse/correct the normals of the elements.
  • Learned a method to prevent null cases.
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.